jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
imagetransfer.py: allow images existing in the shared repo

When transferring files from Commons to other wikis that use
Commons as a shared repo, they can't be uploaded, as they are
seen as a duplicate of the image in the shared repo.

Add a parameter -force_if_shared to override this check.

Note, the user still needs the 'reupload-shared' right at the
target wiki.

Bug: T267535
Change-Id: Ia4412c84aef09d2353017853e327071fffb07386
---
M pywikibot/specialbots/_upload.py
M scripts/imagetransfer.py
2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index c01a81d..cdc6c5b 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -49,7 +49,9 @@
chunk_size: int = 0,
asynchronous: bool = False,
summary: Optional[str] = None,
- filename_prefix: Optional[str] = None, **kwargs):
+ filename_prefix: Optional[str] = None,
+ force_if_shared: bool = False,
+ **kwargs):
"""Initializer.

*Changed in version 6.2:* asynchronous upload is used if
@@ -82,6 +84,9 @@
asynchronous on the server side when possible.
:param filename_prefix: Specify prefix for the title of every
file's page.
+ :param force_if_shared: Upload the file even if it's currently
+ shared to the target site (e.g. when moving from Commons to another
+ wiki)
:keyword always: Disables any input, requires that either
ignore_warning or aborts are set to True and that the
description is also set. It overwrites verify_description to
@@ -110,6 +115,7 @@
self.asynchronous = asynchronous
self.summary = summary
self.filename_prefix = filename_prefix
+ self.force_if_shared = force_if_shared

if config.upload_to_commons:
default_site = pywikibot.Site('commons:commons')
@@ -309,7 +315,8 @@
continue

with suppress(NoPageError):
- if potential_file_page.file_is_shared():
+ if (not self.force_if_shared
+ and potential_file_page.file_is_shared()):
pywikibot.output(
'File with name {} already exists in shared '
'repository and cannot be overwritten.'
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index 59f61ed..5767ede 100755
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -8,18 +8,22 @@

The following parameters are supported:

- -interwiki Look for images in pages found through interwiki links.
+ -interwiki Look for images in pages found through interwiki links.

- -keepname Keep the filename and do not verify description while replacing
+ -keepname Keep the filename and do not verify description while
+ replacing

- -tolang:x Copy the image to the wiki in code x
+ -tolang:x Copy the image to the wiki in code x

- -tofamily:y Copy the image to a wiki in the family y
+ -tofamily:y Copy the image to a wiki in the family y

- -tosite:s Copy the image to the given site like wikipedia:test
+ -tosite:s Copy the image to the given site like wikipedia:test

- -file:z Upload many files from textfile: [[Image:x]]
- [[Image:y]]
+ -force_if_shared Upload the file to the target, even if it exists on that
+ wiki's shared repo
+
+ -file:z Upload many files from textfile: [[Image:x]]
+ [[Image:y]]

If pagename is an image description page, offers to copy the image to the
target site. If it is a normal page, it will offer to copy any of the images
@@ -143,15 +147,20 @@
:type target_site: pywikibot.site.APISite
:keyword interwiki: Look for images in interwiki links, default false
:type interwiki: boolean
- :keyword keep_name: Keep the filename and do not verify description
+ :keyword keepname: Keep the filename and do not verify description
while replacing, default false
- :type keep_name: boolean
+ :type keepname: boolean
+ :keyword force_if_shared: Upload the file even if it's currently
+ shared to the target site (e.g. when moving from Commons to another
+ wiki)
+ :type force_if_shared: boolean
"""
self.available_options.update({
'ignore_warning': False, # not implemented yet
'interwiki': False,
'keepname': False,
'target': None,
+ 'force_if_shared': False,
})

super().__init__(**kwargs)
@@ -207,7 +216,8 @@
url_encoding=sourceSite.encoding(),
keep_filename=self.opt.keepname,
verify_description=not self.opt.keepname,
- ignore_warning=self.opt.ignore_warning)
+ ignore_warning=self.opt.ignore_warning,
+ force_if_shared=self.opt.force_if_shared)

# try to upload
if bot.skip_run():
@@ -307,7 +317,9 @@
def transfer_allowed(self, image):
"""Check whether transfer is allowed."""
target_repo = self.opt.target.image_repository()
- if image.file_is_shared() \
+
+ if not self.opt.force_if_shared \
+ and image.file_is_shared() \
and image.site.image_repository() == target_repo:
pywikibot.output(color_format(
'{yellow}The image is already shared on {}.{default}',
@@ -335,7 +347,8 @@

for arg in local_args:
opt, _, value = arg.partition(':')
- if opt in ('-ignore_warning', '-interwiki', '-keepname'):
+ if opt in ('-ignore_warning', '-interwiki', '-keepname',
+ '-force_if_shared'):
options[opt[1:]] = True
elif opt == '-tolang':
target_code = value

To view, visit change 697869. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia4412c84aef09d2353017853e327071fffb07386
Gerrit-Change-Number: 697869
Gerrit-PatchSet: 5
Gerrit-Owner: Inductiveload <inductiveload@gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged