A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

copyvios.mako 9.5 KiB

12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <%!
  2. from urlparse import parse_qs
  3. from earwigbot.bot import Bot
  4. %>\
  5. <%namespace file="/support/copyvios/__init__.py" import="get_results, highlight_delta"/>\
  6. <%namespace file="/support/sites.py" import="get_site, get_sites"/>\
  7. <%namespace file="/support/misc.py" import="urlstrip"/>\
  8. <%
  9. lang = orig_lang = project = name = title = url = None
  10. query = parse_qs(environ["QUERY_STRING"])
  11. if "lang" in query:
  12. lang = orig_lang = query["lang"][0].decode("utf8").lower()
  13. if "::" in lang:
  14. lang, name = lang.split("::", 1)
  15. if "project" in query:
  16. project = query["project"][0].decode("utf8").lower()
  17. if "title" in query:
  18. title = query["title"][0].decode("utf8")
  19. if "url" in query:
  20. url = query["url"][0].decode("utf8")
  21. bot = Bot(".earwigbot")
  22. all_langs, all_projects = get_sites(bot)
  23. if lang and project and title:
  24. site, page, result = get_results(bot, lang, project, name,
  25. all_projects, title, url, query)
  26. else:
  27. site = page = result = None
  28. %>\
  29. <%include file="/support/header.mako" args="environ=environ, title='Copyvio Detector', add_css=('copyvios.css',), add_js=('copyvios.js',)"/>
  30. <h1>Copyvio Detector</h1>
  31. <p>This tool attempts to detect <a href="//en.wikipedia.org/wiki/WP:COPYVIO">copyright violations</a> in articles. Simply give the title of the page you want to check and hit Submit. The tool will then search for its content elsewhere on the web and display a report if a similar webpage 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 <a href="//toolserver.org/~dcoetzee/duplicationdetector/">Duplication Detector</a>. Check out the <a href="//en.wikipedia.org/wiki/User:EarwigBot/Copyvios/FAQ">FAQ</a> for more information and technical details.</p>
  32. <form action="${environ['PATH_INFO']}" method="get">
  33. <table>
  34. <tr>
  35. <td>Site:</td>
  36. <td>
  37. <tt>http://</tt>
  38. <select name="lang">
  39. <% selected_lang = orig_lang if orig_lang else bot.wiki.get_site().lang %>
  40. % for code, name in all_langs:
  41. % if code == selected_lang:
  42. <option value="${code}" selected="selected">${name}</option>
  43. % else:
  44. <option value="${code}">${name}</option>
  45. % endif
  46. % endfor
  47. </select>
  48. <tt>.</tt>
  49. <select name="project">
  50. <% selected_project = project if project else bot.wiki.get_site().project %>
  51. % for code, name in all_projects:
  52. % if code == selected_project:
  53. <option value="${code}" selected="selected">${name}</option>
  54. % else:
  55. <option value="${code}">${name}</option>
  56. % endif
  57. % endfor
  58. </select>
  59. <tt>.org</tt>
  60. </td>
  61. </tr>
  62. <tr>
  63. <td>Page title:</td>
  64. % if page:
  65. <td><input type="text" name="title" size="60" value="${page.title | h}" /></td>
  66. % elif title:
  67. <td><input type="text" name="title" size="60" value="${title | h}" /></td>
  68. % else:
  69. <td><input type="text" name="title" size="60" /></td>
  70. % endif
  71. </tr>
  72. <tr>
  73. <td>URL (optional):</td>
  74. % if url:
  75. <td><input type="text" name="url" size="120" value="${url | h}" /></td>
  76. % else:
  77. <td><input type="text" name="url" size="120" /></td>
  78. % endif
  79. </tr>
  80. % if query.get("nocache") or (result and result.cached):
  81. <tr>
  82. <td>Bypass cache:</td>
  83. % if query.get("nocache"):
  84. <td><input type="checkbox" name="nocache" value="1" checked="checked" /></td>
  85. % else:
  86. <td><input type="checkbox" name="nocache" value="1" /></td>
  87. % endif
  88. </tr>
  89. % endif
  90. <tr>
  91. <td><button type="submit">Submit</button></td>
  92. </tr>
  93. </table>
  94. </form>
  95. % if project and lang and title and not page:
  96. <div class="divider"></div>
  97. <div id="cv-result-yes">
  98. <p>The given site (project=<b><tt>${project}</tt></b>, language=<b><tt>${lang}</tt></b>) doesn't seem to exist. It may also be closed or private. <a href="//${lang}.${project}.org/">Confirm its URL.</a></p>
  99. </div>
  100. % elif project and lang and title and page and not result:
  101. <div class="divider"></div>
  102. <div id="cv-result-yes">
  103. <p>The given page doesn't seem to exist: <a href="${page.url}">${page.title | h}</a>.</p>
  104. </div>
  105. % elif page:
  106. <div class="divider"></div>
  107. <div id="cv-result-${'yes' if result.violation else 'no'}">
  108. % if result.violation:
  109. <h2 id="cv-result-header"><a href="${page.url}">${page.title | h}</a> is a suspected violation of <a href="${result.url | h}">${result.url | urlstrip}</a>.</h2>
  110. % else:
  111. <h2 id="cv-result-header">No violations detected in <a href="${page.url()}">${page.title | h}</a>.</h2>
  112. % endif
  113. <ul id="cv-result-list">
  114. <li><b><tt>${round(result.confidence * 100, 1)}%</tt></b> confidence of a violation.</li>
  115. % if result.cached:
  116. <li>Results are <a id="cv-cached" href="#">cached
  117. <span>To save time (and money), this tool will retain the results of checks for up to 72 hours. This includes the URL of the "violated" source, but neither its content nor the content of the article. Future checks on the same page (assuming it remains unchanged) will not involve additional search queries, but a fresh comparison against the source URL will be made. If the page is modified, a new check will be run.</span>
  118. </a> from ${result.cache_time} (${result.cache_age} ago). <a href="${environ['REQUEST_URI'].decode("utf8") | h}&amp;nocache=1">Bypass the cache.</a></li>
  119. % else:
  120. <li>Results generated in <tt>${round(result.tdiff, 3)}</tt> seconds using <tt>${result.queries}</tt> queries.</li>
  121. % endif
  122. <li><a id="cv-result-detail-link" href="#cv-result-detail" onclick="copyvio_toggle_details()">Show details:</a></li>
  123. </ul>
  124. <div id="cv-result-detail" style="display: none;">
  125. <ul id="cv-result-detail-list">
  126. <li>Trigrams: <i>Article:</i> <tt>${result.article_chain.size()}</tt> / <i>Source:</i> <tt>${result.source_chain.size()}</tt> / <i>Delta:</i> <tt>${result.delta_chain.size()}</tt></li>
  127. % if result.cached:
  128. % if result.queries:
  129. <li>Retrieved from cache in <tt>${round(result.tdiff, 3)}</tt> seconds (originally generated in <tt>${round(result.original_tdiff, 3)}</tt>s using <tt>${result.queries}</tt> queries; <tt>${round(result.original_tdiff - result.tdiff, 3)}</tt>s saved).</li>
  130. % else:
  131. <li>Retrieved from cache in <tt>${round(result.tdiff, 3)}</tt> seconds (originally generated in <tt>${round(result.original_tdiff, 3)}</tt>s; <tt>${round(result.original_tdiff - result.tdiff, 3)}</tt>s saved).</li>
  132. % endif
  133. % endif
  134. % if result.queries:
  135. <li><i>Fun fact:</i> The Wikimedia Foundation paid Yahoo! Inc. <a href="http://info.yahoo.com/legal/us/yahoo/search/bosspricing/details.html">$${result.queries * 0.0008} USD</a> for these results.</li>
  136. % endif
  137. </ul>
  138. <table id="cv-chain-table">
  139. <tr>
  140. <td>Article: <div class="cv-chain-detail"><p>${highlight_delta(result.article_chain, result.delta_chain)}</p></div></td>
  141. <td>Source: <div class="cv-chain-detail"><p>${highlight_delta(result.source_chain, result.delta_chain)}</p></div></td>
  142. </tr>
  143. </table>
  144. </div>
  145. </div>
  146. % endif
  147. <%include file="/support/footer.mako" args="environ=environ"/>