Last modified: 2011-06-26 13:39:09 UTC
I extended the mw.loader.load function to automatically detect internal links, for example "User:Edokter/MenuToTabs.js", as a substitute for importScript and importStylesheet. It does so by examining the extension first to see if it is an URL or a module. It then checks for "http://" or "https://" and builds a full link if is internal. A possible improvement would be to use load.php directly instead of linking to index.php for internal links. This patch works under the assumption that a module name never ends with ".css" or ".js". If that is not the case, then discard this patch. Another function would then have to be added.
Created attachment 8705 [details] Patch for mediawiki.js
Created attachment 8706 [details] Patch for mediawiki.js Corrected error.
Created attachment 8707 [details] Patch for mediawiki.js Forgot to mark as patch.
See also: * bug 27561 * bug 27535 Support for loading loose wiki pages as scripts is not intended to not be added to ResourceLoader. The legacy functions importScript and importStylesheet provide this for existing scripts that don't use ResourceLoader yet. Those wishing to switch to resourceloader should register themselfs as a module and load it through mw.loader.loader( 'modulename' ). User created scripts (ie. not server side extensions) can registery modules through the Gadget interface by using the [ResourceLoader] keyword. eg. MediaWiki:Gadgets-definition: *foobar[ResourceLoader]|foobar.js|foobar.css mw.loader.load( 'mw.ext.gadget.foobar' ); - In ResourcerLoader 2.0 (MediaWiki 1.19 or 1.20) this will be further developed into an easy-to-use Special:GadgetManager in which modules can be created with more options and configuration. As well as cross-wiki gadgets.
Yes, I realize my method would load the script raw. I was concerned we would have no replacement for importScript before it is too late. I will study the resourceloader and how to register modules. Ultimately, and as other bugs have suggested, the format of 'mw.loader.load("User:Edokter/MenuToTabs.js");' should be the goal. I'll reopen this bug once I have a solution.
I disagree the format of mw.loader.load("User:Edokter/MenuToTabs.js"); should be a goal. It encourages users to harcode script references (be it filepaths, urls or wiki pagenames) which makes maintenance a nightmare. It also doesn't motivate or make it easy for users to: * centralize * share (rather than copy) * translate * modulize (ie. Foo:Bar/core.js, Foo:Bar/lorem.js, Foo:Bar/pluginBaz.js ) * etc. The solution is to use modules which may or may not be loaded from a wiki page. Currently (MediaWiki 1.17) they can be created as a gadget by sysops (or anyone with access to MediaWiki:-namespace) and three of the most important module-features (minification, combination of scripts/styles and dependancies) are already supported. In ResourceLoader 2.0 these will be editable by anyone with the editgadget (or whatever the name will be) userright (not just sysops, or perhaps not sysops at all and/or people like you) from the Special:GadgetManager page. At that point support for the other module-features such as messages (for localizaton) will be implemented as well.
I'm still not sure where that leaves the literally *thousands* of userscripts on wikipedia. Are they all going to be converted to gadgets? Does everyone get some sort of personal gadget control panel? Are stand-alone userscripts going to be banned? Sorry to aks so many questions, but it does help to understand how this framework is envisioned, and the documentation isn't very helpfull in this respect.