XZise has uploaded a new change for review.

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

Change subject: [FIX] Expect that the template is a Page instance
......................................................................

[FIX] Expect that the template is a Page instance

The Page method templatesWithParams returns the first value as a Page
instance instead of a string. It's not possible to use equality in such
a case:

  page.templatesWithParams[0][0] == 'foobar'

This will always be False as the value on the left is a Page instance.
Since 55d6232e the method returns a Page instance so it's not possible
to return string instances like compat does without breaking scripts
which already expecte Page instances.

Bug: T97248
Change-Id: I9d4feffc7d081cbcc349111b3e28da2de300649c
---
M scripts/blockreview.py
M scripts/cfd.py
M scripts/commonscat.py
M scripts/nowcommons.py
4 files changed, 13 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/59/206759/1

diff --git a/scripts/blockreview.py b/scripts/blockreview.py
index d78c9f9..e1c97aa 100755
--- a/scripts/blockreview.py
+++ b/scripts/blockreview.py
@@ -122,7 +122,7 @@
         # saveAdmin = saveProject = False
         talkComment = None
         for templates in userPage.templatesWithParams():
-            if templates[0] == unblock_tpl:
+            if templates[0].title() == unblock_tpl:
                 self.getInfo(user)
                 # Step 1
                 # a new template is set on blocked users talk page.
diff --git a/scripts/cfd.py b/scripts/cfd.py
index 0922e32..5a6eaca 100755
--- a/scripts/cfd.py
+++ b/scripts/cfd.py
@@ -179,7 +179,7 @@
         # Try to parse day link from CFD template parameters.
         templates = page.templatesWithParams()
         for template in templates:
-            if template[0] in cfdTemplates:
+            if template[0].title() in cfdTemplates:
                 params = template[1]
                 (day, month, year) = [None, None, None]
                 for param in params:
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 75beea1..b94bc2f 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -476,7 +476,7 @@
             elif "Category redirect" in commonsPage.templates():
                 pywikibot.log(u"getCommonscat: The category is a category 
redirect")
                 for template in commonsPage.templatesWithParams():
-                    if (template[0] == "Category redirect" and
+                    if (template[0].title(withNamespace=False) == "Category 
redirect" and
                             len(template[1]) > 0):
                         return self.checkCommonscatLink(template[1][0])
             elif commonsPage.isDisambig():
diff --git a/scripts/nowcommons.py b/scripts/nowcommons.py
index ac41e39..b462ec7 100755
--- a/scripts/nowcommons.py
+++ b/scripts/nowcommons.py
@@ -208,6 +208,14 @@
         else:
             return nowCommons['_default']
 
+    @property
+    def nc_templates(self):
+        """A set of now commons template Page instances."""
+        if not hasattr(self, '_nc_templates'):
+            self._nc_templates = set(pywikibot.Page(self.site, title, ns=10)
+                                     for title in self.ncTemplates())
+        return self._nc_templates
+
     def useHashGenerator(self):
         # 
https://toolserver.org/~multichill/nowcommons.php?language=it&page=2&filter=
         lang = self.site.lang
@@ -270,12 +278,9 @@
         if self.getOption('use_hash'):
             gen = self.useHashGenerator()
         else:
-            nowCommonsTemplates = [pywikibot.Page(self.site, title,
-                                                  ns=10)
-                                   for title in self.ncTemplates()]
             gens = [t.getReferences(follow_redirects=True, namespaces=[6],
                                     onlyTemplateInclusion=True)
-                    for t in nowCommonsTemplates]
+                    for t in self.nc_templates]
             gen = pg.CombinedPageGenerator(gens)
             gen = pg.DuplicateFilterPageGenerator(gen)
             gen = pg.PreloadingGenerator(gen)
@@ -284,7 +289,7 @@
     def findFilenameOnCommons(self, localImagePage):
         filenameOnCommons = None
         for templateName, params in localImagePage.templatesWithParams():
-            if templateName in self.ncTemplates():
+            if templateName in self.nc_templates:
                 if params == []:
                     filenameOnCommons = 
localImagePage.title(withNamespace=False)
                 elif self.site.lang in namespaceInTemplate:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d4feffc7d081cbcc349111b3e28da2de300649c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>

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

Reply via email to