Page MenuHomePhabricator

Convert Resources.php to JSON
Open, Needs TriagePublic

Description

Almost all extensions define their ResourceLoader modules in the JSON format, as part of their extension.json files. MediaWiki core, however, defines them in PHP, in the Resources.php file.

I think we should convert it to a JSON file with the same content (or as close as possible), to make it easier for developers familiar with extensions to contribute to MediaWiki core.

Details

Event Timeline

Static PHP seems like a much more developer-friendly format, though. You can use comments, namespaces, callbacks; escaping is nicer. I wish we could convert some of extension.json back to PHP instead.

And yet we make extensions use JSON. Curious. Maybe this could be a call to action to add better support for comments or something. (I guess we have a convention that keys prefixed with @ are comments.)

While I recognise core/Resources.php is different for the purpose of module definitions, when compared to extension.json; I argue it is actually consistent. It is consistent that MediaWiki core generally defines things in PHP (MainConfigSchema, autoload, resource modules, user preferences, QUnit tests, user rights, namespace constants), and extensions generally change/add to that via extensions attributes. Those attributes used to be PHP globals, but nowadays are keys in extension.json.

As a way forward, could we start with moving just one module over to a JSON file as a proof of concept and load and splice it into the returned array at the end of Resources.php?

Change #1176429 had a related patch set uploaded (by Jforrester; author: Jforrester):

[mediawiki/core@master] [WIP] resources: Begin migrating core modules to JSON

https://gerrit.wikimedia.org/r/1176429

I have a half-done script locally that I wrote like a year ago to convert the entire Resources.php to JSON (with only a bit of manual tweaking needed). If there is interest now, I could finish that one day (and do the manual parts).

I have a half-done script locally that I wrote like a year ago to convert the entire Resources.php to JSON (with only a bit of manual tweaking needed). If there is interest now, I could finish that one day (and do the manual parts).

That'd be great. Retaining the // comments for modules would be nice, as previously stated.

The closures for callbacks should be moved to a new class in own patch set, that could make the review easier (or at least the discussion where to store it).