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

Change subject: [IMPR] Add movesubpages parmeter to Page.move() and 
Site.movepage()
......................................................................

[IMPR] Add movesubpages parmeter to Page.move() and Site.movepage()

Also add the new option to movepages.py

Bug: T57084
Change-Id: I529b95c0d3ad09cc3ea187e114cf873538c97fb6
---
M pywikibot/page/_pages.py
M pywikibot/site/_apisite.py
M scripts/movepages.py
3 files changed, 54 insertions(+), 45 deletions(-)

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



diff --git a/pywikibot/page/_pages.py b/pywikibot/page/_pages.py
index 3d48204..7608c83 100644
--- a/pywikibot/page/_pages.py
+++ b/pywikibot/page/_pages.py
@@ -1773,15 +1773,20 @@
              newtitle: str,
              reason: Optional[str] = None,
              movetalk: bool = True,
-             noredirect: bool = False):
+             noredirect: bool = False,
+             movesubpages: bool = True) -> None:
         """
         Move this page to a new title.

+        .. versionchanged:: 7.2
+           The `movesubpages` parameter was added
+
         :param newtitle: The new page title.
         :param reason: The edit summary for the move.
         :param movetalk: If true, move this page's talk page (if it exists)
         :param noredirect: if move succeeds, delete the old page
             (usually requires sysop privileges, depending on wiki settings)
+        :param movesubpages: Rename subpages, if applicable.
         """
         if reason is None:
             pywikibot.output('Moving {} to [[{}]].'
@@ -1789,7 +1794,8 @@
             reason = pywikibot.input('Please enter a reason for the move:')
         return self.site.movepage(self, newtitle, reason,
                                   movetalk=movetalk,
-                                  noredirect=noredirect)
+                                  noredirect=noredirect,
+                                  movesubpages=movesubpages)

     def delete(
         self,
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index df15811..c1d0021 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -2025,11 +2025,15 @@
         newtitle: str,
         summary: str,
         movetalk: bool = True,
-        noredirect: bool = False
+        noredirect: bool = False,
+        movesubpages: bool = True
     ) -> 'pywikibot.page.Page':
         """Move a Page to a new title.

-        :see: https://www.mediawiki.org/wiki/API:Move
+        .. seealso:: https://www.mediawiki.org/wiki/API:Move
+
+        .. versionchanged:: 7.2
+           The `movesubpages` parameter was added

         :param page: the Page to be moved (must exist)
         :param newtitle: the new title for the Page
@@ -2037,6 +2041,7 @@
         :param movetalk: if True (default), also move the talk page if possible
         :param noredirect: if True, suppress creation of a redirect from the
             old title to the new one
+        :param movesubpages: Rename subpages, if applicable.
         :return: Page object with the new title
         """
         oldtitle = page.title(with_section=False)
@@ -2059,6 +2064,7 @@
                                   noredirect=noredirect,
                                   reason=summary,
                                   movetalk=movetalk,
+                                  movesubpages=movesubpages,
                                   token=token,
                                   to=newtitle)
         req['from'] = oldtitle  # "from" is a python keyword
diff --git a/scripts/movepages.py b/scripts/movepages.py
index 75f4536..118dc9c 100755
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -14,6 +14,8 @@

 -notalkpage       Do not move this page's talk page (if it exists)

+-nosubpages       Do not move subpages
+
 -prefix           Move pages by adding a namespace prefix to the names of the
                   pages. (Will remove the old namespace prefix if any)
                   Argument can also be given as "-prefix:namespace:".
@@ -50,12 +52,17 @@

 class MovePagesBot(CurrentPageBot):

-    """Page move bot."""
+    """Page move bot.
+
+    .. versionchanged:: 7.2
+       `movesubpages` option was added
+    """

     update_options = {
         'prefix': '',
         'noredirect': False,
         'movetalkpage': True,
+        'movesubpages': True,
         'skipredirects': False,
         'summary': '',
     }
@@ -69,18 +76,18 @@

     def move_one(self, page, new_page_tite) -> None:
         """Move one page to new_page_tite."""
+        msg = self.opt.summary
+        if not msg:
+            msg = i18n.twtranslate(page.site, 'movepages-moving')
+        pywikibot.output('Moving page {} to [[{}]]'
+                         .format(page, new_page_tite))
         try:
-            msg = self.opt.summary
-            if not msg:
-                msg = i18n.twtranslate(page.site, 'movepages-moving')
-            pywikibot.output('Moving page {} to [[{}]]'
-                             .format(page, new_page_tite))
-            page.move(
-                new_page_tite, reason=msg,
-                movetalk=self.opt.movetalkpage,
-                noredirect=self.opt.noredirect)
-        except PageRelatedError as error:
-            pywikibot.output(error)
+            page.move(new_page_tite, reason=msg,
+                      movetalk=self.opt.movetalkpage,
+                      movesubpages=self.opt.movesubpages,
+                      noredirect=self.opt.noredirect)
+        except PageRelatedError:
+            pywikibot.exception()

     def skip_page(self, page):
         """Treat only non-redirect pages if 'skipredirects' is set."""
@@ -178,7 +185,6 @@
     If args is an empty list, sys.argv is used.

     :param args: command line arguments
-    :type args: str
     """
     old_name = None
     options = {}
@@ -190,12 +196,13 @@
     local_args = gen_factory.handle_args(local_args)

     for arg in local_args:
-        if arg.startswith('-pairsfile'):
-            if len(arg) == len('-pairsfile'):
-                filename = pywikibot.input(
-                    'Enter the name of the file containing pairs:')
-            else:
-                filename = arg[len('-pairsfile:'):]
+        opt, _, value = arg.partition(':')
+        if opt.startswith('-'):
+            continue
+        opt = opt[1:]
+        if opt == 'pairsfile':
+            filename = value or pywikibot.input(
+                'Enter the name of the file containing pairs:')
             old_name1 = None
             for page in pagegenerators.TextIOPageGenerator(filename):
                 if old_name1:
@@ -206,34 +213,24 @@
             if old_name1:
                 pywikibot.warning(
                     'file {} contains odd number of links'.format(filename))
-        elif arg == '-noredirect':
-            options['noredirect'] = True
-        elif arg == '-notalkpage':
-            options['movetalkpage'] = False
-        elif arg == '-always':
-            options['always'] = True
-        elif arg == '-skipredirects':
-            options['skipredirects'] = True
-        elif arg.startswith('-from:'):
+        elif opt in ('always', 'noredirect', 'skipredirects'):
+            options[opt] = True
+        elif opt in ('notalkpage', 'nosubpages'):
+            options[opt.replace('no', 'move', 1)] = False
+        elif opt == 'from':
             if old_name:
                 pywikibot.warning('-from:{} without -to:'.format(old_name))
-            old_name = arg[len('-from:'):]
-        elif arg.startswith('-to:'):
+            old_name = value
+        elif opt == 'to:':
             if old_name:
-                from_to_pairs.append([old_name, arg[len('-to:'):]])
+                from_to_pairs.append([old_name, value])
                 old_name = None
             else:
                 pywikibot.warning('{} without -from'.format(arg))
-        elif arg.startswith('-prefix'):
-            if len(arg) == len('-prefix'):
-                options['prefix'] = pywikibot.input('Enter the prefix:')
-            else:
-                options['prefix'] = arg[8:]
-        elif arg.startswith('-summary'):
-            if len(arg) == len('-summary'):
-                options['summary'] = pywikibot.input('Enter the summary:')
-            else:
-                options['summary'] = arg[9:]
+        elif opt == 'prefix':
+            options[opt] = value or pywikibot.input('Enter the prefix:')
+        elif opt == 'summary':
+            options[opt] = value or pywikibot.input('Enter the summary:')

     if old_name:
         pywikibot.warning('-from:{} without -to:'.format(old_name))

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/772403
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: I529b95c0d3ad09cc3ea187e114cf873538c97fb6
Gerrit-Change-Number: 772403
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Bodhisattwa <[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