Procházet zdrojové kódy

Better error handling for revision IDs

copyvios-ng
Ben Kurtovic před 3 roky
rodič
revize
ad87596e37
3 změnil soubory, kde provedl 12 přidání a 3 odebrání
  1. +1
    -0
      copyvios/api.py
  2. +8
    -2
      copyvios/checker.py
  3. +3
    -1
      templates/index.mako

+ 1
- 0
copyvios/api.py Zobrazit soubor

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

_CHECK_ERRORS = {
"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",
"bad URI": "The given URI scheme is unsupported",
"no data": "No text could be found in the given URL (note that only HTML "


+ 8
- 2
copyvios/checker.py Zobrazit soubor

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

from earwigbot import exceptions
@@ -28,11 +29,16 @@ def do_check(query=None):
if not query:
query = Query()
if query.lang:
query.lang = query.orig_lang = query.lang.lower()
query.lang = query.orig_lang = query.lang.strip().lower()
if "::" in query.lang:
query.lang, query.name = query.lang.split("::", 1)
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)
if query.submitted:


+ 3
- 1
templates/index.mako Zobrazit soubor

@@ -19,6 +19,8 @@
Unknown action: <b><span class="mono">${query.action | h}</span></b>.
% 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.
% 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":
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":
@@ -215,7 +217,7 @@
<% attrib = get_attribution_info(query.site, query.page) %>
% if attrib:
<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>
% endif



Načítá se…
Zrušit
Uložit