Page MenuHomePhabricator

Correct Wikidata IDs not available from Javascript of Commons categories
Open, Needs TriagePublic


In order to work around the fact that you can't create interwiki links to both Commons categories and gallery pages from a single Wikidata item, people have started creating category items on Wikidata (e.g. Category:Pizzas) and linking Commons categories to them instead of to the main conceptual items (e.g. Pizza). While this has improved the interwiki links (via some voodoo with the "category's main topic" property), it has made utilizing Wikidata from gadgets, userscripts, and client-side MediaWiki code even more difficult.

When I try to utilize the wgWikibaseItemId config variable from a category page, for example Category:Pizzas, I get one of the following results:

  • Nothing, if the item (e.g. Pizza) is linked to the gallery page instead of the category and there is no category item.
  • A useless item ID for the category item (e.g. Category:Pizzas) which has none of the actual data for the item (e.g. Pizza).
  • The correct Wikidata ID for the corresponding Wikidata item (e.g. Pizza).

Thus it's impossible to make any effective use of Wikidata from the client-side on Category pages (without making multiple round-trip API queries to Wikidata).

Event Timeline

It seems to me like the only way to resolve this would be to allow a wikidata item to have >1 sitelink to a particular wiki. Looking at the way this stuff is stored in the json, the sitelinks part of a wikidata item is a collection of links indexed by the wiki name like this

    "id": "Q209126",
    "type": "item",
    "sitelinks": {
        "enwiki": "",
        "gawiki": "",

... so it seems to me that allowing more than one sitelink per wiki would be a pretty fundamental rewrite (and even then we'd still somehow have to deal with the bad data we already have)

Another idea would be to associate the Wikidata ID with the category from the category side.

I guess that would be possible, but the extension we use for structured data on commons is specifically targeted at media files. To adapt it (or to write new code) so we could have structured data on Category pages would be a sizable project - not 2.5 years like SDoC was, but not a couple of weeks either

Krinkle removed a project: MediaWiki-Categories.
Krinkle added a subscriber: Krinkle.

Untagging from the core components for the interwiki and category systems as the task does not appear to be about a bug or request for those.