On 12/29/2015 03:59 PM, Daniel Barrett wrote:
> I run a private wiki for developers (not accessible from the Internet) that 
> lets any wiki page author run JavaScript on a page by adding a tag:
> 
> <javascript> alert("hi"); </javascript>
> 
> (We understand  the security implications, which is why the wiki isn't 
> accessible by the world.) When we upgraded to MediaWiki 1.26 (from 1.24), a 
> problem occurred: the <javascript> tag stopped recognizing the "mediawiki" 
> and "mw" objects, but otherwise works. The following code reports an 
> undefined variable "mw":
> 
> <javascript> mw.loader.using(....) </javascript>
> 
> I assume this is because the <javascript> extension builds a <script> tag as 
> a string and uses the SkinAfterBottomScripts hook to add it to the page, 
> rather than using ResourceLoader. However, I cannot figure out how to use 
> ResourceLoader to add JavaScript provided on the wiki page like my small 
> examples above. We can't use the array $wgResourceModules[$name]['scripts']  
> because the JavaScript isn't in a static file.

Since MediaWiki 1.26, all ResourceLoader modules are loaded
asynchronously, so inline scripts now need to account for the
possibility they may be executed before the jquery and mediawiki modules
have loaded.

If you use ResourceLoader::makeInlineScript() to build the HTML script
element, your JavaScript code will be automatically wrapped in an
anonymous function and queued for execution once ResourceLoader has
started up.

-- 
Kevin Israel - MediaWiki developer, Wikipedia editor
https://en.wikipedia.org/wiki/User:PleaseStand
_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to