jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/447397 )
Change subject: [IMPR] Support adding new claims with qualifiers and/or references ......................................................................
[IMPR] Support adding new claims with qualifiers and/or references
This requires changing the called API module to wbsetclaim, as well as a dependency on uuid.
Bug: T112577 Bug: T170432 Change-Id: Id44613daa30ad7b8ba40134e4db496a0e4a927b0 --- M pywikibot/page.py M pywikibot/site.py 2 files changed, 24 insertions(+), 14 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 92118bd..6241382 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -4266,6 +4266,13 @@ """ self.repo.addClaim(self, claim, bot=bot, **kwargs) claim.on_item = self + for snaks in claim.qualifiers.values(): + for snak in snaks: + snak.on_item = self + for source in claim.sources: + for snaks in source.values(): + for snak in snaks: + snak.on_item = self
def removeClaims(self, claims, **kwargs): """ @@ -5113,11 +5120,14 @@ @param claims: the claims to add @type claims: list of pywikibot.Claim """ - data = self.repo.editSource(self, claims, new=True, **kwargs) - self.on_item.latest_revision_id = data['pageinfo']['lastrevid'] + if self.on_item is not None: + data = self.repo.editSource(self, claims, new=True, **kwargs) + self.on_item.latest_revision_id = data['pageinfo']['lastrevid'] + for claim in claims: + claim.hash = data['reference']['hash'] source = defaultdict(list) for claim in claims: - claim.hash = data['reference']['hash'] + claim.isReference = True source[claim.getID()].append(claim) self.sources.append(source)
@@ -5150,9 +5160,10 @@ @param qualifier: the qualifier to add @type qualifier: Claim """ - data = self.repo.editQualifier(self, qualifier, **kwargs) + if self.on_item is not None: + data = self.repo.editQualifier(self, qualifier, **kwargs) + self.on_item.latest_revision_id = data['pageinfo']['lastrevid'] qualifier.isQualifier = True - self.on_item.latest_revision_id = data['pageinfo']['lastrevid'] if qualifier.getID() in self.qualifiers: self.qualifiers[qualifier.getID()].append(qualifier) else: diff --git a/pywikibot/site.py b/pywikibot/site.py index ea0b4a3..d92be9a 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -24,6 +24,7 @@ import sys import threading import time +import uuid
try: from collections.abc import Iterable, Container, Mapping @@ -7780,18 +7781,16 @@ @param summary: Edit summary @type summary: str """ - params = {'action': 'wbcreateclaim', 'entity': entity.getID(), + claim.snak = entity.getID() + '$' + str(uuid.uuid4()) + params = {'action': 'wbsetclaim', + 'claim': json.dumps(claim.toJSON()), 'baserevid': entity.latest_revision_id, - 'snaktype': claim.getSnakType(), 'property': claim.getID(), - 'summary': summary, 'bot': bot} - - if claim.getSnakType() == 'value': - params['value'] = json.dumps(claim._formatValue()) - - params['token'] = self.tokens['edit'] + 'summary': summary, + 'token': self.tokens['edit'], + 'bot': bot, + } req = self._simple_request(**params) data = req.submit() - claim.snak = data['claim']['id'] # Update the item if claim.getID() in entity.claims: entity.claims[claim.getID()].append(claim)
pywikibot-commits@lists.wikimedia.org