Xqt has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/373849 )
Change subject: [bugfix] rewrite of family._get_cr_templates()
......................................................................
[bugfix] rewrite of family._get_cr_templates()
- category_redirect_templates is a tuple, not a list
- retrieve backlinks of all category redirect templates not fir 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, 17 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/49/373849/1
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 9c94c1b..f08ec7b 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1016,23 +1016,24 @@
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)
- # 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):
- newtitle = t.title(withNamespace=False)
- if newtitle not in cr_list:
- cr_list.append(newtitle)
- self._catredirtemplates[code] = cr_list
+ cr_template_tuple = (, )
+ cr_set = set()
+ if cr_template_tuple:
+ 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=tpl_ns):
+ newtitle = t.title(withNamespace=False)
+ 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):
--
To view, visit https://gerrit.wikimedia.org/r/373849
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I596aee7b8934c8aa022cca56679c336c098f5b5b
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits