Page MenuHomePhabricator

ResourceLoader: Implement per module configuration
Closed, DeclinedPublic


Author: mdale

Presently javascript based configuration is global. In the context of many extensions with many dynamic loading javascript modules with lots of configuration it would be ideal to have the option to package configuration per module. Like adding a 'config' parameter to the ResourceLoaderModule register array. ( similar to messages )

If an extension or module wanted the configuration available globally it could use the existing 'ResourceLoaderGetConfigVars' hook or associate it with the loaderScripts register. Otherwise configuration would just be delivered per module registration array.

Part of this patch of course checks localSettings.php modified time as part of "resources with configuration" max timestamp checks.

Version: unspecified
Severity: enhancement



Event Timeline

bzimport raised the priority of this task from to Lowest.Nov 21 2014, 11:21 PM
bzimport set Reference to bz26901.
bzimport added a subscriber: Unknown Object (MLST).

mdale wrote:

Krinkle this would be a nice feature for RL2 efforts. So that if you have lots of modules with lots of configuration your startup module does not get overloaded with configuration.

Perhaps within the module definition you include a way to designate some configuration as global, with the default setting only packaging in the resource configuration once the module is loaded.

GSoC 2011 features per-gadget preferences. Once that is reviewed and merged back into trunk we should look at this for RL3 (too late imho for RL2, lots of stuff already).

Possible use cases:

  • Ability to change configuration options that are for one module only.
  • That ability for the site admin (from php) and (if module allows it) per-user as well from the preferences somewhere (ie. a sub pref-pane per module)
  • ResourceLoader passes this to the front-end just like it does for other things (either as a 4th component (next to scripts/styles/messages), or as a separete module implementation (like is done for mw.config and mw.user.options)
  • Moduel get can it's stuff via mw.loader.getConfig( 'modulename' ).someThing

(In reply to comment #3)

too late imho for RL2, lots of stuff already

What a pity... =(

Within the context of Gadgets this might come up again, but for ResourceLoader this is unlikely to happen.

A related thing, though, is that various modules now augment their file module with dynamic data (LanguageDataModule, MwUtilModule, etc.). Once T133462 settles, we could encourage that dynamic modules export data in a virtual subfile instead of using mw.config.

That way instead of outputting mw.config.set( generated... ); with index.js concatenated, we could instead export index.js as the main file, with a second file, like ./data.json that can be read via local require(). That would reduce some congestion in mw.config with regards to namespaces.

However, not leaving this task open for that because the above is merely an idea and usage pattern, not in itself a feature to be implemented. It can work like that for anyone after T133462.