1

I would like to install a new javascript script on my wiki.

So I have to call this following scripts:

<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Quicksand">
<link rel="stylesheet" type="text/css" href="library/pretty-json-master/css/pretty-json.css">
<script type="text/javascript" src="library/pretty-json-master/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="library/pretty-json-master/libs/underscore-min.js"></script>
<script type="text/javascript" src="library/pretty-json-master/libs/backbone-min.js"></script>
<script type="text/javascript" src="library/pretty-json-master/pretty-json-debug.js"></script>

What is the best practice to add this on all my pages ?

Thx

2

2 Answers 2

0

There might be other ways, but you could create a light MediaWiki extension which only sets $wgResourceModules. See Manual:$wgResourceModules.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok thanks but I don't know where I have to call the $this->getOutput()->addModules( 'ext.myExtension' );
Follow-up in Where to call addModules()?. Other options (I would say they are worse): load it from a global script file, use gadgets.
-1

1/ Create a new extension in "extensions" folder (extensions/jsonTree/)

2/ Create a php file in this folder (jsonTree.php)

$wgHooks['BeforePageDisplay'][] = 'onBeforePageDisplay';

function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {

    $script = '
    <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Quicksand">
    <link rel="stylesheet" type="text/css" href="/extensions/jsonTree/modules/css/pretty-json.css">
    <script type="text/javascript" src="/extensions/jsonTree/modules/libs/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="/extensions/jsonTree/modules/libs/underscore-min.js"></script>
    <script type="text/javascript" src="/extensions/jsonTree/modules/libs/backbone-min.js"></script>
    <script type="text/javascript" src="/extensions/jsonTree/modules/pretty-json-debug.js"></script>
    ';

    $out->addHeadItem("jsonTree script", $script);

    return true;

}

3/ Include this file in LocalSettings.php

require_once( "$IP/extensions/jsonTree/jsonTree.php" );

1 Comment

That's the worst way you can do it in a MediaWiki extension. This bypasses the ResourceLoader, which takes care about a lot of useful things, read mediawiki.org/wiki/ResourceLoader/Features and mediawiki.org/wiki/ResourceLoader/… to know, how to develop an extension with the ResourceLoader. You can add a module with $out->addModules() in your onBeforePageDisplay hook handler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.