On 24/11/2010 10:42, Markus Krötzsch wrote:
> A small update to the below instructions on how to load resources in the
> future: the file SMW.hooks.php that is given there in the example, has
> been merged into .includes/SMW_Setup.php. You can now find the example
> code in there (look for "$wgResourceModules").

Those who update their code for the new RL framework should also 
consider the following notes:

(1) The new system will not even load former "standard" Javascripts any 
more. If you require the previous "Wikibits" Javascript (e.g. for the 
onLoadHook), then you must say so when declaring your modules (as done 
in SMW).

(2) If you use inline Javascript (e.g. onclick events) then you might 
encounter scoping problems that will prevent your event handlers from 
being found (i.e. you click but the onclick does not trigger the 
function you want). To fix this, you can insert a line

  window.your_function_name = your_function_name;

into your Javascript after your declaration of the function 
your_function_name().

(3) Ultimately, you should change your code to avoid inline Javascript 
by using the methods of jQuery instead. SMW does not yet do this, so I 
cannot point you to examples.

- Markus

>
>
> On 07/11/2010 20:51, Markus Krötzsch wrote:
>> Dear extension developers,
>>
>> this is an important notice for developers of extensions that load
>> JavaScript or CSS. Updates are required in order to stay compatible with
>> recent changes in MediaWiki (1.17). Luckily, SMW helps you to achieve
>> this easily. Below is a quick walkthrough.
>>
>>
>> So far, SMW supports the loading of Javascript and CSS resources with
>> the function "SMWOutputs::requireHeadItem". It takes two parameters: an
>> ID (to avoid loading something twice) and an HTML snippet for the thing
>> that is loaded. Example from SRF's timeline code:
>>
>> SMWOutputs::requireHeadItem( 'smw_tlhelper', '<script
>> type="text/javascript" src="' . $wgScriptPath .
>> '/extensions/SemanticResultFormats/Timeline/SRF_timeline.js"></script>' );
>>
>>   From 1.17 on, MediaWiki has its own support for efficiently loading and
>> compressing resources that also reduces server load. To use this
>> facility, it is necessary to declare so-called "resource modules". SMW
>> has examples on how to do this in its file "./SMW.hooks.php".
>> Essentially, you just need to specify the location of the file to be
>> loaded, and the other resource modules that it requires to run. Each
>> module also has an ID (e.g. "ext.smw.tooltips").
>>
>> Now you need to do the following to make your extension MW 1.17
>> compatible while keeping downwards compatible with older MW version:
>>
>> (1) Define resource modules for the files that you need, just like done
>> for SMW in SMW.hooks.php. Please use hierarchical names and a suitable
>> group name for your extension (SMW uses "ext.smw" as a prefix, Semantic
>> Result Formats might use "ext.srf" etc.).
>>
>> (2) Change all calls to SMWOutputs::requireHeadItem in your code to use
>> the ID of the according resource module when loading a script. For
>> example, the above ID 'smw_tlhelper' would probably not be used for
>> resource modules. Rather, you could use something hierarchical like
>> 'ext.srf.tlhelper'.
>>
>> The above should allow you to update your code in no time while keeping
>> fully compatible with old versions of SMW and MW.
>>
>> If you use a lot of Javascript, then you could check out the
>> capabilities of Resource Loader for your application. In particular, SMW
>> also allows you to directly register a module for loading by using the
>> function "SMWOutputs::requireModule". Thus, if preferred, you can do the
>> MW version check in your own code and only call either this function or
>> the old function directly.
>>
>> The above method only works in the current development version of SMW.
>> SMW 1.5.3 uses the Resource Loader but it does not yet interpret the IDs
>> used for scripts by extensions as resource loader IDs. So if you need to
>> be compatible with SMW 1.5.3, you will have to call
>> SMWOutputs::requireModule manually in such cases. Calling it in addition
>> to RequireHeadItem would not do much harm, though.
>>
>> Cheers,
>>
>> Markus
>>
>>
>>
>
>
> ------------------------------------------------------------------------------
> Increase Visibility of Your 3D Game App&  Earn a Chance To Win $500!
> Tap into the largest installed PC base&  get more eyes on your game by
> optimizing for Intel(R) Graphics Technology. Get started today with the
> Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
> http://p.sf.net/sfu/intelisp-dev2dev
> _______________________________________________
> Semediawiki-devel mailing list
> Semediawiki-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
>


------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel

Reply via email to