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

Change subject: [compat2core] Fix regressions of multiple Page methods
......................................................................

[compat2core] Fix regressions of multiple Page methods

The following methods' behavior differs between compat and core:
- templates()
- templatesWithParams()
- linkedPages()

Warnings were added to README-conversion.txt and compat2core.py. Every
incorrect (not-working compat-like) usage across scripts was fixed.

Solve_disambiguation.py slicing problem was splitted into a separate patch.

Bug: T58188
Bug: T186394
Change-Id: If0abe8ad1653e2bc0786cf48dea214d5b94d1cbc
---
M README-conversion.txt
M scripts/commonscat.py
M scripts/imagecopy_self.py
M scripts/imagerecat.py
M scripts/maintenance/compat2core.py
M scripts/solve_disambiguation.py
6 files changed, 29 insertions(+), 14 deletions(-)

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



diff --git a/README-conversion.txt b/README-conversion.txt
index 4363efa..9618a07 100644
--- a/README-conversion.txt
+++ b/README-conversion.txt
@@ -91,9 +91,13 @@
 The following methods have had their outputs changed:

 - getVersionHistory(): Returns a pywikibot.Timestamp object instead of a 
MediaWiki one
+- templates(): Returns a list of Page objects of templates. In compat we have
+    a list of template title strings.
 - templatesWithParams(): Returns a list of tuples with two items. The first 
item is
     a Page object of the template, the second is a list of parameters. In 
compat we have
     a list of tuples with two items. The first item is the template title.
+- linkedPages(): Returns a PageGenerator of Page objects of link targets.
+    In compat we have a list of link target strings.

 === FilePage objects ===

diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 8b4062a..38c3a76 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -488,7 +488,8 @@
                 pywikibot.log('getCommonscat: The category is a redirect')
                 return self.checkCommonscatLink(
                     commonsPage.getRedirectTarget().title(with_ns=False))
-            elif 'Category redirect' in commonsPage.templates():
+            elif (pywikibot.Page(commonsPage.site,
+                  'Template:Category redirect') in commonsPage.templates()):
                 pywikibot.log(
                     'getCommonscat: The category is a category redirect')
                 for template in commonsPage.templatesWithParams():
diff --git a/scripts/imagecopy_self.py b/scripts/imagecopy_self.py
index 4730d16..3718367 100644
--- a/scripts/imagecopy_self.py
+++ b/scripts/imagecopy_self.py
@@ -384,10 +384,11 @@

         """
         for template in imagepage.templates():
-            if template in skipTemplates[imagepage.site.lang]:
+            template_title = template.title(with_ns=False)
+            if template_title in skipTemplates[imagepage.site.lang]:
                 pywikibot.output(
                     'Found {} which is on the template skip list'
-                    .format(template))
+                    .format(template_title))
                 return True
         return False

diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py
index 8af4a9a..cdc9c57 100755
--- a/scripts/imagerecat.py
+++ b/scripts/imagerecat.py
@@ -86,7 +86,9 @@
             imagepage = pywikibot.FilePage(page.site, page.title())
             pywikibot.output('Working on ' + imagepage.title())

-            if onlyUncat and not('Uncategorized' in imagepage.templates()):
+            if (onlyUncat and not pywikibot.Page(
+                    imagepage.site, 'Template:Uncategorized')
+                    in imagepage.templates()):
                 pywikibot.output('No Uncategorized template found')
             else:
                 currentCats = getCurrentCats(imagepage)
diff --git a/scripts/maintenance/compat2core.py 
b/scripts/maintenance/compat2core.py
index 4caf605..c4b64ce 100755
--- a/scripts/maintenance/compat2core.py
+++ b/scripts/maintenance/compat2core.py
@@ -117,12 +117,17 @@
      'by a direct site request'),
     ('.verbose',
      'verbose_output need "from pywikibot import config" first'),
+    ('templates(',
+     'returns a list of templage page objects, not a list of template titles.'
+     '\nPlease refer README-conversion.txt and the documentation.'),
     ('templatesWithParams(',
      'the first item of each template info is a Page object of the template,\n'
      'not the title. '
      'Please refer README-conversion.txt and the documentation.'),
-    ('templates(',
-     'returns a list of template title not a list of templage page objects.'),
+    ('linkedPages(',
+     'returns a PageGenerator of page objects of link targets, not a list\n'
+     'of link target strings. Please refer README-conversion.txt\n'
+     'and the documentation.'),
 )


diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index a262d54..378e921 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -1039,15 +1039,17 @@

         """
         if disambPage.isRedirectPage() and not self.primary:
-            if (disambPage.site.lang in self.primary_redir_template
-                    and self.primary_redir_template[disambPage.site.lang]
-                    in disambPage.templates()):
+            primary = i18n.translate(disambPage.site,
+                                     self.primary_redir_template)
+            if primary:
+                primary_page = pywikibot.Page(disambPage.site,
+                                              'Template:' + primary)
+            if primary and primary_page in disambPage.templates():
                 baseTerm = disambPage.title()
-                for template in disambPage.templatesWithParams():
-                    if template[0] == self.primary_redir_template[
-                        disambPage.site.lang] \
-                            and len(template[1]) > 0:
-                        baseTerm = template[1][1]
+                for template, params in disambPage.templatesWithParams():
+                    if params and template == primary_page:
+                        baseTerm = params[1]
+                        break
                 disambTitle = primary_topic_format[self.mylang] % baseTerm
                 try:
                     disambPage2 = pywikibot.Page(

--
To view, visit https://gerrit.wikimedia.org/r/463660
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: If0abe8ad1653e2bc0786cf48dea214d5b94d1cbc
Gerrit-Change-Number: 463660
Gerrit-PatchSet: 5
Gerrit-Owner: Dvorapa <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: Dvorapa <[email protected]>
Gerrit-Reviewer: Framawiki <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Liuxinyu970226 <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: Zhuyifei1999 <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to