Page MenuHomePhabricator

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

Description

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

kaldari created this task.Aug 1 2019, 4:45 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptAug 1 2019, 4:45 PM
kaldari updated the task description. (Show Details)Aug 1 2019, 4:51 PM

Any thoughts on this?

Cparle added a subscriber: Cparle.Mar 31 2020, 4:56 PM

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": "https://en.wikipedia.org/wiki/Wexford",
        "gawiki": "https://ga.wikipedia.org/wiki/Loch_Garman",
        ...
    }
}

... 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.

Cparle added a comment.Apr 1 2020, 9:16 AM

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