Page MenuHomePhabricator

Add MediaInfo.editLabels,addClaim,removeClaims functions to Pywikibot
Closed, ResolvedPublic

Description

Currently, editing structured on commons labels using MediaInfo.editEntity() throws errors in various places. Also, the function Mediainfo.editLabels() needs to be added. The current workaround for these is to use Site.editEntity().

The underlying reason for the bug is that the current Pywikibot SDC code in pywikibot/page/_wikibase.py sets Mediainfo.id = -1 until it is loaded with Mediainfo.get(). In Wikidata code, the id is already set when Mediainfo is initialized.

Additional target to fixing editLabels is to add addClaim and removeClaim functions as they start to working at same when the editLabels works.

Relevant files

FilePage.data_item()

MediaItem

The target for the ticket is to get this working.

MediaInfo.editLabels

site = pywikibot.Site('commons', 'commons')
site.login()
page = pywikibot.FilePage(site,'File:Kauppaneuvos Holger Sweins.tif')
item = page.data_item()
item.editLabels({'en': 'this is test label'})

MediaInfo.addClaim

wikidata_site = pywikibot.Site('wikidata', 'wikidata')
site = pywikibot.Site('commons', 'commons')
site.login()
page = pywikibot.FilePage(site,'File:Kauppaneuvos Holger Sweins.tif')
item = page.data_item()
property_id="P9478"
value_id="museovirasto.C397A9B678302675D32592E51E39A2BA"
new_claim = pywikibot.Claim(wikidata_site, property_id)
new_claim.setTarget(value_id)
ret=item.addClaim(new_claim)

MediaInfo.removeClaims

site = pywikibot.Site('commons', 'commons')
site.login()
page = pywikibot.FilePage(site,'File:Kauppaneuvos Holger Sweins.tif')
item = page.data_item()
for claim in item.claims[property_id]:
    item.removeClaims(claim)
    break

Event Timeline

Zache renamed this task from Add MediaInfo.editLabels() to Pywikibot to Add MediaInfo.editLabels() function to Pywikibot.Oct 9 2023, 9:00 AM
Zache renamed this task from Add MediaInfo.editLabels() function to Pywikibot to Add MediaInfo.editLabels,addClaim,removeClaims functions to Pywikibot.Oct 10 2023, 2:05 PM
Zache updated the task description. (Show Details)

Change 964925 had a related patch set uploaded (by Zache-tool; author: Zache-tool):

[pywikibot/core@master] Add MediaInfo id in initialization and edit functions.

https://gerrit.wikimedia.org/r/964925

Just thinking aloud: Write unit tests are missing because it was unknown to me how to do write tests for wikimedia commons.

Change 968553 had a related patch set uploaded (by Zache-tool; author: Zache-tool):

[pywikibot/core@master] Add MediaInfo editLabels, AddClaim and removeClaim functions.

https://gerrit.wikimedia.org/r/968553

Change 964925 abandoned by Zache-tool:

[pywikibot/core@master] Add MediaInfo id in initialization and edit functions.

Reason:

it seems that i created a new independent version for this (not on purpose though) so lets go with that https://gerrit.wikimedia.org/r/c/pywikibot/core/+/968553/

https://gerrit.wikimedia.org/r/964925

Change 968553 merged by jenkins-bot:

[pywikibot/core@master] Add MediaInfo editLabels, AddClaim and removeClaim functions.

https://gerrit.wikimedia.org/r/968553