MediaWiki extensions manual
HeaderScriptInjector
Release status: unmaintained
Description Inject scripts, CSS, load popular JS libraries from Google Ajax API into the HTML header of your wiki
Author(s) Evgeny Fadeev
Latest version 0.1 (2008-11-29)
MediaWiki 1.12 (will probably work on earlier versions)
License MIT License
Download Project page
Subversion [Help ]

Browse source code
View code changes

Note Note: No localisation updates provided by Translatewiki.net .

Summary

This extension creates $wgHeader global variable, pointing to the object of class 'HeaderScriptInjector'. You will be able to access functions of this extension through $wgHeader.

To use HeaderScriptInjector in your extension, within your extension file add a line:

global $wgHeader;

Libraries, local javascript files, css will be added through method calls:

$wgHeader->loadLib(...);       //more details below
$wgHeader->addScript($url);    //if your script depends on libraries add libraries before!
$wgHeader->addCSS($url);
$wgHeader->loadGoogleApi();    //this is also called implicitly by loadLib() if the libraries are loaded through the Google CDN

All scripts/libraries/style sheets loaded through the HeaderScriptInjector will be added to the header only once.

Add library from CDN

Attach a javascript library hosted by an external content distribution network (CDN) to your extension. i.e. you won't need to copy source of javascript to your server, page response might be faster due to possibly better robustness of the CDN

At the moment only Google Ajax libraries API is supported.

$wgHeader->loadLib("jquery","google","1.2.6");
#                     ^        ^        ^
#              library tag    CDN    version of the library   (please, make sure to use correct values)

Check the list of libraries and their versions supported by Google AJAX libraries API.

library tag
jQuery jquery
jQuery UI jqueryui
Prototype prototype
script.aculo.us scriptaculous
MooTools mootools
Dojo dojo
SWF Object swfobject
Yahoo User Interface yui

Installation

Go to root of your wiki installation, then type

cd extensions
mkdir HeaderScriptInjector 
cd HeaderScriptInjector
svn checkout http://mw-header-script-injector.googlecode.com/svn/trunk/ mw-header-script-injector-read-only .

If you don't have svn installed on your server, get this file, put it in the extensions/HeaderScriptInjector directory and name it HeaderScriptInjector.php

Then in your LocalSettings.php add:

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

If you are using Google AJAX library CDN you will need to add your Google API Key. Add a line in LocalSettings.php after "require_once".

$wgGoogleApiKey = '....';

See also

This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.