Difference between revisions of "JKey to Gadget and ResourceLoader"
Line 1: | Line 1: | ||
− | Notes on porting the jKey to a gadget and using mediawiki ResourceLoader: | + | '''Notes on a possible future porting the jKey to a gadget and using mediawiki ResourceLoader:''' |
See http://www.mediawiki.org/wiki/Gadgets | See http://www.mediawiki.org/wiki/Gadgets |
Latest revision as of 17:46, 13 June 2012
Notes on a possible future porting the jKey to a gadget and using mediawiki ResourceLoader:
See http://www.mediawiki.org/wiki/Gadgets
Gadgets are defined on a special mediawiki page like: http://commons.wikimedia.org/wiki/MediaWiki:Gadgets-definition
Gadgets can be system gadgets that are invisible to users. By defining rights = hidden (where there is no such group "hidden" defined) a gadget can be made non-selectable by users, e.g. libCommons [ResourceLoader|rights=hidden|hidden]|libCommons.js
It is possible to have gadgets that run only under certain conditions, like a html class name present on the current page. This requires a jquery code checking for the presence of such a class, and then loading the gadget.
http://www.mediawiki.org/wiki/ResourceLoader/Developing_with_ResourceLoader#Client-side_.28dynamically.29
recommends: "If you only need a module in a certain scenario of the user interface, you could instead create a small init module (that is loaded server side), and from there use JavaScript to kick-off the load of the rest of the module when necessary. Use the mw.loader object for this. mw.loader.using( 'example.fooBar', function () { /* This callback is invoked as soon as the example.fooBar is ready */ } );
Tip: If you just want to load the module, and don't need the callback, you can use mw.loader.load( 'example.fooBar' );
instead."
The relation between gadget and resource loader at present is yet poorly documented. The Gadget definition must have a special attribute ResourceLoader to mark it as compatible with resource loader.
Centralization example
The js-based mw-loader ( http://www.mediawiki.org/wiki/RL/DM#mediaWiki.loader ) can load from an URL. This allows to centralize the js code in a single wiki, but use it in multiple one; the method is used on WMF/Wikipedias.
http://en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&action=edit contains:
mw.loader.load( '//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-UTCLiveClock.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400' );
that is, it externally loads the centralized http://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js
(Testing gadget creation, but not yet centralization: Inserting the code directly into a same named test-wiki gadget http://biowikifarm.net/test/MediaWiki:Gadget-UTCLiveClock.js and adding to http://biowikifarm.net/test/MediaWiki:Gadgets-definition and enabling for a given user worked ok.)