jenkins-bot has submitted this change and it was merged.
Change subject: archivebot: make capitalized templates discoverable
......................................................................
archivebot: make capitalized templates discoverable
Follows up ee42bfd6, which made templates like
https://en.wikivoyage.org/wiki/Template:Auto_archiving
not discoverable when used with the syntax {{auto archiving}}.
Change-Id: I89a7248967c133fc56133c957ea4c32534b3f25a
---
M scripts/archivebot.py
1 file changed, 25 insertions(+), 4 deletions(-)
Approvals:
XZise: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
Whym: Looks good to me, but someone else must approve
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 6563a83..a8fe3b7 100644
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -206,6 +206,29 @@
namespaces=namespaces)
+def template_title_regex(tpl_page):
+ """
+ Return a regex that matches to variations of the template title.
+
+ It supports the transcluding variant as well as localized namespaces and
+ case-insensitivity depending on the namspace.
+
+ @param tpl_page: The template page
+ @type tpl_page: Page
+ """
+ ns = tpl_page.site.namespaces[tpl_page.namespace()]
+ marker = '?' if ns.id == 10 else ''
+ title = tpl_page.title(withNamespace=False)
+ if ns.case != 'case-sensitive':
+ title = '[%s%s]%s' % (re.escape(title[0].upper()),
+ re.escape(title[0].lower()),
+ re.escape(title[1:]))
+ else:
+ title = re.escape(title)
+
+ return re.compile(r'(?:(?:{0}):){1}{2}'.format(u'|'.join(ns), marker,
title))
+
+
class TZoneUTC(datetime.tzinfo):
"""Class building a UTC tzinfo object."""
@@ -535,10 +558,8 @@
self.archives[a].update(comment)
# Save the page itself
- marker = '?' if self.tpl.namespace() == 10 else ''
- rx = re.compile(r"\{\{(?:(?:%s):)%s%s\s*?\n.*?\n\}\}" %
(u'|'.join(
- set(self.site.namespaces[self.tpl.namespace()])), marker,
- re.escape(self.tpl.title(withNamespace=False))), re.DOTALL)
+ rx = re.compile(r'\{\{%s\s*?\n.*?\n\}\}'
+ % (template_title_regex(self.tpl).pattern), re.DOTALL)
if not rx.search(self.page.header):
pywikibot.error("Couldn't find the template in the
header")
return
--
To view, visit
https://gerrit.wikimedia.org/r/193351
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I89a7248967c133fc56133c957ea4c32534b3f25a
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Whym <whym(a)whym.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Whym <whym(a)whym.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>