Page MenuHomePhabricator

Allow Pywikibot to stack edits to items
Open, Needs TriagePublicFeature

Description

Feature summary (what you would like to be able to do and where): Allow Pywikibot to only make local changes when adding, removing, or changing claims, labels, aliases, descriptions, and/or sitelinks. These edits can be saved in one go with save().

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution): It would allow consolidating multiple bot edits on a single item to only one edit.

Benefits (why should this be implemented?): Lowers the number of revisions that are made on an item by bots.

There has been discussion in Wikidata.

Event Timeline

Just make all changes to the item's attributes and then call item.editEntity:

item = pywikibot.ItemPage(repo, 'Q123')
item.labels['en'] = 'English label'
item.descriptions['de'] = 'German description'

claim = pywikibot.Claim(repo, 'P456')
claim.setTarget(...)
item.claims.setdefault('P456', []).append(claim)

item.editEntity(summary='edit summary')

I understand it's possible to manually do it this way, but it would be much easier if pywikibot could do it internally. It is much easier to pass in a claim with qualifiers and references added than to manually deal with all of this yourself. Plus it requires knowledge of how the editEntity dictionary needs to be structured, which isn't readily available for non-trivial examples. The entire point of having objects is that instead of needing to go down low-level like this, we can use the higher-level helper methods.

Plus it requires knowledge of how the editEntity dictionary needs to be structured, which isn't readily available for non-trivial examples.

It does not, I'm not building any dictionary in my example. You first stack the changes by setting/appending data to the entity, then you call editEntity without the data argument.

I can think of one improvement, we could enhance the ClaimCollection (item.claims) with a method like item.claims.put_claim(claim) that would inline that chain of calls.

I think maybe another option is to add optional kwarg internal to addClaim/removeClaim/etc. Then those methods will basically do what your code example is doing but without having to setdefault every time.