瀏覽代碼

Some minor tweaks, plus documentation for API parameters.

pull/24/head
Ben Kurtovic 10 年之前
父節點
當前提交
89feddba98
共有 5 個文件被更改,包括 170 次插入9 次删除
  1. +5
    -1
      app.fcgi
  2. +9
    -5
      copyvios/checker.py
  3. +8
    -1
      static/api.css
  4. +147
    -1
      templates/api.mako
  5. +1
    -1
      templates/support/footer.mako

+ 5
- 1
app.fcgi 查看文件

@@ -87,8 +87,12 @@ def settings():
"default_lang": default.lang, "default_project": default.project}
return render_template("settings.mako", **kwargs)

@app.route("/api.json")
@app.route("/api")
def api():
return render_template("api.mako", help=True)

@app.route("/api.json")
def api_json():
if not request.args:
return render_template("api.mako", help=True)



+ 9
- 5
copyvios/checker.py 查看文件

@@ -17,6 +17,9 @@ __all__ = ["do_check", "T_POSSIBLE", "T_SUSPECT"]
T_POSSIBLE = 0.4
T_SUSPECT = 0.75

def _coerce_bool(val):
return val and val not in ("0", "false")

def do_check(query=None):
if not query:
query = Query()
@@ -32,7 +35,7 @@ def do_check(query=None):
if query.submitted:
query.site = get_site(query)
if query.site:
_get_results(query, follow=query.noredirect is None)
_get_results(query, follow=not _coerce_bool(query.noredirect))
return query

def _get_results(query, follow=True):
@@ -59,14 +62,15 @@ def _get_results(query, follow=True):
query.action = "compare" if query.url else "search"
if query.action == "search":
conn = get_cache_db()
use_engine = 0 if query.use_engine == "0" else 1
use_links = 0 if query.use_links == "0" else 1
use_engine = 0 if query.use_engine in ("0", "false") else 1
use_links = 0 if query.use_links in ("0", "false") else 1
if not use_engine and not use_links:
query.error = "no search method"
return
mode = "{0}:{1}:".format(use_engine, use_links)
if not query.nocache:
query.result = _get_cached_results(page, conn, mode, query.noskip)
if not _coerce_bool(query.nocache):
query.result = _get_cached_results(
page, conn, mode, _coerce_bool(query.noskip))
if not query.result:
try:
query.result = page.copyvio_check(


+ 8
- 1
static/api.css 查看文件

@@ -1,3 +1,10 @@
.code {
span.code {
font-family: monospace;
}

table.parameters {
}

table.parameters td:first-child {
font-family: monospace;
}

+ 147
- 1
templates/api.mako 查看文件

@@ -1,3 +1,7 @@
<%def name="walk_json(obj)">
<!-- TODO -->
${obj | h}
</%def>
<!DOCTYPE html>
<html lang="en">
<head>
@@ -8,13 +12,155 @@
<body>
% if help:
<div id="help">
<h1>Copyvio Detector API</h1>
<p>This is the first version of the <a href="//en.wikipedia.org/wiki/Application_programming_interface">API</a> for <a href="${request.script_root}">Earwig's Copyvio Detector</a>. It works, but some bugs might still need to be ironed out, so please <a href="https://github.com/earwig/copyvios/issues">report any</a> if you see them.</p>
<h2>Requests</h2>
<p>The API responds to GET requests made to <span class="code">https://tools.wmflabs.org/copyvios/api.json</span>. Parameters are described in the tables below:</p>
<table class="parameters">
<tr>
<th colspan="3">Always</th>
</tr>
<tr>
<th>Parameter</th>
<th>Values</th>
<th>Required?</th>
<th>Description</th>
</tr>
<tr>
<td>action</td>
<td><span class="code">compare</span>, <span class="code">search</span>, <span class="code">sites</span></td>
<td>Yes</td>
<td>The API will do URL comparisons in <span class="code">compare</span> mode, run full copyvio checks in <span class="code">search</span> mode, and list all known site languages and projects in <span class="code">sites</span> mode.</td>
</tr>
<tr>
<td>format</td>
<td><span class="code">json</span>, <span class="code">jsonfm</span></td>
<td>No (default: <span class="code">json</span>)</td>
<td>The default output format is <a href="http://json.org/">JSON</a>. <span class="code">jsonfm</span> mode produces the same output, but renders it as a formatted HTML document for debugging.</td>
</tr>
<tr>
<td>version</td>
<td>integer</td>
<td>No (default: <span class="code">1</span>)</td>
<td>Currently, the API only has one version. You can skip this parameter, but it is recommended to include it for forward compatibility.</td>
</tr>
</table>
<table class="parameters">
<tr>
<th colspan="3"><span class="code">compare</span> Mode</th>
</tr>
<tr>
<th>Parameter</th>
<th>Values</th>
<th>Required?</th>
<th>Description</th>
</tr>
<tr>
<td>project</td>
<td>string</td>
<td>Yes</td>
<td>The project name of the site the page lives on. Examples are <span class="code">wikipedia</span> and <span class="code">wiktionary</span>. A list of acceptable values can be retrieved using <span class="code">action=sites</span>.</td>
</tr>
<tr>
<td>lang</td>
<td>string</td>
<td>Yes</td>
<td>The language name of the site the page lives on. Examples are <span class="code">en</span> and <span class="code">de</span>. A list of acceptable values can be retrieved using <span class="code">action=sites</span>.</td>
</tr>
<tr>
<td>title</td>
<td>string</td>
<td>Yes (either <span class="code">title</span> or <span class="code">oldid</span>)</td>
<td>The title of the page or article to make a comparison against. Namespace must be included if the page isn't in the mainspace.</td>
</tr>
<tr>
<td>oldid</td>
<td>integer</td>
<td>Yes (either <span class="code">title</span> or <span class="code">oldid</span>)</td>
<td>The revision ID (also called oldid) of the page revision to make a comparison against. If both a title and oldid are given, the oldid will be used.</td>
</tr>
<tr>
<td>url</td>
<td>string</td>
<td>Yes</td>
<td>The URL of the suspected violation source that will be compared to the page.</td>
</tr>
</table>
<table class="parameters">
<tr>
<th colspan="3"><span class="code">search</span> Mode</th>
</tr>
<tr>
<th>Parameter</th>
<th>Values</th>
<th>Required?</th>
<th>Description</th>
</tr>
<tr>
<td>project</td>
<td>string</td>
<td>Yes</td>
<td>The project name of the site the page lives on. Examples are <span class="code">wikipedia</span> and <span class="code">wiktionary</span>. A list of acceptable values can be retrieved using <span class="code">action=sites</span>.</td>
</tr>
<tr>
<td>lang</td>
<td>string</td>
<td>Yes</td>
<td>The language name of the site the page lives on. Examples are <span class="code">en</span> and <span class="code">de</span>. A list of acceptable values can be retrieved using <span class="code">action=sites</span>.</td>
</tr>
<tr>
<td>title</td>
<td>string</td>
<td>Yes (either <span class="code">title</span> or <span class="code">oldid</span>)</td>
<td>The title of the page or article to make a check against. Namespace must be included if the page isn't in the mainspace.</td>
</tr>
<tr>
<td>oldid</td>
<td>integer</td>
<td>Yes (either <span class="code">title</span> or <span class="code">oldid</span>)</td>
<td>The revision ID (also called oldid) of the page revision to make a check against. If both a title and oldid are given, the oldid will be used.</td>
</tr>
<tr>
<td>use_engine</td>
<td>boolean</td>
<td>No (default: <span class="code">true</span>)</td>
<td>Whether to use a search engine (<a href="//developer.yahoo.com/boss/search/">Yahoo! BOSS</a>) as a source of URLs to compare against the page.</td>
</tr>
<tr>
<td>use_links</td>
<td>boolean</td>
<td>No (default: <span class="code">true</span>)</td>
<td>Whether to compare the page against external links found in its wikitext.</td>
</tr>
<tr>
<td>nocache</td>
<td>boolean</td>
<td>No (default: <span class="code">false</span>)</td>
<td>Whether to bypass search results cached from previous checks. It is recommended that you don't pass this option unless a user specifically asks for it.</td>
</tr>
<tr>
<td>noredirect</td>
<td>boolean</td>
<td>No (default: <span class="code">false</span>)</td>
<td>Whether to avoid following redirects if the given page is a redirect.</td>
</tr>
<tr>
<td>noskip</td>
<td>boolean</td>
<td>No (default: <span class="code">false</span>)</td>
<td>If a suspected source is found during a check to have a sufficiently high confidence value, the check will end prematurely, and other pending URLs will be skipped. Passing this option will prevent this behavior, resulting in complete (but more time-consuming) checks.</td>
</tr>
</table>
<h2>Responses</h2>
<p></p> <!-- List errors -->
<h2>Example</h2>
<p></p>
</div>
% endif
% if result:
<div id="result">
<p>You are using <span class="code">jsonfm</span> output mode, which renders JSON data as a formatted HTML document. This is intended for testing and debugging only.</p>
<!-- walk tree -->
${walk_json(result)}
</div>
% endif
</body>


+ 1
- 1
templates/support/footer.mako 查看文件

@@ -2,7 +2,7 @@
</div>
<div id="footer">
<p>Copyright &copy; 2009&ndash;2014 <a href="//en.wikipedia.org/wiki/User:The_Earwig">Ben Kurtovic</a> &bull; \
<a href="${request.script_root}/api.json">API</a> &bull; \
<a href="${request.script_root}/api">API</a> &bull; \
<a href="https://github.com/earwig/copyvios">Source Code</a> &bull; \
% if ("CopyviosBackground" in g.cookies and g.cookies["CopyviosBackground"].value in ["potd", "list"]) or "CopyviosBackground" not in g.cookies:
<a href="${g.descurl | h}">Background</a> &bull; \


Loading…
取消
儲存