Page MenuHomePhabricator

Add mediawikiCategories parameter support to HotCat
Closed, ResolvedPublic

Description

In February 2025, a categorization feature for the data namespace was added to Wikimedia Commons (T242596). These categories are defined in the JSON data of the page using the mediawikiCategories parameter. Pages in this namespace do not support wikitext and will throw a content format text/x-wiki is not supported by the content model Tabular.JsonConfig error if wikitext is added.

Currently, this means that category tools like HotCat or Cat-a-lot will not work for these pages and support for JSON content model should be added to these tools.

Example pages which are using mediawikiCategories parameter:

Howto test version

Remove HotCat from Wikimedia Commons preferences and then add this to your user:username/common.js (example)

mw.loader.load('//commons.wikimedia.org/wiki/User:Zache-test/Gadget-HotCat-T387094.js&action=raw&ctype=text/javascript');

Event Timeline

Hey, HotCat is now working on Data namespace pages. It now:

  • Shows existing categories from mediawikiCategories
  • Properly adds/removes categories without JSON errors
  • Maintains valid JSON structure

You can test it by disabling HotCat from your preferences and adding following to your common.js :

mw.loader.load('//commons.wikimedia.org/w/index.php?title=User:Adiba_anjum3/HotCat.js&action=raw&ctype=text/javascript');

You can use the files from the following category for testing: Category:Cat-a-lot data namespace test pages
diff for reference

Hi, thank you very much! I checked the changes and the code worked. Here are my notes about how I would change it further:

  • Instead of just checking if the wgPageContentModel is wikitext and if not then trying to parse content as json, I would check that the expected pageContentModel is exactly the one we think it is. It would make the function more robust when new content models are added.
  • I also moved the wikitext and json handling to separate functions. This was to make the code easier to read when there are clear code paths for different cases. It also makes easier to see that changes doesn't break anything in the wikicode side by mistake.
  • In find_category() there was a difference in wikitext and json handling when once parameter was true. The wikitext handler returned direct regexp value as array [ "one", "two", "three" ] and json handling returned it as { match : [ "one", "two", "three"] }. This didn't cause any problems as in data namespace pages code just checked if the returned value was not null. However, I changed the code so that in both cases the returned value was in the same format.

Here is links to my version and diff to your version: user:Zache-test/Gadget-HotCat-T387094.js ( diff )

Thanks a lot for the detailed feedback and improvements! I completely agree, your fix makes the behavior much clearer and consistent. I’ve reviewed your version and it all looks great!

@Tacsipacsi : If you have time, could you do a code review for user:Zache-test/Gadget-HotCat-T387094.js ( diff ) before we make the edit request to  mediawiki:Gadget-HotCat.js?

I just would like to have additional round of check before asking to update the high-usage gadget.