Ricordisamoa has uploaded a new change for review. https://gerrit.wikimedia.org/r/148082
Change subject: preserve sortKey exactly when (de)serializing category links ...................................................................... preserve sortKey exactly when (de)serializing category links an empty sortKey and a null one are not considered the same anymore - in Category.aslink() by checking `key` against None - in textlib.getCategoryLinks() by making the regex catch empty sortKeys TestCategoryRearrangement has been introduced to ensure that the bot doesn't do any undesired changes to the text Change-Id: Ief9d5f95b37f949d667a0ffd43d79b69d12bd8d7 --- M pywikibot/page.py M pywikibot/textlib.py M tests/textlib_tests.py 3 files changed, 17 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/82/148082/1 diff --git a/pywikibot/page.py b/pywikibot/page.py index 3396ed1..c6473bc 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1913,7 +1913,7 @@ """ key = sortKey or self.sortKey - if key: + if key is not None: titleWithSortKey = '%s|%s' % (self.title(withSection=False), key) else: diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index bbac6a3..259d15e 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -661,7 +661,7 @@ text = removeDisabledParts(text) catNamespace = '|'.join(site.category_namespaces()) R = re.compile(r'\[\[\s*(?P<namespace>%s)\s*:\s*(?P<catName>.+?)' - r'(?:\|(?P<sortKey>.+?))?\s*\]\]' + r'(?:\|(?P<sortKey>.*))?\s*\]\]' % catNamespace, re.I) for match in R.finditer(text): cat = pywikibot.Category(pywikibot.Link( diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index ba7da8e..f6d30f3 100644 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -130,6 +130,21 @@ textlib.categoryFormat(data, self.site)) +class TestCategoryRearrangement(PywikibotTestCase): + + @classmethod + def setUpClass(cls): + cls.site = pywikibot.Site('en', 'wikipedia') + cls.cats = ('[[Category:Cat1]]%(LS)s[[Category:Cat2|]]%(LS)s' + '[[Category:Cat1| ]]%(LS)s[[Category:Cat2|key]]' + % {'LS': config.LS}) + + def test_replace_category_links(self): + old = textlib.getCategoryLinks(self.cats, site=self.site) + new = textlib.replaceCategoryLinks(self.cats, old, site=self.site) + self.assertEqual(old, new) + + if __name__ == '__main__': try: unittest.main() -- To view, visit https://gerrit.wikimedia.org/r/148082 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ief9d5f95b37f949d667a0ffd43d79b69d12bd8d7 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ricordisamoa <ricordisa...@openmailbox.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits