diff --git a/LICENSE b/LICENSE index ef34f5a..e142526 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-2013 Ben Kurtovic +Copyright (c) 2009-2014 Ben Kurtovic Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/copyvios/__init__.py b/copyvios/__init__.py index b81633d..5aa8af0 100644 --- a/copyvios/__init__.py +++ b/copyvios/__init__.py @@ -14,12 +14,10 @@ def main(context, environ): if query.project: query.project = query.project.lower() - bot = get_bot() - all_langs, all_projects = get_sites(bot) - page = result = None + query.bot = get_bot() + query.all_langs, query.all_projects = get_sites(query.bot) if query.lang and query.project and query.title: - site = get_site(bot, query, all_projects) - if site: - page, result = get_results(bot, site, query) - - return query, bot, all_langs, all_projects, page, result + query.site = get_site(query) + if query.site: + get_results(query) + return query diff --git a/copyvios/checker.py b/copyvios/checker.py index ae95c6b..ef18d08 100644 --- a/copyvios/checker.py +++ b/copyvios/checker.py @@ -8,28 +8,27 @@ from earwigbot import exceptions from .misc import open_sql_connection -def get_results(bot, site, query): - page = site.get_page(query.title) +def get_results(query): + page = query.page = query.site.get_page(query.title) try: page.get() # Make sure that the page exists before we check it! except (exceptions.PageNotFoundError, exceptions.InvalidPageError): - return page, None + return if query.url: if urlparse(query.url).scheme not in ["http", "https"]: - return page, "bad URI" - result = page.copyvio_compare(query.url) - result.cached = False + query.result = "bad URI" + return + query.result = page.copyvio_compare(query.url) + query.result.cached = False else: - conn = open_sql_connection(bot, "cache") + conn = open_sql_connection(query.bot, "cache") if not query.nocache: - result = _get_cached_results(page, conn) - if query.nocache or not result: - result = page.copyvio_check(max_queries=10, max_time=45) - result.cached = False - _cache_result(page, result, conn) - - return page, result + query.result = _get_cached_results(page, conn) + if not query.result: + query.result = page.copyvio_check(max_queries=10, max_time=45) + query.result.cached = False + _cache_result(page, query.result, conn) def _get_cached_results(page, conn): query1 = "DELETE FROM cache WHERE cache_time < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 3 DAY)" diff --git a/copyvios/sites.py b/copyvios/sites.py index 4430512..dcc7925 100644 --- a/copyvios/sites.py +++ b/copyvios/sites.py @@ -7,23 +7,24 @@ from earwigbot import exceptions from .misc import open_sql_connection -def get_site(bot, query, all_projects): +def get_site(query): lang, project, name = query.lang, query.project, query.name - if project not in [proj[0] for proj in all_projects]: + wiki = query.bot.wiki + if project not in [proj[0] for proj in query.all_projects]: return None if project == "wikimedia" and name: # Special sites: try: - return bot.wiki.get_site(name=name) + return wiki.get_site(name=name) except exceptions.SiteNotFoundError: try: - return bot.wiki.add_site(lang=lang, project=project) + return wiki.add_site(lang=lang, project=project) except (exceptions.APIError, exceptions.LoginError): return None try: - return bot.wiki.get_site(lang=lang, project=project) + return wiki.get_site(lang=lang, project=project) except exceptions.SiteNotFoundError: try: - return bot.wiki.add_site(lang=lang, project=project) + return wiki.add_site(lang=lang, project=project) except (exceptions.APIError, exceptions.LoginError): return None diff --git a/pages/index.mako b/pages/index.mako index c2c7ebf..80408f4 100644 --- a/pages/index.mako +++ b/pages/index.mako @@ -1,32 +1,43 @@ <%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Earwig\'s Copyvio Detector'"/>\ <%namespace module="copyvios" import="main, highlight_delta"/>\ <%namespace module="copyvios.misc" import="urlstrip"/>\ -<% query, bot, all_langs, all_projects, page, result = main(environ) %>\ - % if query.project and query.lang and query.title and not page: -
-

The given site (project=${query.project | h}, language=${query.lang | h}) doesn't seem to exist. It may also be closed or private. Confirm its URL.

-
- % elif query.project and query.lang and query.title and page and not result: -
-

The given page doesn't seem to exist: ${page.title | h}.

-
- % elif query.project and query.lang and query.title and query.url and page and result == "bad URI": - <% result = None %> -
-

Unsupported URI scheme: ${query.url | h}.

-
- % endif +<% + query = main(environ) + # Unpack query data: + lang, orig_lang, title, oldid, url, nocache = query.lang, query.orig_lang, query.title, query.oldid, query.url, query.nocache + bot, site, page, result = query.bot, query.site, query.page, query.result +%>\ + % if query.project and lang and (title or oldid): + % if not site: +
+

The given site (project=${query.project | h}, language=${lang | h}) doesn't seem to exist. It may also be closed or private. Confirm its URL.

+
+ % elif title and not result: +
+

The given page doesn't seem to exist: ${page.title | h}.

+
+ % elif oldid and not result: +
+

The given revision ID doesn't seem to exist: ${oldid | h}.

+
+ % elif url and result == "bad URI": + <% result = None %> +
+

Unsupported URI scheme: ${url | h}.

+
+ % endif + %endif

This tool attempts to detect copyright violations in articles. Simply give the title of the page or ID of the revision you want to check and hit Submit. The tool will search for similar content elsewhere on the web and display a report if a match is found. If you also provide a URL, it will not query any search engines and instead display a report comparing the article to that particular webpage, like the Duplication Detector. Check out the FAQ for more information and technical details.

Note: The tool is still in beta. You are completely welcome to use it and provide feedback, but be aware that it may produce strange or broken results.

-
+ - % if query.nocache or (result and result.cached): + % if nocache or (result and result.cached):
Site: http:// <% selected_project = query.project if query.project else cookies["CopyviosDefaultProject"].value if "CopyviosDefaultProject" in cookies else bot.wiki.get_site().project %>\ - % for code, name in all_projects: + % for code, name in query.all_projects: % if code == selected_project: % else: @@ -53,16 +64,16 @@ % if page: - % elif query.title: - + % elif title: + % else: % endif or revision ID: - % if query.oldid: - + % if oldid: + % else: % endif @@ -71,18 +82,18 @@
URL (optional): - % if query.url: - + % if url: + % else: % endif
Bypass cache: - % if query.nocache: + % if nocache: % else: @@ -97,7 +108,7 @@
- % if page and result: + % if result: <% show_details = "CopyviosShowDetails" in cookies and cookies["CopyviosShowDetails"].value == "True" %>
@@ -107,7 +118,7 @@

No violations detected in ${page.title | h}.

% endif
    - % if not result.violation and not query.url: + % if not result.violation and not url: % if result.url:
  • Best match: ${result.url | urlstrip, h}.
  • % else: diff --git a/pages/settings.mako b/pages/settings.mako index ec0fc38..aae4c9b 100644 --- a/pages/settings.mako +++ b/pages/settings.mako @@ -8,7 +8,7 @@
% endif

This page contains some configurable options for the copyvio detector. Settings are saved as cookies. You can view and delete all cookies generated by this site at the bottom of this page.

-
+ @@ -85,7 +85,7 @@ % endtry
Default site:${cookie.value | h} - + @@ -95,7 +95,7 @@ % endfor
- + diff --git a/pages/support/footer.mako b/pages/support/footer.mako index 9aeff6e..9fdead0 100644 --- a/pages/support/footer.mako +++ b/pages/support/footer.mako @@ -2,7 +2,7 @@ <%namespace module="copyvios.background" import="get_desc_url"/>\