diff --git a/app.fcgi b/app.fcgi index ee804cb..207ea74 100755 --- a/app.fcgi +++ b/app.fcgi @@ -11,6 +11,7 @@ from flask import Flask, g, request from flask.ext.mako import MakoTemplates, render_template, TemplateError from flup.server.fcgi import WSGIServer +from copyvios.checker import do_check from copyvios.cookies import parse_cookies from copyvios.misc import get_bot from copyvios.settings import process_settings @@ -56,7 +57,8 @@ def write_access_log(response): @app.route("/") @catch_errors def index(): - return render_template("index.mako") + query = do_check() + return render_template("index.mako", query=query, result=query.result) @app.route("/settings", methods=["GET", "POST"]) @catch_errors diff --git a/copyvios/__init__.py b/copyvios/__init__.py index 5aa8af0..89907bf 100644 --- a/copyvios/__init__.py +++ b/copyvios/__init__.py @@ -1,23 +1 @@ # -*- coding: utf-8 -*- - -from .checker import get_results -from .highlighter import highlight_delta -from .misc import get_bot, Query -from .sites import get_site, get_sites - -def main(context, environ): - query = Query(environ) - if query.lang: - query.lang = query.orig_lang = query.lang.lower() - if "::" in query.lang: - query.lang, query.name = query.lang.split("::", 1) - if query.project: - query.project = query.project.lower() - - query.bot = get_bot() - query.all_langs, query.all_projects = get_sites(query.bot) - if query.lang and query.project and query.title: - query.site = get_site(query) - if query.site: - get_results(query) - return query diff --git a/copyvios/checker.py b/copyvios/checker.py index ef18d08..d864193 100644 --- a/copyvios/checker.py +++ b/copyvios/checker.py @@ -6,9 +6,27 @@ from urlparse import urlparse from earwigbot import exceptions -from .misc import open_sql_connection +from .misc import get_bot, Query, open_sql_connection +from .sites import get_site, get_sites -def get_results(query): +def do_check(): + query = Query() + if query.lang: + query.lang = query.orig_lang = query.lang.lower() + if "::" in query.lang: + query.lang, query.name = query.lang.split("::", 1) + if query.project: + query.project = query.project.lower() + + query.bot = get_bot() + query.all_langs, query.all_projects = get_sites(query.bot) + if query.project and query.lang and query.title: # TODO: and (query.title or query.oldid): ... + query.site = get_site(query) + if query.site: + _get_results(query) + return query + +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! diff --git a/copyvios/misc.py b/copyvios/misc.py index e8cb721..c7f226e 100644 --- a/copyvios/misc.py +++ b/copyvios/misc.py @@ -27,10 +27,7 @@ class Query(object): pass def __getattr__(self, key): - try: - return self.query[key] - except KeyError: - return None + return self.query.get(key) def __setattr__(self, key, value): if key == "query": diff --git a/templates/index.mako b/templates/index.mako index 33e1176..7c65468 100644 --- a/templates/index.mako +++ b/templates/index.mako @@ -1,42 +1,40 @@ +<%! + from flask import g, request +%>\ <%include file="/support/header.mako" args="title='Earwig\'s Copyvio Detector'"/> -<%namespace module="copyvios" import="main, highlight_delta"/>\ +<%namespace module="copyvios.highlighter" import="highlight_delta"/>\ <%namespace module="copyvios.misc" import="urlstrip"/>\ -<% - 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: +% if query.project and query.lang and (query.title or query.oldid): + % if not query.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.

+

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 title and not result: + % elif query.title and not result:
-

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

+

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

- % elif oldid and not result: + % elif query.oldid and not result:
-

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

+

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

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

Unsupported URI scheme: ${url | h}.

+

Unsupported URI scheme: ${query.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.

+

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 using Yahoo! BOSS and then display a report if a match is found. If you give a URL, it will skip the search engine step and directly display a report comparing the article to that particular webpage, like the Duplication Detector.

+

Specific websites can be excluded from the check (for example, if their content is in the public domain) by being added to the excluded URL list.

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 nocache or (result and result.cached): + % if query.nocache or (result and result.cached):
Site: http:// .
Page title: - % if page: - - % elif title: - + % if query.page: + + % elif query.title: + % else: % endif or revision ID: - % if oldid: - + % if query.oldid: + % else: % endif @@ -82,18 +80,18 @@
URL (optional): - % if url: - + % if query.url: + % else: % endif
Bypass cache: - % if nocache: + % if query.nocache: % else: @@ -109,16 +107,16 @@
% if result: - <% show_details = "CopyviosShowDetails" in cookies and cookies["CopyviosShowDetails"].value == "True" %> + <% show_details = "CopyviosShowDetails" in g.cookies and g.cookies["CopyviosShowDetails"].value == "True" %>
% if result.violation: -

${page.title | h} is a suspected violation of ${result.url | urlstrip, h}.

+

${query.page.title | h} is a suspected violation of ${result.url | urlstrip, h}.

% else: -

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

+

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

% endif