From 63f1ae98c41258dbb1af66d6ce64440f863881e1 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 28 Feb 2017 23:01:25 -0600 Subject: [PATCH] Show warning when a page has an attribution template. --- copyvios/attribution.py | 34 ++++++++++++++++++++++++++++++++++ static/style.css | 5 +++++ templates/index.mako | 9 +++++++++ 3 files changed, 48 insertions(+) create mode 100644 copyvios/attribution.py diff --git a/copyvios/attribution.py b/copyvios/attribution.py new file mode 100644 index 0000000..15f3e36 --- /dev/null +++ b/copyvios/attribution.py @@ -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 diff --git a/static/style.css b/static/style.css index de16c55..a5b48a7 100644 --- a/static/style.css +++ b/static/style.css @@ -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; diff --git a/templates/index.mako b/templates/index.mako index e1610d2..25e0819 100644 --- a/templates/index.mako +++ b/templates/index.mako @@ -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 @@ + <% attrib = get_attribution_info(query.site, query.page) %> + % if attrib: + <% attrib_page = query.site.get_page(attrib.name) %> +
+ This article contains an attribution template: {{${attrib_page.title | h}}}. Please verify that any potential copyvios are not from properly attributed sources. +
+ % endif + % if query.turnitin_result:
Turnitin Results