jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1005523?usp=email )

Change subject: [bugfix] Use site.code instead of site.lang in interwiki.py
......................................................................

[bugfix] Use site.code instead of site.lang in interwiki.py

The site.code specifies the site. This may be different from language
spezifier 'lang'. Therefore Use site.code instead of site.lang.

Also add a new method get_alternative() to ask for a alternative page
hint to prevent code duplication.

Change-Id: I15d66b29d13bbf60c31c5a1cb0003d53601110ae
---
M scripts/interwiki.py
1 file changed, 42 insertions(+), 21 deletions(-)

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




diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index ead72d0..33102ef 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -821,6 +821,21 @@
             or self.namespaceMismatch(page, target, counter) \
             or self.wiktionaryMismatch(target)

+    def get_alternative(
+        self,
+        site: pywikibot.site.BaseSite
+    ) -> pywikibot.Page | None:
+        """Ask for an alternative Page for a given site.
+
+        :param site: a BaseSite
+        """
+        title = pywikibot.input(f'Give the alternative page for code '
+                                f'{site.code!r} (without site code)')
+        if title:
+            return pywikibot.Page(site, title)
+
+        return None
+
     def namespaceMismatch(self, linkingPage, linkedPage, counter) -> bool:
         """
         Check whether or not the given page has a different namespace.
@@ -836,9 +851,9 @@
             # Allow for a mapping between different namespaces
             crossFrom = self.origin.site.family.crossnamespace.get(
                 self.origin.namespace(), {})
-            crossTo = crossFrom.get(self.origin.site.lang,
+            crossTo = crossFrom.get(self.origin.site.code,
                                     crossFrom.get('_default', {}))
-            nsmatch = crossTo.get(linkedPage.site.lang,
+            nsmatch = crossTo.get(linkedPage.site.code,
                                   crossTo.get('_default', []))
             if linkedPage.namespace() in nsmatch:
                 return False
@@ -879,15 +894,10 @@
                 if choice == 'g':
                     self.makeForcedStop(counter)
                 elif choice == 'a':
-                    newHint = pywikibot.input(
-                        'Give the alternative for language {}, not '
-                        'using a language code:'
-                        .format(linkedPage.site.lang))
-                    if newHint:
-                        alternativePage = pywikibot.Page(
-                            linkedPage.site, newHint)
+                    alternative_page = self.get_alternative(linkedPage.site)
+                    if alternative_page:
                         # add the page that was entered by the user
-                        self.addIfNew(alternativePage, counter, None)
+                        self.addIfNew(alternative_page, counter, None)
                 else:
                     pywikibot.info(
                         f'NOTE: ignoring {linkedPage} and its interwiki links')
@@ -986,11 +996,8 @@
                 return (True, None)

             if choice == 'a':
-                newHint = pywikibot.input(
-                    f'Give the alternative for language {page.site.lang}, '
-                    f'not using a language code:')
-                alternativePage = pywikibot.Page(page.site, newHint)
-                return (True, alternativePage)
+                alternative_page = self.get_alternative(page.site)
+                return (True, alternative_page)

             if choice == 'g':
                 self.makeForcedStop(counter)
@@ -1001,7 +1008,7 @@

     def isIgnored(self, page) -> bool:
         """Return True if pages is to be ignored."""
-        if page.site.lang in self.conf.neverlink:
+        if page.site.code in self.conf.neverlink:
             pywikibot.info(f'Skipping link {page} to an ignored language')
             return True

@@ -1183,7 +1190,7 @@
                 # Ignore the interwiki links.
                 iw = ()
             if self.conf.lacklanguage \
-               and self.conf.lacklanguage in (link.site.lang for link in iw):
+               and self.conf.lacklanguage in (link.site.code for link in iw):
                 iw = ()
                 self.workonme = False
             if len(iw) < self.conf.minlinks:
@@ -1269,10 +1276,9 @@
                 if dictName is not None:
                     if self.origin:
                         pywikibot.warning(
-                            '{}:{} relates to {}:{}, which is an '
-                            'auto entry {}({})'
-                            .format(self.origin.site.lang, self.origin,
-                                    page.site.lang, page, dictName, year))
+                            f'{self.origin.site.code}:{self.origin} relates '
+                            f'to {page.site.code}:{page}, which is an auto '
+                            f'entry {dictName}({year})')

                     # Abort processing if the bot is running in autonomous mode
                     if self.conf.autonomous:

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1005523?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I15d66b29d13bbf60c31c5a1cb0003d53601110ae
Gerrit-Change-Number: 1005523
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to