jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/396910 )
Change subject: scripts/imagecopy.py: Add -delete option
......................................................................
scripts/imagecopy.py: Add -delete option
Add `-delete` option to `scripts/imagecopy.py`.
This option will delete the page in the wiki after the
moving process finished if the user has `sysops`
privilege in the wiki, otherwise it will be marked
for deletion.
Bug: T57522
Change-Id: I495647883eb223bebf79eb50463785841f179fb3
---
M scripts/imagecopy.py
1 file changed, 23 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
Zoranzoki21: Looks good to me, but someone else must approve
diff --git a/scripts/imagecopy.py b/scripts/imagecopy.py
index aa06cbb..f16a43a 100644
--- a/scripts/imagecopy.py
+++ b/scripts/imagecopy.py
@@ -27,6 +27,10 @@
python pwb.py imagecopy.py -cat:<cat>
Work on all images which transclude a template
python pwb.py imagecopy.py -transcludes:<template>
+Work on a single image and deletes the image when the transfer is complete
+(only works if the user has sysops privilege, otherwise it will be marked for
+deletion)
+ python pwb.py imagecopy.py -page:Image:<imagename> -delete
See pagegenerators.py for more ways to get a list of images.
By default the bot works on your home wiki (set in user-config)
@@ -210,11 +214,12 @@
"""Facilitate transfer of image/file to commons."""
- def __init__(self, imagePage, newname, category):
+ def __init__(self, imagePage, newname, category, delete_after_done=False):
"""Constructor."""
self.imagePage = imagePage
self.newname = newname
self.category = category
+ self.delete_after_done = delete_after_done
threading.Thread.__init__(self)
def run(self):
@@ -294,21 +299,27 @@
self.gen = pagegenerators.FileLinksGenerator(self.imagePage)
self.preloadingGen = pagegenerators.PreloadingGenerator(self.gen)
+ moveSummary = i18n.twtranslate(
+ self.imagePage.site,
+ 'commons-file-moved',
+ {'localfile': self.imagePage.title(withNamespace=False),
+ 'commonsfile': self.newname})
+
# If the image is uploaded under a different name, replace all
# instances
if self.imagePage.title(withNamespace=False) != self.newname:
- moveSummary = i18n.twtranslate(
- self.imagePage.site,
- 'commons-file-moved',
- {'localfile': self.imagePage.title(withNamespace=False),
- 'commonsfile': self.newname})
-
imagebot = image.ImageRobot(
generator=self.preloadingGen,
oldImage=self.imagePage.title(withNamespace=False),
newImage=self.newname,
summary=moveSummary, always=True, loose=True)
imagebot.run()
+
+ # If the user want to delete the page and
+ # the user has sysops privilege, delete the page, otherwise
+ # it will be marked for deletion.
+ if self.delete_after_done:
+ self.imagePage.delete(moveSummary, False)
return
def fixAuthor(self, pageText):
@@ -460,6 +471,7 @@
imagepage = None
always = False
category = u''
+ delete_after_done = False
# Load a lot of default generators
local_args = pywikibot.handle_args(args)
genFactory = pagegenerators.GeneratorFactory()
@@ -469,6 +481,8 @@
always = True
elif arg.startswith('-cc:'):
category = arg[len('-cc:'):]
+ elif arg == '-delete':
+ delete_after_done = True
else:
genFactory.handleArg(arg)
@@ -535,7 +549,8 @@
# the start of the loop
if not skip:
- imageTransfer(imagepage, newname, category).start()
+ imageTransfer(imagepage, newname, category,
+ delete_after_done).start()
pywikibot.output('Still ' + str(threading.activeCount()) +
' active threads, lets wait')
--
To view, visit
https://gerrit.wikimedia.org/r/396910
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I495647883eb223bebf79eb50463785841f179fb3
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Rafidaslam <rafidteam(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: MtDu <justin.d128(a)gmail.com>
Gerrit-Reviewer: Rafidaslam <rafidteam(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>