Page MenuHomePhabricator

[Cat-a-lot] Feature: Add Support for Categorizing JSON Data Namespace Pages
Closed, ResolvedPublic

Description

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:

  1. Go to the following category page to find different types of json pages.
  2. Open cat-a-lot by clicking its icon in the lower right corner of the window.
  3. Go to preferences and enable the "Allow categorising pages (including categories) that are not files" setting to be able to select pages.
  4. Now, select the .tab, .map or .chart page from the category provided above.
  5. 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

  1. Content Model Detection:
    • Enhanced getMarkedLabels() to retrieve the content model of pages.
    • Modified getContent() to preserve content model information.
  2. 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.
  3. 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.

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!

Event Timeline

I figured out that there were data namespace sandbox files, so I changed test category to the ticket as there are fewer possibilities for anyone to comment about test edits.

If somebody wants more test files here is original from the tickets as well

Important note: Please immediately revert any of the changes you make during this testing procedure as these are not testing pages!

Thanks a lot! Testing on sandbox pages is indeed safer and better.

Hi Adiba,

I tested the new JSON category support in Cat-a-lot and here are my findings:

  1. Adding a Category:
  1. Removing a Category:
    • I removed "OldCategory" from the same page.
    • The category was successfully removed and the JSON structure remained valid.
  1. Moving a Category:
    • I renamed "OldCategory" to "NewCategory".
    • The category name was successfully updated and the JSON structure remained valid.

Overall, the new feature works well.

Thank you for your hard work on this!