jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/373849 )
Change subject: [bugfix] rewrite family._get_cr_templates() ......................................................................
[bugfix] rewrite family._get_cr_templates()
- category_redirect_templates is a tuple, not a list - retrieve backlinks of all category redirect templates not for the first item only - use fallback if fallback is given and key found in template tuple - keep list order for the given tuple and append the backlinks
Bug: T174041 Change-Id: I596aee7b8934c8aa022cca56679c336c098f5b5b --- M pywikibot/family.py 1 file changed, 15 insertions(+), 13 deletions(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py index 9c94c1b..4f3bd43 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -1016,23 +1016,25 @@ if not hasattr(self, "_catredirtemplates"): self._catredirtemplates = {} if code in self.category_redirect_templates: - cr_template_list = self.category_redirect_templates[code] - cr_list = list(self.category_redirect_templates[code]) + cr_template_tuple = self.category_redirect_templates[code] + elif fallback and fallback in self.category_redirect_templates: + cr_template_tuple = self.category_redirect_templates[fallback] else: - cr_template_list = self.category_redirect_templates[fallback] - cr_list = [] - if cr_template_list: - cr_template = cr_template_list[0] - # start with list of category redirect templates from family file - cr_page = pywikibot.Page(pywikibot.Site(code, self), - "Template:" + cr_template) + self._catredirtemplates[code] = [] + return + cr_set = set() + site = pywikibot.Site(code, self) + tpl_ns = site.namespaces.TEMPLATE + for cr_template in cr_template_tuple: + cr_page = pywikibot.Page(site, cr_template, ns=tpl_ns) # retrieve all redirects to primary template from API, # add any that are not already on the list - for t in cr_page.backlinks(filterRedirects=True, namespaces=10): + for t in cr_page.backlinks(filterRedirects=True, + namespaces=tpl_ns): newtitle = t.title(withNamespace=False) - if newtitle not in cr_list: - cr_list.append(newtitle) - self._catredirtemplates[code] = cr_list + if newtitle not in cr_template_tuple: + cr_set.add(newtitle) + self._catredirtemplates[code] = list(cr_template_tuple) + list(cr_set)
@deprecated('site.category_redirects()') def get_cr_templates(self, code, fallback):
pywikibot-commits@lists.wikimedia.org