Page MenuHomePhabricator

Implement federated Wikibase in Pywikibot
Closed, ResolvedPublic

Description

Wikibase (the software behind Wikidata) has been updated to support federation. In the old system a wiki was a database (wikidata.org) and another wiki was a client (commons.wikimedia.org). In the new system with federation a client wiki (commons) can be a database wiki too.

We should support this in Pywikibot too. Somewhere hiding on labs is already a test setup. Can someone please add a link to it?

Not sure what we have to do exactly for it,. Feel free to make this task more specific or add subtasks.

Event Timeline

AFAIK, the API works just fine on our side. pywikibot only needs implementation (which can be quite difficult)

Why is this moved to upstream? Nothing needs to be done there, we just need to implement it.

Xqt triaged this task as Medium priority.Feb 8 2019, 5:11 AM

With some refactors done, this is the last thing that Pywikibot doesn't support yet.

Not sure what we have to do exactly for it,.

Perhaps let's outline, where we want to get:


  • We want to query associated mediainfo objects, similarly to Wikidata items associated with articles. Specifically, we want this to work / not to break:
import pywikibot

site = pywikibot.Site('commons', 'commons')
page = pywikibot.Page(site, 'Wikipedia')
item = page.data_item()  # pywikibot.ItemPage(wikidata, 'Q52')
file = pywikibot.FilePage(site, 'Wikipedia-logo-v2.svg')
file_item = file.data_item()  # an object for M10337301

  • We want to load data from mediainfo objects and this data must correctly refer to its origin:
import pywikibot

file = pywikibot.FilePage(file_repo, 'Würfelzucker_--_2018_--_3564.jpg')
file_item = file.data_item()  # an object for M71019999
caption = file_item.get()['labels']['en']  # 'Sugar cubes (2018)'
depicts = file_item.statements['P180'][0].getTarget()  # pywikibot.ItemPage(wikidata, 'Q1042920')

  • We want to save only data which refers to appropriate sites:
import pywikibot

file_repo = pywikibot.Site('commons', 'commons')
data_repo = pywikibot.Site('wikidata', 'wikidata')

file = pywikibot.FilePage(file_repo, 'FooBar.jpg')
file_data = file.data_item()

item = pywikibot.ItemPage(data_repo, 'Q146')
depicts = pywikibot.Claim(data_repo, 'P180')
depicts.setTarget(item)

file_data.addClaim(depicts)

(Seems nobody cared about this yet, I was just able to save a claim on Wikidata with Q1 constructed as pywikibot.ItemPage(pywikibot.Site('test', 'wikidata'), 'Q1').)


Data from API doesn't seem to indicate the provenance and so does general information from API, so we have to hardcode this to our "family files". Either way, Commons has to become DataSite in Pywikibot and DataSite will get new methods for determining the repository. They will be useful for eg. Claim objects for setting or validating the repository.

Change 871226 had a related patch set uploaded (by Matěj Suchánek; author: Matěj Suchánek):

[pywikibot/core@master] [FEAT] Support federated Wikibase

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

Change 871226 merged by jenkins-bot:

[pywikibot/core@master] [FEAT] Support federated Wikibase

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