Am 15.12.2013 09:37, schrieb Sen:
> hi,i had a confuse,how can i pass a value to the js content script
>
> for nowi,i use the way from msupload:
> $wgOut->addScript("<script type='text/javascript'>var clipup_vars =
> $clipup_vars ;</script>\n");
> it's work but sometimes it seems not work well,the js cant get the value
> clipup_vars.
> it's any nature way to doing this?
A short section of the ResourceLoader guide explains this.
*
https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_for_extension_developers#Configuration_variables
If you used to insert javascript like:
var wgFoo = "bar";
You can now use resource loader to add your variable as a config
variable. If the variable is the same for all pages and should be on all
pages, use the ResourceLoaderGetConfigVars
<https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars> hook.
Otherwise if the variable depends on the current page being viewed you
can either use the MakeGlobalVariablesScript
<https://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript>
hook or if you have an OutputPage object, the addJsConfigVars
<https://doc.wikimedia.org/mediawiki-core/master/php/html/classOutputPage.html#a81c86f0fc996076ed05467f63b3fb154>
method. Variables added can be accesed in javascript using
|mw.config.get( 'variable name' );|
and look to the example in
* https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
(If the variable is the same for all pages and should be on all pages)
*
https://doc.wikimedia.org/mediawiki-core/master/php/html/classOutputPage.html
(if the variable depends on the current page)
Sometimes in my php I use a construct like
if ( $out->getTitle()->equals( SpecialPage::getTitleFor(
'OpenIDConvert' ) ) {
$out->addHeadItem( 'openid-providerstyle',
self::providerStyle() );
}
to embed code (here: a style) only for certain pages, not for all.
Perhaps you want this, too.
_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l