Problem (T387090):
In February 2025, a categorization feature for the Data namespace was added to Wikimedia Commons. Categories in this namespace are defined in the mediawikiCategories parameter within the JSON data of a page. Unlike regular pages, these do not support wikitext, and attempting to use wikitext-based categorization tools results in error. As a result, tools like HotCat and Cat-a-lot currently do not function for pages using the JSON content model.
Procedure to replicate the problem:
- Go to the following category page to find different types of json pages.
- Open cat-a-lot by clicking its icon in the lower right corner of the window.
- Go to preferences and enable the "Allow categorising pages (including categories) that are not files" setting to be able to select pages.
- Now, select the .tab, .map or .chart page from the category provided above.
- Try to copy or move the selected page to a different category.
Current Outcome:
The loader gets stuck indefinitely and no edit occurs.
Expected Outcome:
The appropriate edit is applied
Fix Implemented
After thorough testing, Cat-a-lot now fully supports both wikitext and JSON content model pages for all category operations.
Key Changes in Gadget-Cat-a-lot.js
- Content Model Detection:
- Enhanced getMarkedLabels() to retrieve the content model of pages.
- Modified getContent() to preserve content model information.
- Dual Processing Paths:
- Refactored editCategories() to act as a router function that:
- Detects content type (wikitext vs JSON).
- Calls the appropriate editor function.
- Kept editWikitextCategories() unchanged for traditional pages.
- Created editJsonCategories() for handling JSON-based categorization.
- Refactored editCategories() to act as a router function that:
- JSON-Specific Implementation:
- Added full support for category operations on JSON pages:
- Add → Pushes new category into mediawikiCategories.
- Remove → Filters out the category from the array.
- Copy → Duplicates category entries under a new name.
- Move → Removes the source category and adds the target category.
- Implemented proper JSON parsing/serialization to ensure correct formatting.
- Modified API calls to include contentmodel=json when necessary.
- Added full support for category operations on JSON pages:
Code Changes for Review: Gadget-Cat-a-lot.js: View Diff
How to Load the Updated Script:
To test the new JSON category support, load the modified script in your common.js
mw.loader.load('//commons.wikimedia.org/w/index.php?title=User:Adiba_anjum3/data-namespace-cat-a-lot.js&action=raw&ctype=text/javascript');Summary:
With these changes, Cat-a-lot now fully supports categorizing JSON Data namespace pages, fixing compatibility issues with mediawikiCategories. I’d appreciate any feedback on this update. Let me know if you notice any issues or have suggestions for improvements.
Thanks!