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 and linking Commons categories to them instead of to the main conceptual items. 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.
Now, when I try to utilize the `wgWikibaseItemId` config variable from a category page, for example [[ https://commons.wikimedia.org/wiki/Category:Pizzas | Category:Pizzas ]], I get one of the following results:
* Nothing, if the item (e.g. [[ https://www.wikidata.org/wiki/Q177 | 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. [[ https://www.wikidata.org/wiki/Q6931672 | Category:Pizzas ]]) which has none of the actual data for the item (e.g. [[ https://www.wikidata.org/wiki/Q177 | Pizza ]]).
* The correct Wikidata ID for the corresponding Wikidata item (e.g. [[ https://www.wikidata.org/wiki/Q177 | 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).