Home > Software engineering >  MediaWiki: how can I tell an extension to load load mediawiki.js and mediawiki.base.js?
MediaWiki: how can I tell an extension to load load mediawiki.js and mediawiki.base.js?

Time:12-26

I'm trying to mantain an abandoned MediaWiki extension but I realized it's not that easy.

I've forked it in github https://github.com/slim16165/Semantic-MediaWiki-Graph and trying to make MW load the base javascript that defines the JS mw.util

The PHP Code

$wgOut->addModules(['mediawiki', 'mediawiki.base', 'mw.util']);
//$wgOut->addScriptFile("{$wgScriptPath}/resources/src/mediawiki.base/mediawiki.base.js");
 $wgOut->addScriptFile("{$wgScriptPath}/extensions/SemanticMediaWikiGraph/includes/js/d3_v4.min.js");
 $wgOut->addScriptFile("{$wgScriptPath}/extensions/SemanticMediaWikiGraph/includes/js/utility.js");
 $wgOut->addScriptFile("{$wgScriptPath}/extensions/SemanticMediaWikiGraph/includes/js/app.js");

The JS Error

jquery-3.6.3.js:4114 jQuery.Deferred exception: mw is not defined ReferenceError: mw is not defined
    at HTMLDocument.<anonymous> (https://www.tematichedigenere.com/extensions/SemanticMediaWikiGraph/includes/js/utility.js:3:5)
    at mightThrow (https://code.jquery.com/jquery-3.6.3.js:3830:29)
    at process (https://code.jquery.com/jquery-3.6.3.js:3898:12) undefined

Testing the extension on my wiki: link to the test page

CodePudding user response:

These modules are always loaded. The code is probably running too early. Ideally you'd rewrite the extension to use ResourceLoader modules and declare a dependency on mediawiki.util; less ideally, you can just wrap the scripts in an onl oad handler so they execute after everything else has.

  • Related