Browse Source

Better error handling for revision IDs

copyvios-ng
Ben Kurtovic 3 years ago
parent
commit
ad87596e37
3 changed files with 12 additions and 3 deletions
  1. +1
    -0
      copyvios/api.py
  2. +8
    -2
      copyvios/checker.py
  3. +3
    -1
      templates/index.mako

+ 1
- 0
copyvios/api.py View File

@@ -11,6 +11,7 @@ __all__ = ["format_api_error", "handle_api_request"]


_CHECK_ERRORS = { _CHECK_ERRORS = {
"no search method": "Either 'use_engine' or 'use_links' must be true", "no search method": "Either 'use_engine' or 'use_links' must be true",
"bad oldid": "The revision ID is invalid",
"no URL": "The parameter 'url' is required for URL comparisons", "no URL": "The parameter 'url' is required for URL comparisons",
"bad URI": "The given URI scheme is unsupported", "bad URI": "The given URI scheme is unsupported",
"no data": "No text could be found in the given URL (note that only HTML " "no data": "No text could be found in the given URL (note that only HTML "


+ 8
- 2
copyvios/checker.py View File

@@ -3,6 +3,7 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from hashlib import sha256 from hashlib import sha256
from logging import getLogger from logging import getLogger
import re
from urlparse import urlparse from urlparse import urlparse


from earwigbot import exceptions from earwigbot import exceptions
@@ -28,11 +29,16 @@ def do_check(query=None):
if not query: if not query:
query = Query() query = Query()
if query.lang: if query.lang:
query.lang = query.orig_lang = query.lang.lower()
query.lang = query.orig_lang = query.lang.strip().lower()
if "::" in query.lang: if "::" in query.lang:
query.lang, query.name = query.lang.split("::", 1) query.lang, query.name = query.lang.split("::", 1)
if query.project: if query.project:
query.project = query.project.lower()
query.project = query.project.strip().lower()
if query.oldid:
query.oldid = query.oldid.strip().lstrip("0")
if not re.match(r"^\d+$", query.oldid):
query.error = "bad oldid"
return


query.submitted = query.project and query.lang and (query.title or query.oldid) query.submitted = query.project and query.lang and (query.title or query.oldid)
if query.submitted: if query.submitted:


+ 3
- 1
templates/index.mako View File

@@ -19,6 +19,8 @@
Unknown action: <b><span class="mono">${query.action | h}</span></b>. Unknown action: <b><span class="mono">${query.action | h}</span></b>.
% elif query.error == "no search method": % elif query.error == "no search method":
No copyvio search methods were selected. A check can only be made using the search engine, links present in the page, Turnitin, or some combination of these. No copyvio search methods were selected. A check can only be made using the search engine, links present in the page, Turnitin, or some combination of these.
% elif query.error == "bad oldid":
The revision ID <code>${query.oldid | h}</code> is invalid. It should be an integer.
% elif query.error == "no URL": % elif query.error == "no URL":
URL comparison mode requires a URL to be entered. Enter one in the text box below, or choose copyvio search mode to look for content similar to the article elsewhere on the web. URL comparison mode requires a URL to be entered. Enter one in the text box below, or choose copyvio search mode to look for content similar to the article elsewhere on the web.
% elif query.error == "bad URI": % elif query.error == "bad URI":
@@ -215,7 +217,7 @@
<% attrib = get_attribution_info(query.site, query.page) %> <% attrib = get_attribution_info(query.site, query.page) %>
% if attrib: % if attrib:
<div id="attribution-warning" class="yellow-box"> <div id="attribution-warning" class="yellow-box">
This article contains an attribution template: <tt>{{<a href="${attrib[1]}">${attrib[0] | h}</a>}}</tt>. Please verify that any potential copyvios are not from properly attributed sources.
This article contains an attribution template: <code>{{<a href="${attrib[1]}">${attrib[0] | h}</a>}}</code>. Please verify that any potential copyvios are not from properly attributed sources.
</div> </div>
% endif % endif




Loading…
Cancel
Save