jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/447390 )
Change subject: Move methods for simple claim adding/removing to WikibasePage ......................................................................
Move methods for simple claim adding/removing to WikibasePage
This object already assumes in WikibasePage.get() that all WikibasePage instances have claims. This is the case for items, properties and also upcoming lexemes and mediainfo entities.
Bug: T113131 Change-Id: Iea1c82e47328588aa7f44fa3364c538d689c0cd3 --- M pywikibot/page.py M pywikibot/site.py 2 files changed, 49 insertions(+), 48 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 1a67eeb..dba0e7d 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -4230,6 +4230,46 @@ """ raise NotImplementedError
+ @allow_asynchronous + def addClaim(self, claim, bot=True, **kwargs): + """ + Add a claim to the entity. + + @param claim: The claim to add + @type claim: Claim + @param bot: Whether to flag as bot (if possible) + @type bot: bool + @keyword asynchronous: if True, launch a separate thread to add claim + asynchronously + @type asynchronous: bool + @keyword callback: a callable object that will be called after the + claim has been added. It must take two arguments: + (1) a WikibasePage object, and (2) an exception instance, + which will be None if the entity was saved successfully. This is + intended for use by bots that need to keep track of which saves + were successful. + @type callback: callable + """ + self.repo.addClaim(self, claim, bot=bot, **kwargs) + claim.on_item = self + + def removeClaims(self, claims, **kwargs): + """ + Remove the claims from the entity. + + @param claims: list of claims to be removed + @type claims: list or pywikibot.Claim + """ + # this check allows single claims to be removed by pushing them into a + # list of length one. + if isinstance(claims, pywikibot.Claim): + claims = [claims] + data = self.repo.removeClaims(claims, **kwargs) + for claim in claims: + claim.on_item.latest_revision_id = data['pageinfo']['lastrevid'] + claim.on_item = None + claim.snak = None +
class ItemPage(WikibasePage):
@@ -4534,45 +4574,6 @@ data = {'sitelinks': data} self.editEntity(data, **kwargs)
- @allow_asynchronous - def addClaim(self, claim, bot=True, **kwargs): - """ - Add a claim to the item. - - @param claim: The claim to add - @type claim: Claim - @param bot: Whether to flag as bot (if possible) - @type bot: bool - @keyword asynchronous: if True, launch a separate thread to add claim - asynchronously - @type asynchronous: bool - @keyword callback: a callable object that will be called after the - claim has been added. It must take two arguments: (1) an ItemPage - object, and (2) an exception instance, which will be None if the - item was saved successfully. This is intended for use by bots that - need to keep track of which saves were successful. - @type callback: callable - """ - self.repo.addClaim(self, claim, bot=bot, **kwargs) - claim.on_item = self - - def removeClaims(self, claims, **kwargs): - """ - Remove the claims from the item. - - @param claims: list of claims to be removed - @type claims: list or pywikibot.Claim - """ - # this check allows single claims to be removed by pushing them into a - # list of length one. - if isinstance(claims, pywikibot.Claim): - claims = [claims] - data = self.repo.removeClaims(claims, **kwargs) - for claim in claims: - claim.on_item.latest_revision_id = data['pageinfo']['lastrevid'] - claim.on_item = None - claim.snak = None - def mergeInto(self, item, **kwargs): """ Merge the item into another item. diff --git a/pywikibot/site.py b/pywikibot/site.py index ea6c6b3..db1569d 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -7719,12 +7719,12 @@ return data
@must_be(group='user') - def addClaim(self, item, claim, bot=True, summary=None): + def addClaim(self, entity, claim, bot=True, summary=None): """ Add a claim.
- @param item: Entity to modify - @type item: WikibasePage + @param entity: Entity to modify + @type entity: WikibasePage @param claim: Claim to be added @type claim: pywikibot.Claim @param bot: Whether to mark the edit as a bot edit @@ -7732,8 +7732,8 @@ @param summary: Edit summary @type summary: str """ - params = {'action': 'wbcreateclaim', 'entity': item.getID(), - 'baserevid': item.latest_revision_id, + params = {'action': 'wbcreateclaim', 'entity': entity.getID(), + 'baserevid': entity.latest_revision_id, 'snaktype': claim.getSnakType(), 'property': claim.getID(), 'summary': summary, 'bot': bot}
@@ -7745,11 +7745,11 @@ data = req.submit() claim.snak = data['claim']['id'] # Update the item - if claim.getID() in item.claims: - item.claims[claim.getID()].append(claim) + if claim.getID() in entity.claims: + entity.claims[claim.getID()].append(claim) else: - item.claims[claim.getID()] = [claim] - item.latest_revision_id = data['pageinfo']['lastrevid'] + entity.claims[claim.getID()] = [claim] + entity.latest_revision_id = data['pageinfo']['lastrevid']
@must_be(group='user') def changeClaimTarget(self, claim, snaktype='value',
pywikibot-commits@lists.wikimedia.org