MakeGlobalVariablesScript does not do what you think it does, and is not 
an appropriate hook for doing anything but adding elements to the array 
argument for that hook. You should be adding modules in your 
SpecialPage::execute function.

As for your addScript() calls not working, I will need to look at your 
code, I assume it's checked in at extensions/WikiSyncSetup? Maybe you 
could find me on IRC and I could help you there - it will be quicker 
than this list.

- Trevor

On 11/5/10 10:20 AM, Dmitriy Sintsov wrote:
> * Roan Kattouw<[email protected]>  [Fri, 5 Nov 2010 14:43:57
> +0100]:
>> You totally can. It's not recommended, and it'll be less performant,
>> but you can use it and it'll work. Your script tag will end up near
>> the bottom of the<body>  though, so you can't use inline JS to call
>> functions defined in that script.
>>
> I am viewing generated HTML and don't see my script anywhere, neither in
> top nor bottom. It is a special page and I've used $wgOut->addScript()
> in "overloaded" SpecialPage::execute(). Works just fine in 1.15.x, while
> in relatively fresh trunk this $wgOut->addScript() is completely ignored
> - like it wasn't there. The "old" code is in repo Extension:WikiSync.
> But, $wgOut->addLink() in SpecialPage::execute() works just fine, css is
> being added, scripts are not! I've tried to switch to ResourceLoader, in
> case such class exists; however cannot get it to work.
>
>               $wgHooks['ResourceLoaderRegisterModules'][] =
> 'WikiSyncSetup::registerModules';
>               $wgHooks['MakeGlobalVariablesScript'][] =
> 'WikiSyncSetup::MakeGlobalVariablesScript';
> ...
> I am trying MakeGlobalVariablesScript to call
> ResourceLoader::addModules() because when it was in
> SpecialPage::execute(), addModules() was performed before
> registerModules (which is probably wrong). I've also tried
> OutputPageParserOutput, but that is not being executed in SpecialPage
> (which is probably right, because some Special pages can live without
> parser at all)..
> ...
>       static function registerModules( $resourceLoader ) {
>               global $wgExtensionAssetsPath;
>               $localpath = dirname( __FILE__ );
>               $remotepath = "$wgExtensionAssetsPath/WikiSync";
>               $resourceLoader->register(
>                       array(
>                               'ext.wikisync' =>  new
> ResourceLoaderFileModule(
>                                       array(
>                                               'scripts' =>
> 'WikiSync.js',
>                                               'styles' =>
> 'WikiSync.css',
>                                               'messages' =>
> self::$jsMessages
>                                       ),
>                                       $localpath,
>                                       $remotepath
>                               )
>                       )
>               );
>               return true;
>       }
>
>       static function MakeGlobalVariablesScript(&$vars )  {
>               global $wgOut, $wgContLang;
>               self::headScripts( $wgOut, $wgContLang->isRTL() );
>               return true;
>       }
>
>       /*
>        * include stylesheets and scripts; set javascript variables
>        * @param $outputPage - an instance of OutputPage
>        * @param $isRTL - whether the current language is RTL
>        */
>       static function headScripts(&$outputPage, $isRTL ) {
>               global $wgJsMimeType;
>               if ( class_exists( 'ResourceLoader' ) ) {
> #                     $outputPage->addModules( 'jquery' );
>                       $outputPage->addModules( 'ext.wikisync' );
>                       return;
>               }
>               $outputPage->addLink(
>                       array( 'rel' =>  'stylesheet', 'type' =>
> 'text/css', 'href' =>  self::$ScriptPath . '/WikiSync.css?' .
> self::$version )
>               );
>               if ( $isRTL ) {
>                       $outputPage->addLink(
>                               array( 'rel' =>  'stylesheet', 'type' =>
> 'text/css', 'href' =>  self::$ScriptPath . '/WikiSync_rtl.css?' .
> self::$version )
>                       );
>               }
>               $outputPage->addScript(
>                       '<script type="' . $wgJsMimeType . '" src="' .
> self::$ScriptPath . '/WikiSync.js?' . self::$version . '"></script>
>                       <script type="' . $wgJsMimeType . '" src="' .
> self::$ScriptPath . '/WikiSync_Utils.js?' . self::$version .
> '"></script>
>                       <script type="' . $wgJsMimeType .
> '">WikiSyncUtils.addEvent(window,"load",WikiSync.onloadHandler);</script>
>                       <script type="' . $wgJsMimeType . '">
>                       WikiSync.setLocalMessages( ' .
>                               self::getJsObject( 'wsLocalMessages',
> self::$jsMessages ) .
>                       ');</script>' . "\n"
>               );
>       }
>
>> As long as they're not using inline JS, they won't break.
>>
> Unfortunately, I've used a bit of inline JS. How do I add window.onload?
> Inside "main flow" of WikiSync.js ? I'll try that however currently I
> cannot get registerModule() and addModules() to work. Probably it's
> something simple, sorry.
> Dmitriy
>
> _______________________________________________
> Wikitech-l mailing list
> [email protected]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l

_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to