John Vandenberg has uploaded a new change for review. https://gerrit.wikimedia.org/r/260905
Change subject: Do not expand text by default in getCategoryLinks ...................................................................... Do not expand text by default in getCategoryLinks 666364ca introduced wikitext expansion while getting category links, however this caused magic names like {{PAGENAME}} to be expanded when it should be kept in the wikitext. Make this new functionality disabled by default. Bug: T109213 Change-Id: I321ba1715fe7b1a9c24d7f8109db236339e5f4b5 (cherry picked from commit b28346ab33e0f2d844904bded538f137c7d04cd3) --- M pywikibot/textlib.py M tests/textlib_tests.py 2 files changed, 9 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/05/260905/1 diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 1f659c9..456940e 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -743,7 +743,7 @@ # Functions dealing with category links # ------------------------------------- -def getCategoryLinks(text, site=None, include=[]): +def getCategoryLinks(text, site=None, include=[], expand_text=False): """Return a list of category links found in text. @param include: list of tags which should not be removed by @@ -763,7 +763,7 @@ R = re.compile(r'\[\[\s*(?P<namespace>%s)\s*:\s*(?P<rest>.+?)\]\]' % catNamespace, re.I) for match in R.finditer(text): - if '{{' in match.group('rest'): + if expand_text and '{{' in match.group('rest'): rest = site.expand_text(match.group('rest')) else: rest = match.group('rest') diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index 563f639..e928ade 100644 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -237,24 +237,25 @@ def test_templates(self): self.site = self.get_site() self.assertEqual(textlib.getCategoryLinks( - '[[Category:{{P1|Foo}}]]', self.site), + '[[Category:{{P1|Foo}}]]', self.site, expand_text=True), [pywikibot.page.Category(self.site, 'Foo')]) self.assertEqual(textlib.getCategoryLinks( - '[[Category:{{P1|Foo}}|bar]]', self.site), + '[[Category:{{P1|Foo}}|bar]]', self.site, expand_text=True), [pywikibot.page.Category(self.site, 'Foo', sortKey='bar')]) self.assertEqual(textlib.getCategoryLinks( - '[[Category:{{P1|{{P2|L33t|Foo}}}}|bar]]', self.site), + '[[Category:{{P1|{{P2|L33t|Foo}}}}|bar]]', + self.site, expand_text=True), [pywikibot.page.Category(self.site, 'Foo', sortKey='bar')]) self.assertEqual(textlib.getCategoryLinks( - '[[Category:Foo{{!}}bar]]', self.site), + '[[Category:Foo{{!}}bar]]', self.site, expand_text=True), [pywikibot.page.Category(self.site, 'Foo', sortKey='bar')]) self.assertEqual(textlib.getCategoryLinks( '[[Category:Foo{{!}}bar]][[Category:Wiki{{P2||pedia}}]]', - self.site), + self.site, expand_text=True), [pywikibot.page.Category(self.site, 'Foo', sortKey='bar'), pywikibot.page.Category(self.site, 'Wikipedia')]) self.assertEqual(textlib.getCategoryLinks( - '[[Category:Foo{{!}}and{{!}}bar]]', self.site), + '[[Category:Foo{{!}}and{{!}}bar]]', self.site, expand_text=True), [pywikibot.page.Category(self.site, 'Foo', sortKey='and|bar')]) self.assertRaises(pywikibot.InvalidTitle, textlib.getCategoryLinks, '[[Category:nasty{{{!}}]]', self.site) -- To view, visit https://gerrit.wikimedia.org/r/260905 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I321ba1715fe7b1a9c24d7f8109db236339e5f4b5 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: 2.0 Gerrit-Owner: John Vandenberg <jay...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits