Dear Developers,

since MW 1.17, the Resource Loader (RL) is a convenient and efficient 
way for including styles and scripts into pages (see [1] for details). 
However, SMW also supports MW 1.16, so it has hitherto been stuck with 
some old code that did not take advantage of the new features. This has 
now changed:

* SMW provides backwards compatibility code to use RL modules even in MW 
1.16.
* SMW includes some Javascripts that are shipped with MW 1.17 so that 
they can already be used earlier. In particular this includes jquery and 
some jquery.ui modules.
* Code for using these and any own RL modules in SMW does not have to be 
aware of whether MW is pre or post 1.17.

The relevant features are all part of SMW's class SMWOutputs. This class 
is used (as always) to allow code that includes styles and scripts to 
ignore the fact whether it is used in a wiki page or special page (in 
the first case, styles/scripts are loaded into a ParserOutput, in the 
second they are loaded into an OuptutPage). SMWOutputs collects all 
required resources so they can be committed to an OutputPage or a 
ParserOutput later on. For example:

  // Require that JQuery autocompletion JS be loaded:
  // (anywhere in the code):
  SMWOutputs::requireModule( 'jquery.ui.autocomplete' );

  // Flush all collected requirements to $wgOut:
  // (done at the end of building, e.g., a special page)
  SMWOutputs::commitToOutputPage( $wgOut );

The code that eventually finalizes the output must call the relevant 
commit... method. All other code can just add its requirements without 
being aware of the output context. Besides MediaWiki RL modules (such as 
'jquery.ui.autocomplete') you can also require the inclusion of custom 
scripts (i.e.something in <script> tags) or other header items (such as 
RSS feed links) with similar require... methods.

The SMW styles and tooltip scripts are now also loaded as resource 
modules. So instead of:

  // deprecated, but still works:
  SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP );
  SMWOutputs::requireHeadItem( SMW_HEADER_STYLE );

you would do:

  SMWOutputs::requireResource( 'ext.smw.tooltips' );
  SMWOutputs::requireResource( 'ext.smw.style' );

where the relevant declarations of all SMW-provided RL modules can be 
found in SMW_Setup.php function smwfRegisterResourceLoaderModules().

The backwards compatibility code currently does not support message 
loading yet. This will be added soon. So I18N for javascript will also 
work as in MW post 1.17 in all code.

We strongly suggest all code that uses Javascript or styles to make use 
of the new features since the RL is not just cleaner but also more 
efficient in pushing scripts to the client. The RL backwards 
compatibility in SMW is not in SMW 1.6.1 yet but will be in all later 
releases (as long as MW 1.16 is supported).

Cheers,

Markus


[1] http://www.mediawiki.org/wiki/ResourceLoader


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel

Reply via email to