Ricordisamoa has uploaded a new change for review.

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

Change subject: update Wikibase item on category rename
......................................................................

update Wikibase item on category rename

the 'wikibase' variable in CategoryMoveRobot is True by default,
but can be turned off by passing the '-nowb' argument

other unrelated parts of the code have not and will not be touched

bug: 64815
Change-Id: Idaaa272b30ad2e3372e70e0c6af4995998546d2d
---
M scripts/category.py
1 file changed, 24 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/39/148539/1

diff --git a/scripts/category.py b/scripts/category.py
index 3923ca0..2cfb625 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -410,7 +410,8 @@
     @deprecate_arg("withHistory", "history")
     def __init__(self, oldcat, newcat=None, batch=False, comment='',
                  inplace=False, move_oldcat=True, delete_oldcat=True,
-                 title_regex=None, history=False, pagesonly=False):
+                 title_regex=None, history=False, pagesonly=False,
+                 wikibase=True):
         """Store all given parameters in the objects attributes.
 
         @param oldcat: The move source.
@@ -428,6 +429,8 @@
         @param history: If True the history of the oldcat is posted on
             the talkpage of newcat.
         @param pagesonly: If True only move pages, not subcategories.
+        @param wikibase: If True, update the Wikibase item of the
+            old category.
         """
         self.site = pywikibot.Site()
         # Create attributes for the categories and their talk pages.
@@ -447,6 +450,7 @@
         self.title_regex = title_regex
         self.history = history
         self.pagesonly = pagesonly
+        self.wikibase = wikibase
         # Set edit summary for changed pages.
         self.comment = comment
         if not self.comment:
@@ -475,6 +479,8 @@
             else:
                 self._movecat()
                 self._movetalk()
+                if self.wikibase:
+                    self._update_item()
             if self.history:
                 self._hist()
         self._change(pagegenerators.CategorizedPageGenerator(self.oldcat))
@@ -544,6 +550,18 @@
                                        {'newcat': self.newcat.title(),
                                         'title': self.newcat.title()})
             self.oldtalk.move(self.newtalk.title(), comment)
+
+    def _update_item(self):
+        """Private function to update the Wikibase item for the category.
+        Do not use this function from outside the class.
+        """
+        if self.oldtalk.exists():
+            item = pywikibot.ItemPage.fromPage(self.oldtalk)
+            if item.exists():
+                comment = i18n.twtranslate(self.site, 'category-was-moved',
+                                           {'newcat': self.newcat.title(),
+                                            'title': self.newcat.title()})
+                item.setSitelink(self.newcat, summary=comment)
 
     def _hist(self):
         """Private function to create a history table with the history
@@ -950,6 +968,7 @@
     recurse = False
     titleRegex = None
     pagesonly = False
+    wikibase = True
     withHistory = False
     rebuild = False
     depth = 5
@@ -1008,6 +1027,8 @@
             recurse = True
         elif arg == '-pagesonly':
             pagesonly = True
+        elif arg == '-nowb':
+            wikibase = False
         elif arg == '-create':
             create_pages = True
         elif arg == '-redirect':
@@ -1051,7 +1072,8 @@
         bot = CategoryMoveRobot(oldCatTitle, newCatTitle, batchMode,
                                 editSummary, inPlace,
                                 delete_oldcat=deleteEmptySourceCat,
-                                title_regex=titleRegex, history=withHistory)
+                                title_regex=titleRegex, history=withHistory,
+                                wikibase=wikibase)
         bot.run()
     elif action == 'tidy':
         catTitle = pywikibot.input(u'Which category do you want to tidy up?')

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

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

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

Reply via email to