A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

api.mako 18 KiB

10 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <%! from json import dumps %>\
  2. <%def name="do_indent(size)">
  3. <br />
  4. % for i in xrange(size):
  5. <div class="indent"></div>
  6. % endfor
  7. </%def>\
  8. <%def name="walk_json(obj, indent=0)">
  9. % if isinstance(obj, type({})):
  10. {
  11. % for key in obj:
  12. ${do_indent(indent + 1)}
  13. "${key | h}": ${walk_json(obj[key], indent + 1)}${"," if not loop.last else ""}
  14. % endfor
  15. ${do_indent(indent)}
  16. }
  17. % elif isinstance(obj, (type([]), type(()))):
  18. [
  19. % for elem in obj:
  20. ${do_indent(indent + 1)}
  21. ${walk_json(elem, indent + 1)}${"," if not loop.last else ""}
  22. % endfor
  23. ${do_indent(indent)}
  24. ]
  25. % else:
  26. ${dumps(obj) | h}
  27. % endif
  28. </%def>\
  29. <!DOCTYPE html>
  30. <html lang="en">
  31. <head>
  32. <meta charset="utf-8">
  33. <title>API - Earwig's Copyvio Detector</title>
  34. <link rel="stylesheet" href="${request.script_root}/static/api.min.css" type="text/css" />
  35. </head>
  36. <body>
  37. % if help:
  38. <div id="help">
  39. <h1>Copyvio Detector API</h1>
  40. <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>
  41. <h2>Requests</h2>
  42. <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>
  43. <table class="parameters">
  44. <tr>
  45. <th colspan="4">Always</th>
  46. </tr>
  47. <tr>
  48. <th>Parameter</th>
  49. <th>Values</th>
  50. <th>Required?</th>
  51. <th>Description</th>
  52. </tr>
  53. <tr>
  54. <td>action</td>
  55. <td><span class="code">compare</span>, <span class="code">search</span>, <span class="code">sites</span></td>
  56. <td>Yes</td>
  57. <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>
  58. </tr>
  59. <tr>
  60. <td>format</td>
  61. <td><span class="code">json</span>, <span class="code">jsonfm</span></td>
  62. <td>No&nbsp;(default:&nbsp;<span class="code">json</span>)</td>
  63. <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>
  64. </tr>
  65. <tr>
  66. <td>version</td>
  67. <td>integer</td>
  68. <td>No (default: <span class="code">1</span>)</td>
  69. <td>Currently, the API only has one version. You can skip this parameter, but it is recommended to include it for forward compatibility.</td>
  70. </tr>
  71. </table>
  72. <table class="parameters">
  73. <tr>
  74. <th colspan="4"><span class="code">compare</span> Mode</th>
  75. </tr>
  76. <tr>
  77. <th>Parameter</th>
  78. <th>Values</th>
  79. <th>Required?</th>
  80. <th>Description</th>
  81. </tr>
  82. <tr>
  83. <td>project</td>
  84. <td>string</td>
  85. <td>Yes</td>
  86. <td>The project code 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>
  87. </tr>
  88. <tr>
  89. <td>lang</td>
  90. <td>string</td>
  91. <td>Yes</td>
  92. <td>The language code 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>
  93. </tr>
  94. <tr>
  95. <td>title</td>
  96. <td>string</td>
  97. <td>Yes&nbsp;(either&nbsp;<span class="code">title</span>&nbsp;or&nbsp;<span class="code">oldid</span>)</td>
  98. <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>
  99. </tr>
  100. <tr>
  101. <td>oldid</td>
  102. <td>integer</td>
  103. <td>Yes (either <span class="code">title</span> or <span class="code">oldid</span>)</td>
  104. <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>
  105. </tr>
  106. <tr>
  107. <td>url</td>
  108. <td>string</td>
  109. <td>Yes</td>
  110. <td>The URL of the suspected violation source that will be compared to the page.</td>
  111. </tr>
  112. </table>
  113. <table class="parameters">
  114. <tr>
  115. <th colspan="4"><span class="code">search</span> Mode</th>
  116. </tr>
  117. <tr>
  118. <th>Parameter</th>
  119. <th>Values</th>
  120. <th>Required?</th>
  121. <th>Description</th>
  122. </tr>
  123. <tr>
  124. <td>project</td>
  125. <td>string</td>
  126. <td>Yes</td>
  127. <td>The project code 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>
  128. </tr>
  129. <tr>
  130. <td>lang</td>
  131. <td>string</td>
  132. <td>Yes</td>
  133. <td>The language code 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>
  134. </tr>
  135. <tr>
  136. <td>title</td>
  137. <td>string</td>
  138. <td>Yes&nbsp;(either&nbsp;<span class="code">title</span>&nbsp;or&nbsp;<span class="code">oldid</span>)</td>
  139. <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>
  140. </tr>
  141. <tr>
  142. <td>oldid</td>
  143. <td>integer</td>
  144. <td>Yes (either <span class="code">title</span> or <span class="code">oldid</span>)</td>
  145. <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>
  146. </tr>
  147. <tr>
  148. <td>use_engine</td>
  149. <td>boolean</td>
  150. <td>No (default: <span class="code">true</span>)</td>
  151. <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>
  152. </tr>
  153. <tr>
  154. <td>use_links</td>
  155. <td>boolean</td>
  156. <td>No (default: <span class="code">true</span>)</td>
  157. <td>Whether to compare the page against external links found in its wikitext.</td>
  158. </tr>
  159. <tr>
  160. <td>nocache</td>
  161. <td>boolean</td>
  162. <td>No (default: <span class="code">false</span>)</td>
  163. <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>
  164. </tr>
  165. <tr>
  166. <td>noredirect</td>
  167. <td>boolean</td>
  168. <td>No (default: <span class="code">false</span>)</td>
  169. <td>Whether to avoid following redirects if the given page is a redirect.</td>
  170. </tr>
  171. <tr>
  172. <td>noskip</td>
  173. <td>boolean</td>
  174. <td>No (default: <span class="code">false</span>)</td>
  175. <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>
  176. </tr>
  177. </table>
  178. <h2>Responses</h2>
  179. <p>The JSON response object always contains a <span class="code">status</span> key, whose value is either <span class="code">ok</span> or <span class="code">error</span>. If an error has occurred, the response will look like this:</p>
  180. <pre>{
  181. "status": "error",
  182. "error": {
  183. "code": <span class="resp-dtype">string</span> <span class="resp-desc">error code</span>,
  184. "info": <span class="resp-dtype">string</span> <span class="resp-desc">human-readable description of error</span>
  185. }
  186. }</pre>
  187. <p>Valid responses for <span class="code">action=compare</span> and <span class="code">action=search</span> are formatted like this:</p>
  188. <pre>{
  189. "status": "ok",
  190. "meta": {
  191. "time": <span class="resp-dtype">float</span> <span class="resp-desc">time to generate results, in seconds</span>,
  192. "queries": <span class="resp-dtype">int</span> <span class="resp-desc">number of search engine queries made</span>,
  193. "cached": <span class="resp-dtype">boolean</span> <span class="resp-desc">whether or not these results are cached from an earlier search (always false in the case of action=compare)</span>,
  194. "redirected": <span class="resp-dtype">boolean</span> <span class="resp-desc">whether or not a redirect was followed</span>,
  195. <span class="resp-cond">only if cached=true</span> "cache_time": <span class="resp-dtype">string</span> <span class="resp-desc">human-readable time of the original search that the results are cached from</span>
  196. },
  197. "page": {
  198. "title": <span class="resp-dtype">string</span> <span class="resp-desc">the normalized title of the page checked</span>,
  199. "url": <span class="resp-dtype">string</span> <span class="resp-desc">the full URL of the page checked</span>
  200. },
  201. <span class="resp-cond">only if redirected=true</span> "original_page": {
  202. "title": <span class="resp-dtype">string</span> <span class="resp-desc">the normalized title of the original page whose redirect was followed</span>,
  203. "url": <span class="resp-dtype">string</span> <span class="resp-desc">the full URL of the original page whose redirect was followed</span>
  204. },
  205. "best": {
  206. "url": <span class="resp-dtype">string</span> <span class="resp-desc">the URL of the best match found, or null if no matches were found</span>,
  207. "confidence": <span class="resp-dtype">float</span> <span class="resp-desc">the confidence of a violation in the best match, or 0.0 if no matches were found</span>,
  208. "violation": <span class="resp-dtype">string</span> <span class="resp-desc">one of "suspected", "possible", or "none"</span>
  209. },
  210. "sources": [
  211. {
  212. "url": <span class="resp-dtype">string</span> <span class="resp-desc">the URL of the source</span>,
  213. "confidence": <span class="resp-dtype">float</span> <span class="resp-desc">the confidence of a violation in the source</span>,
  214. "violation": <span class="resp-dtype">string</span> <span class="resp-desc">one of "suspected", "possible", or "none"</span>,
  215. "skipped": <span class="resp-dtype">boolean</span> <span class="resp-desc">whether or not the source was skipped due to the check finishing early (see note about noskip above)</span>
  216. },
  217. ...
  218. ]
  219. }</pre>
  220. <p>In the case of <span class="code">action=search</span>, <span class="code">sources</span> will contain one entry for each source checked (or skipped if the check ends early), sorted in order of confidence, with skipped sources at the bottom.</p>
  221. <p>In the case of <span class="code">action=compare</span>, <span class="code">best</span> will always contain information about the URL that was given, so <span class="code">response["best"]["url"]</span> will never be <span class="code">null</span>. Also, <span class="code">sources</span> will always contain one entry, with the same data as <span class="code">best</span>, since only one source is checked in comparison mode.</p>
  222. <p>Valid responses for <span class="code">action=sites</span> are formatted like this:</p>
  223. <pre>{
  224. "status": "ok",
  225. "langs": [
  226. [
  227. <span class="resp-dtype">string</span> <span class="resp-desc">language code</span>,
  228. <span class="resp-dtype">string</span> <span class="resp-desc">human-readable language name</span>
  229. ],
  230. ...
  231. ],
  232. "projects": [
  233. [
  234. <span class="resp-dtype">string</span> <span class="resp-desc">project code</span>,
  235. <span class="resp-dtype">string</span> <span class="resp-desc">human-readable project name</span>
  236. ],
  237. ...
  238. ]
  239. }</pre>
  240. <h2>Caveats</h2>
  241. <ul>
  242. <li>There is currently no way to get the contents of the article or suspected source, nor can you get the data behind the visual comparison available from the main tool. This may be changed in a future version if there is sufficient demand for it.</li>
  243. <li>Requests are typically not rate-limited, but the tool uses the same workers to handle all requests, so making simultaneous API calls is only going to slow you down. In general, you are fine making an unlimited number of requests, as long as they are not concurrent and you wait a few seconds between them.</li>
  244. </ul>
  245. <h2>Example</h2>
  246. <p><a class="no-color" href="https://tools.wmflabs.org/copyvios/api.json?version=1&amp;action=search&amp;project=wikipedia&amp;lang=en&amp;title=User:The_Earwig/Sandbox/CopyvioExample"><span class="code">https://tools.wmflabs.org/copyvios/api.json?<span class="param-key">version</span>=<span class="param-val">1</span>&amp;<span class="param-key">action</span>=<span class="param-val">search</span>&amp;<span class="param-key">project</span>=<span class="param-val">wikipedia</span>&amp;<span class="param-key">lang</span>=<span class="param-val">en</span>&amp;<span class="param-key">title</span>=<span class="param-val">User:The_Earwig/Sandbox/CopyvioExample</span></span></a></p>
  247. <pre>{
  248. "status": "ok",
  249. "meta": {
  250. "time": 2.2474379539489746,
  251. "queries": 1,
  252. "cached": false,
  253. "redirected": false
  254. },
  255. "page": {
  256. "title": "User:The Earwig/Sandbox/CopyvioExample",
  257. "url": "https://en.wikipedia.org/wiki/User:The_Earwig/Sandbox/CopyvioExample"
  258. },
  259. "best": {
  260. "url": "http://www.whitehouse.gov/administration/president-obama/",
  261. "confidence": 0.9886608511242603,
  262. "violation": "suspected"
  263. }
  264. "sources": [
  265. {
  266. "url": "http://www.whitehouse.gov/administration/president-obama/",
  267. "confidence": 0.9886608511242603,
  268. "violation": "suspected",
  269. "skipped": false
  270. },
  271. {
  272. "url": "http://maige2009.blogspot.com/2013/07/barack-h-obama-is-44th-president-of.html",
  273. "confidence": 0.9864798816568047,
  274. "violation": "suspected",
  275. "skipped": false
  276. },
  277. {
  278. "url": "http://jeuxdemonstre-apkdownload.rhcloud.com/luo-people-of-kenya-and-tanzania---wikipedia--the-free",
  279. "confidence": 0.0,
  280. "violation": "none",
  281. "skipped": false
  282. },
  283. {
  284. "url": "http://www.whitehouse.gov/about/presidents/barackobama",
  285. "confidence": 0.0,
  286. "violation": "none",
  287. "skipped": true
  288. },
  289. {
  290. "url": "http://jeuxdemonstre-apkdownload.rhcloud.com/president-barack-obama---the-white-house",
  291. "confidence": 0.0,
  292. "violation": "none",
  293. "skipped": true
  294. }
  295. ]
  296. }
  297. </pre>
  298. </div>
  299. % endif
  300. % if result:
  301. <div id="result">
  302. <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>
  303. <div class="json">
  304. ${walk_json(result)}
  305. </div>
  306. </div>
  307. % endif
  308. </body>
  309. </html>