Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/102126


Change subject: [SYNC] Synchronize with compat, code improvements, enable -xml 
option
......................................................................

[SYNC] Synchronize with compat, code improvements, enable -xml option

- use mediawiki's comma-separator
- remove obsolete config and catlib import
- remove unused variables
- reorder generators

Change-Id: I19a6b377022e00491ba50d3d3e4a01ea0c36f507
---
M scripts/template.py
1 file changed, 25 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/26/102126/1

diff --git a/scripts/template.py b/scripts/template.py
index 3400c60..782893c 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -99,8 +99,8 @@
 #
 # (C) Daniel Herding, 2004
 # (C) Rob W.W. Hooft, 2003
-# (C) xqt, 2009-2011
-# (C) Pywikibot team, 2004-2010
+# (C) xqt, 2009-2013
+# (C) Pywikibot team, 2004-2013
 #
 # Distributed under the terms of the MIT license.
 #
@@ -110,7 +110,8 @@
 import re
 import pywikibot
 from pywikibot import i18n
-from pywikibot import config, pagegenerators, catlib
+from pywikibot import pagegenerators as pg
+from pywikibot import xmlreader
 from scripts import replace
 
 
@@ -155,14 +156,13 @@
             * templateNames - A list of Page object representing the searched
                               templates
             * xmlfilename   - The dump's path, either absolute or relative
+
         """
-        raise NotImplementedError("Sorry, no XML reader in rewrite yet.")
         self.templates = templates
         self.xmlfilename = xmlfilename
 
     def __iter__(self):
         """Yield page objects until the entire XML dump has been read."""
-        from pywikibot import xmlreader
         mysite = pywikibot.getSite()
         dump = xmlreader.XmlDump(self.xmlfilename)
         # regular expression to find the original template.
@@ -171,7 +171,7 @@
         # TODO: check site.nocapitalize()
         templatePatterns = []
         for template in self.templates:
-            templatePattern = template.titleWithoutNamespace()
+            templatePattern = template.title(withNamespace=False)
             if not pywikibot.getSite().nocapitalize:
                 templatePattern = '[%s%s]%s' % (templatePattern[0].upper(),
                                                 templatePattern[0].lower(),
@@ -192,6 +192,7 @@
     This robot will load all pages yielded by a page generator and replace or
     remove all occurences of the old template, or substitute them with the
     template's text.
+
     """
     def __init__(self, generator, templates, subst=False, remove=False,
                  editSummary='', acceptAll=False, addedCat=None):
@@ -204,6 +205,7 @@
                              removed/resolved to None.
             * remove       - True if the template should be removed.
             * subst        - True if the template should be resolved.
+
         """
         self.generator = generator
         self.templates = templates
@@ -217,9 +219,11 @@
             self.addedCat = pywikibot.Category(
                 site, u'%s:%s' % (site.namespace(14), self.addedCat))
 
+        comma = site.mediawiki_message('comma-separator')
+
         # get edit summary message if it's empty
-        if (self.editSummary == ''):
-            Param = {'list': (', ').join(self.templates.keys()),
+        if not self.editSummary:
+            Param = {'list': comma.join(self.templates.keys()),
                      'num': len(self.templates)}
             if self.remove:
                 self.editSummary = i18n.twntranslate(
@@ -232,9 +236,7 @@
                     site, 'template-changing', Param)
 
     def run(self):
-        """
-        Starts the robot's action.
-        """
+        """Starts the robot's action."""
         # regular expression to find the original template.
         # {{vfd}} does the same thing as {{Vfd}}, so both will be found.
         # The old syntax, {{msg:vfd}}, will also be found.
@@ -285,11 +287,10 @@
     templates = {}
     subst = False
     remove = False
-    namespaces = []
     editSummary = ''
     addedCat = ''
     acceptAll = False
-    genFactory = pagegenerators.GeneratorFactory()
+    genFactory = pg.GeneratorFactory()
     # If xmlfilename is None, references will be loaded from the live wiki.
     xmlfilename = None
     user = None
@@ -326,7 +327,8 @@
             if not genFactory.handleArg(arg):
                 templateNames.append(
                     pywikibot.Page(pywikibot.Site(), arg,
-                                   ns=10).title(withNamespace=False))
+                                   ns=10
+                                   ).title(withNamespace=False))
 
     if subst ^ remove:
         for templateName in templateNames:
@@ -341,27 +343,24 @@
             return
 
     oldTemplates = []
-    ns = pywikibot.Site().template_namespace()
     for templateName in templates.keys():
-        oldTemplate = pywikibot.Page(pywikibot.Site(), templateName, ns=10)
+        oldTemplate = pywikibot.Page(pywikibot.Site(), templateName,
+                                     ns=10)
         oldTemplates.append(oldTemplate)
 
     if xmlfilename:
         gen = XmlDumpTemplatePageGenerator(oldTemplates, xmlfilename)
+    elif user:
+        gen = UserEditFilterGenerator(gen, user, timestamp, skip)
     else:
         gen = genFactory.getCombinedGenerator()
     if not gen:
-        gens = []
-        gens = [
-            pagegenerators.ReferringPageGenerator(t, 
onlyTemplateInclusion=True)
-            for t in oldTemplates
-        ]
-        gen = pagegenerators.CombinedPageGenerator(gens)
-        gen = pagegenerators.DuplicateFilterPageGenerator(gen)
+        gens = [pg.ReferringPageGenerator(t, onlyTemplateInclusion=True)
+                for t in oldTemplates]
+        gen = pg.CombinedPageGenerator(gens)
+        gen = pg.DuplicateFilterPageGenerator(gen)
 
-    if user:
-        gen = UserEditFilterGenerator(gen, user, timestamp, skip)
-    preloadingGen = pagegenerators.PreloadingGenerator(gen)
+    preloadingGen = pg.PreloadingGenerator(gen)
 
     bot = TemplateRobot(preloadingGen, templates, subst, remove, editSummary,
                         acceptAll, addedCat)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I19a6b377022e00491ba50d3d3e4a01ea0c36f507
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

Reply via email to