jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/322401 )

Change subject: Improve and re-enable translateMagicWords
......................................................................


Improve and re-enable translateMagicWords

Bug: T151107
Change-Id: I97b1bc227959feb889610c3c2b7c9609b0c5dccf
---
M pywikibot/cosmetic_changes.py
M tests/cosmetic_changes_tests.py
2 files changed, 22 insertions(+), 8 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved



diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index f1923a8..07fb95c 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -50,7 +50,7 @@
 """
 #
 # (C) xqt, 2009-2016
-# (C) Pywikibot team, 2006-2016
+# (C) Pywikibot team, 2006-2017
 #
 # Distributed under the terms of the MIT license.
 #
@@ -221,8 +221,7 @@
             self.cleanUpSectionHeaders,
             self.putSpacesInLists,
             self.translateAndCapitalizeNamespaces,
-            # FIXME: fix bugs and re-enable
-            # self.translateMagicWords,
+            self.translateMagicWords,
             self.replaceDeprecatedTemplates,
             # FIXME: fix bugs and re-enable
             # self.resolveHtmlEntities,
@@ -406,19 +405,22 @@
         """Use localized magic words."""
         # not wanted at ru
         # arz uses english stylish codes
-        if self.site.code not in ['arz', 'ru']:
+        # no need to run on English wikis
+        if self.site.code not in ['arz', 'en', 'ru']:
             exceptions = ['nowiki', 'comment', 'math', 'pre']
             for magicWord in ['img_thumbnail', 'img_left', 'img_center',
                               'img_right', 'img_none', 'img_framed',
                               'img_frameless', 'img_border', 'img_upright', ]:
-                aliases = self.site.getmagicwords(magicWord)
+                aliases = list(self.site.getmagicwords(magicWord))
+                preferred = aliases.pop(0)
                 if not aliases:
                     continue
                 text = textlib.replaceExcept(
                     text,
-                    r'\[\[(?P<left>.+?:.+?\..+?\|) *(' + '|'.join(aliases) +
-                    r') *(?P<right>(\|.*?)?\]\])',
-                    r'[[\g<left>' + aliases[0] + r'\g<right>', exceptions)
+                    r'\[\[(?P<left>.+?:.+?\..+?\|(.*?\|)*?) *(' +
+                    '|'.join(aliases) +
+                    r') *(?P<right>(\|.*?)*?\]\])',
+                    r'[[\g<left>' + preferred + r'\g<right>', exceptions)
         return text
 
     def cleanUpLinks(self, text):
diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py
index cc3947c..5db7281 100644
--- a/tests/cosmetic_changes_tests.py
+++ b/tests/cosmetic_changes_tests.py
@@ -244,6 +244,18 @@
         self.assertEqual(
             '[[File:Foo.bar|miniatur]]',
             self.cct.translateMagicWords('[[File:Foo.bar|mini]]'))
+        self.assertEqual(
+            '[[File:Foo.bar|links|miniatur]]',
+            self.cct.translateMagicWords('[[File:Foo.bar|left|thumb]]'))
+        self.assertEqual(
+            '[[File:Foo.bar|250px|links]]',
+            self.cct.translateMagicWords('[[File:Foo.bar|250px|left]]'))
+        self.assertEqual(
+            '[[File:Foo.bar|links|250px]]',
+            self.cct.translateMagicWords('[[File:Foo.bar| left |250px]]'))
+        self.assertEqual(
+            '[[File:Foo.bar|250px|zentriert|Baz]]',
+            self.cct.translateMagicWords('[[File:Foo.bar|250px|center|Baz]]'))
 
     def test_cleanUpLinks_pipes(self):
         """Test cleanUpLinks method."""

-- 
To view, visit https://gerrit.wikimedia.org/r/322401
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I97b1bc227959feb889610c3c2b7c9609b0c5dccf
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Magul <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to