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.
 
 
 
 
 

37 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from earwigbot.wiki import NS_TEMPLATE
  4. __all__ = ["get_attribution_info"]
  5. ATTRIB_TEMPLATES = {
  6. "enwiki": {
  7. "CC-notice", "Cc-notice",
  8. "Citation-attribution",
  9. "Free-content attribution", "Open-source attribution",
  10. "Source-attribution",
  11. }
  12. }
  13. def get_attribution_info(site, page):
  14. """Check to see if the given page has some kind of attribution info.
  15. If yes, return a tuple of (attribution template name, template URL).
  16. If no, return None.
  17. """
  18. if site.name not in ATTRIB_TEMPLATES:
  19. return None
  20. base = ATTRIB_TEMPLATES[site.name]
  21. prefix = site.namespace_id_to_name(NS_TEMPLATE)
  22. templates = base | {prefix + ":" + tpl for tpl in base if ":" not in tpl}
  23. for template in page.parse().ifilter_templates():
  24. if template.name.matches(templates):
  25. name = unicode(template.name).strip()
  26. title = name if ":" in name else prefix + ":" + name
  27. return name, site.get_page(title).url
  28. return None