Right now the mw object is overloaded with various things and used as a place to register modules. This is confusing as it doesn't make it clear what can be initiated and what cannot and which ResourceLoader module stuff lives.
This leads to code such as mw.mobileFrontend, mw.cnBannerControllerLib, mw.webfonts, mw.uls and so on so on so on...
We already have jQuery and OO.ui but these can be extended in standard ways. Do we have a similar plan for mediawiki specific code?
What I would like to see is something similar to how our templates work and a cleaner way to register code that other extensions can use.
mw.template.get( 'moduleName', 'template.mustache' )
Mobilefrontend has a concept of mw.mobileFrontend.require and mw.mobileFrontend.define for controlling access to public interfaces [1]. Could we imagine a similar mechanism for core?
Proposed syntax: require and module.exports (methods scoped to module execution context, not a public interface)
// my-module-foo.js # scope( module ) module.exports = { doThings: function () { .. } }; // mediawiki.js # mw.loader script( module ); // my-other-module.js # scope( require ) require( 'mediawiki.foo', function ( foo ) { foo.doThings(); } );
What are people's thoughts on this? I would like a cleaner way to access stuff that's not a jQuery module and not an OO.ui module.