Page MenuHomePhabricator

Self-hosted Wikibase has no API to search sitelinks
Closed, InvalidPublic

Description

Installing Wikibase as both a repo and a client on the same wiki, and using local sitelinks makes it impossible to get Wikibase item by using the sitelink string via MW API.

For example, in OSM wiki, which is both a client and a wikibase repo, each item has a sitelink:
Q104 -> Key:bridge:movable. Note that the sitelink is shown at the top right corner using a CSS hack. The site name is wiki.

A very common operation is to get the item by knowing the Key:bridge:movable string. A user can navigate to it with the Special:ItemByTitle/wiki/Key:highway. Lua code can get it with mw.wikibase.getEntityIdForTitle( 'Key:bridge:movable' ). But there seems to be no clean way to do that via MW API, which seems like a big omission.

Some (bad) workarounds:

  • Use internal scribunto API module: {action: 'scribunto-console', format: 'json', title: 'Module:Sandbox', question: "=mw.wikibase.getEntityIdForTitle( 'Key:bridge:movable' )"} - try it. This is bad because it is not cachable, and because being internal, it could change at any moment.
  • Create a dedicated protected Lua module, and use action=parse to call it

Event Timeline

Can you not sure action=wbgetentities with the sites and titles parameters?

@Addshore thanks! It does work indeed! I saw that many query modules were marked with Caveat: On a repo wiki, this module only works directly on entity pages, not on pages connected to an entity via a sitelink. This may change in the future., and I couldn't find any way around it. Thanks for the quick help!

https://wiki.openstreetmap.org/w/api.php?action=wbgetentities&sites=wiki&titles=Key:bridge:movable&languages=en