jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/698156 )
Change subject: [bugfix] Clean up DataSite._wbset_action
......................................................................
[bugfix] Clean up DataSite._wbset_action
- Fix prepare_data for wbsetaliases:
-- Intersection of two sets will never be equal to an (empty) dict.
-- Make it not contradict the main docstring.
- Fix 'bot' argument: in Pywikibot, the default is True and there is
no reason to have it different here.
- Support WikibaseEntity.
- Support lazy-loading for pywikibot.Page as the definition.
- Support 'tags' as a keyword argument since it is already
supported by the API.
- Add @need_right.
- Clean up typos.
Change-Id: Ib0126fcfec322a46ad95612ed7db77b61ec97fde
---
M pywikibot/site/_datasite.py
1 file changed, 22 insertions(+), 18 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index 8b271b3..56dd857 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -740,16 +740,17 @@
total=total, parameters=parameters)
return gen
+ @need_right('edit')
def _wbset_action(self, itemdef, action, action_data, **kwargs):
"""
- Execute wbset{action}' on a Wikibase entity.
+ Execute wbset{action} on a Wikibase entity.
Supported actions are:
wbsetaliases, wbsetdescription, wbsetlabel and wbsetsitelink
:param itemdef: Item to modify or create
- :type itemdef: str, WikibasePage or Page coonected to such item
- :param action: wbset{action] to perform:
+ :type itemdef: str, WikibaseEntity or Page connected to such item
+ :param action: wbset{action} to perform:
'wbsetaliases', 'wbsetdescription', 'wbsetlabel', 'wbsetsitelink'
:type action: str
:param data: data to be used in API request, see API help
@@ -767,8 +768,10 @@
wbsetsitelink:
dict shall have keys 'linksite', 'linktitle' and
optionally 'badges'
- @kwargs bot: Whether to mark the edit as a bot edit, default is False
+ @kwargs bot: Whether to mark the edit as a bot edit, default is True
:type bot: bool
+ @kwargs tags: Change tags to apply with the edit
+ :type tags: list of str
:return: query result
:rtype: dict
:raises AssertionError, TypeError
@@ -792,8 +795,10 @@
res = data
keys = set(res)
assert keys < {'language', 'add', 'remove', 'set'}
- assert keys & {'add', 'set'} == {}
- assert keys & {'remove', 'set'} == {}
+ assert 'language' in keys
+ assert ({'add', 'remove', 'set'} & keys)
+ assert not ({'add', 'set'} < keys)
+ assert not ({'remove', 'set'} < keys)
elif action in ('wbsetlabel', 'wbsetdescription'):
res = data
keys = set(res)
@@ -817,30 +822,29 @@
if isinstance(itemdef, str):
itemdef = self.get_entity_for_entity_id(itemdef)
elif isinstance(itemdef, pywikibot.Page):
- try:
- itemdef = itemdef.data_item()
- except NoPageError:
- itemdef = pywikibot.ItemPage(self)
- if not isinstance(itemdef, pywikibot.page.WikibasePage):
- raise TypeError('itemdef shall be str, WikibasePage or Page')
+ itemdef = pywikibot.ItemPage.fromPage(lazy_load=True)
+ elif not isinstance(itemdef, pywikibot.page.WikibaseEntity):
+ raise TypeError('itemdef shall be str, WikibaseEntity or Page')
params = itemdef._defined_by(singular=True)
# TODO: support 'new'
- baserevid = kwargs.pop('baserevid', 0) or itemdef.latest_revision_id
+ baserevid = kwargs.pop(
+ 'baserevid',
+ itemdef.latest_revision_id if 'id' in params else 0
+ )
params.update(
- {'id': itemdef.id,
- 'baserevid': baserevid,
+ {'baserevid': baserevid,
'action': action,
'token': self.tokens['edit'],
- 'bot': kwargs.pop('bot', False),
+ 'bot': kwargs.pop('bot', True),
})
params.update(prepare_data(action, action_data))
for arg in kwargs:
- if arg in ['summary']:
+ if arg in ['summary', 'tags']:
params[arg] = kwargs[arg]
else:
- warn('Unknown parameter {} for action {}, ignored'
+ warn('Unknown parameter {} for action {}, ignored'
.format(arg, action), UserWarning, 2)
req = self._simple_request(**params)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/698156
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: Ib0126fcfec322a46ad95612ed7db77b61ec97fde
Gerrit-Change-Number: 698156
Gerrit-PatchSet: 1
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697869 )
Change subject: imagetransfer.py: allow images existing in the shared repo
......................................................................
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(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
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 https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697869
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: Ia4412c84aef09d2353017853e327071fffb07386
Gerrit-Change-Number: 697869
Gerrit-PatchSet: 5
Gerrit-Owner: Inductiveload <inductiveload(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697937 )
Change subject: [doc] Fix link
......................................................................
[doc] Fix link
Change-Id: Ic56e8cff426f680e23ed5a83b071286c2917de94
---
M docs/glossary.rst
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/glossary.rst b/docs/glossary.rst
index 49a49e8..2de688d 100644
--- a/docs/glossary.rst
+++ b/docs/glossary.rst
@@ -15,7 +15,7 @@
The first Pywikibot package formerly known as *Pywikipediabot*
also called :term:`trunk` was started in 2003. MediaWiki didn't
have an API so a `screen scrapping
- <https://en.wikipedia.org/Screen_scraper>`_ was used.
+ <https://en.wikipedia.org/wiki/Screen_scraper>`_ was used.
core
In 2007 a new branch of Pywikibot formerly known as
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/697937
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: Ic56e8cff426f680e23ed5a83b071286c2917de94
Gerrit-Change-Number: 697937
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged