Browse Source

Show warning when a page has an attribution template.

master
Ben Kurtovic 7 years ago
parent
commit
63f1ae98c4
3 changed files with 48 additions and 0 deletions
  1. +34
    -0
      copyvios/attribution.py
  2. +5
    -0
      static/style.css
  3. +9
    -0
      templates/index.mako

+ 34
- 0
copyvios/attribution.py View File

@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from earwigbot.wiki import NS_TEMPLATE

__all__ = ["get_attribution_info"]

ATTRIB_TEMPLATES = {
"enwiki": {
"CC-notice", "Cc-notice",
"Citation-attribution",
"Free-content attribution", "Open-source attribution",
"Source-attribution",
}
}

def get_attribution_info(site, page):
"""Check to see if the given page has some kind of attribution info.

If yes, return a mwparserfromhell.nodes.Template object for the attribution
template. If no, return None.
"""
if site.name not in ATTRIB_TEMPLATES:
return None

templates = ATTRIB_TEMPLATES[site.name]
prefix = site.namespace_id_to_name(NS_TEMPLATE)
templates |= {prefix + ":" + tmpl for tmpl in templates if ":" not in tmpl}

for template in page.parse().ifilter_templates():
if template.name.matches(templates):
return template
return None

+ 5
- 0
static/style.css View File

@@ -68,6 +68,11 @@ div#cv-result {
margin: 10px 5px;
}

div#attribution-warning {
padding: 5px;
margin: 15px 5px 10px 5px;
}

div#turnitin-container {
padding: 5px;
margin: 15px 5px 10px 5px;


+ 9
- 0
templates/index.mako View File

@@ -4,6 +4,7 @@
from copyvios.misc import cache
%>\
<%include file="/support/header.mako" args="title='Earwig\'s Copyvio Detector'"/>
<%namespace module="copyvios.attribution" import="get_attribution_info"/>\
<%namespace module="copyvios.highlighter" import="highlight_delta"/>\
<%namespace module="copyvios.misc" import="httpsfix, urlstrip"/>\
% if notice:
@@ -211,6 +212,14 @@
</table>
</div>

<% attrib = get_attribution_info(query.site, query.page) %>
% if attrib:
<% attrib_page = query.site.get_page(attrib.name) %>
<div id="attribution-warning" class="yellow-box">
This article contains an attribution template: <tt>{{<a href="attrib_page.url">${attrib_page.title | h}</a>}}</tt>. Please verify that any potential copyvios are not from properly attributed sources.
</div>
% endif

% if query.turnitin_result:
<div id="turnitin-container" class="${'red' if query.turnitin_result.reports else 'green'}-box">
<div id="turnitin-title">Turnitin Results</div>


Loading…
Cancel
Save