http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11658
Revision: 11658 Author: legoktm Date: 2013-06-18 06:25:19 +0000 (Tue, 18 Jun 2013) Log Message: ----------- Fix bug with bots editconflicting themselves on Wikidata By ensuring that the claim knows what page it's on, we can pass the correct revid when adding sources/stuff
Modified Paths: -------------- branches/rewrite/pywikibot/page.py branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2013-06-17 11:38:24 UTC (rev 11657) +++ branches/rewrite/pywikibot/page.py 2013-06-18 06:25:19 UTC (rev 11658) @@ -2468,7 +2468,9 @@ for pid in self._content['claims']: self.claims[pid] = list() for claim in self._content['claims'][pid]: - self.claims[pid].append(Claim.fromJSON(self.repo, claim)) + c = Claim.fromJSON(self.repo, claim) + c.on_item = self + self.claims[pid].append(c)
#sitelinks self.sitelinks = {} @@ -2555,6 +2557,7 @@ @type bot bool """ self.repo.addClaim(self, claim, bot=bot) + claim.on_item = self
def removeClaims(self, claims, **kwargs): """ @@ -2617,6 +2620,7 @@ self.sources = [] self.target = None self.snaktype = 'value' + self.on_item = None # The item it's on
@staticmethod def fromJSON(site, data): @@ -2730,6 +2734,7 @@ """ data = self.repo.editSource(self, source, new=True, **kwargs) source.hash = data['reference']['hash'] + self.on_item.lastrevid = data['pageinfo']['lastrevid'] self.sources.append(source)
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2013-06-17 11:38:24 UTC (rev 11657) +++ branches/rewrite/pywikibot/site.py 2013-06-18 06:25:19 UTC (rev 11658) @@ -3481,6 +3481,8 @@ params = dict(action='wbsetreference', statement=claim.snak, ) + if claim.on_item: # I can't think of when this would be false, but lets be safe + params['baserevid'] = claim.on_item.lastrevid if bot: params['bot'] = 1 params['token'] = self.token(claim, 'edit')
pywikipedia-svn@lists.wikimedia.org