jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697446 )

Change subject: [IMPR] fixing_redirects.py: add overwrite parameter
......................................................................

[IMPR] fixing_redirects.py: add overwrite parameter

Bug: T235219
Change-Id: Ie4fefdada948883a5b55dc5a085bce7b6f4910e1
---
M scripts/fixing_redirects.py
1 file changed, 19 insertions(+), 5 deletions(-)

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



diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index f80e326..12193bd 100755
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -6,6 +6,10 @@

 -featured         Run over featured pages (for some Wikimedia wikis only)

+-overwrite        Usually only the link is changed ([[Foo]] -> [[Bar|Foo]]).
+                  This parameters sets the script to completly overwrite the
+                  link text ([[Foo]] -> [[Bar]]).
+
 &params;
 """
 #
@@ -55,6 +59,14 @@
     ignore_server_errors = True
     summary_key = 'fixing_redirects-fixing'

+    def __init__(self, **kwargs) -> None:
+        """Initializer."""
+        self.available_options.update({
+            'overwrite': False,
+        })
+
+        super().__init__(**kwargs)
+
     def replace_links(self, text, linkedPage, targetPage):
         """Replace all source links by target."""
         mysite = pywikibot.Site()
@@ -127,7 +139,8 @@
             if new_page_title[0] == ':':
                 new_page_title = new_page_title[1:]

-            if (new_page_title == link_text and not section):
+            if ((new_page_title == link_text and not section)
+                    or self.opt.overwrite):
                 newlink = '[[{}]]'.format(new_page_title)
             # check if we can create a link with trailing characters instead of
             # a pipelink
@@ -212,6 +225,7 @@
     @type args: str
     """
     featured = False
+    options = {}
     gen = None

     # Process global args and prepare generator args parser
@@ -221,6 +235,8 @@
     for arg in local_args:
         if arg == '-featured':
             featured = True
+        elif arg == '-overwrite':
+            options['overwrite'] = True
         elif genFactory.handle_arg(arg):
             pass

@@ -241,11 +257,9 @@
                 additional_text='Option is not available for this site.')
             return
     else:
-        gen = genFactory.getCombinedGenerator()
-        if gen:
-            gen = mysite.preloadpages(gen)
+        gen = genFactory.getCombinedGenerator(preload=True)
     if gen:
-        bot = FixingRedirectBot(generator=gen)
+        bot = FixingRedirectBot(generator=gen, **options)
         bot.run()
     else:
         suggest_help(missing_generator=True)

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697446
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: Ie4fefdada948883a5b55dc5a085bce7b6f4910e1
Gerrit-Change-Number: 697446
Gerrit-PatchSet: 14
Gerrit-Owner: Zabe <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: JAn Dudík <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Meno25 <[email protected]>
Gerrit-Reviewer: Rubin <[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