Extension:AddScriptCss

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
AddScriptCss

Release status: stable

Implementation Tag, Parser function
Author(s) Jean-Lou Dupont
Latest version 1.0.0
MediaWiki 1.10, 1.11
License No license specified
Download SVN
See SVN ($Id: AddScriptCss.php 822 2007-09-30 13:28:36Z jeanlou.dupont $)

Translate the AddScriptCss extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

Purpose[edit | edit source]

Inserts <script> (i.e. Javascript) or <link> (i.e. CSS) code at the bottom of the page's head or within the page's body. Securely inserts arbitrary code to the page's head using <addtohead>.

Features[edit | edit source]

  • Security: local files (URI) only
    • Files must be located in wiki installation home directory/scripts
  • <addtohead>some html code here</addtohead>
  • Security:
    • Only pages with restricted editing can access 'addtohead' functionality (i.e. manually protect the page).
  • Use global variable '$bwScriptsDirectory' to customize scripts directory

Examples[edit | edit source]

<addscript src='local URL' />
  • (R1) e.g. <addscript src=/sarissa/sarissa type=js />
  • (R2) e.g. {{#addscript: src=/styleinfo|pos=head|type=css}}
R1) Results in /home/scripts/sarissa/sarissa.js being added to the page's body section provided the said file exists.
R2) The CSS file /home/scripts/styleinfo.css will be added to the page's HEAD section (provided it exists).

Syntax[edit | edit source]

Form 1: <addscript src=filename [type={js|css}] [pos={head|body}] />

Form 2: {{#addscript:src=filename [|type={js|css} [|pos={head|body}] }}

If no 'type' field is present, then the extension assumes 'js'.

If no 'pos' field is present, then the extension assumes 'body'

USAGE NOTES[edit | edit source]

  • When using 'pos=body', it is recommended to use the extension 'ParserCacheControl' in order to better integrate this extension with the standard MW parser cache.
  • Use the global variable $bwScriptsDirectory to set a new directory for the scripts
    • e.g. $bwScriptsDirectory = 'scripts'; will result in $IP.'/'.$scripts to be used.

Dependency[edit | edit source]

History[edit | edit source]

  • Adjusted for new ExtensionClass version (no automatic registering of hooks of ExtensionClass)
  • Adjusted singleton invocation to end of file (PHP limitation)
  • Imported required functionality from ExtensionClass
  • Imported 'addtohead' tag functionality from SecureHTML extension
  • Removed dependency on ExtensionClass
  • Added support for a global setting '$bwScriptsDirectory'
  • Fixed issue when $IP !== $wgScriptPath

1.0.0[edit | edit source]

  • Moved to PEAR repository



Installation[edit | edit source]

See the Mediawiki Extension table entry "download" above.[1]

LocalSettings.php[edit | edit source]

Extension:ExtensionManager: See footnote[2]

require_once( "$IP/extensions/AddScriptCss/AddScriptCss.php" );
  • Since this Extensions is depending on StubManager, add the line after the StubManager include, or else your Wiki won't work.

PEAR[edit | edit source]

PEAR is a repository of PHP software code.

pear channel-discover mediawiki.googlecode.com/svn
  • Install extension through PEAR:
pear install mediawiki/AddScriptCss
  • Add the following to LocalSettings.php[2][3]:
require 'MediaWiki/AddScriptCss/AddScriptCss.php';
  • Note that the required version of PEAR must be respected. Currently, the minimum version of PEAR usable with this channel is v1.6.2. Perform the following command to upgrade to the latest version of PEAR:
pear upgrade pear

Upgrades through PEAR[edit | edit source]

Sometimes, it is necessary to clear PEAR's cache in order to perform upgrades.

pear clear-cache

or use the force method:

pear upgrade --force mediawiki/AddScriptCss

PEAR Web Frontend[edit | edit source]

For easier remote package management, PEAR Frontend WEB can be installed. Installation notes can be found here. An example of the WEB frontend is available here.

RSS feed[edit | edit source]

To keep up-to-date with this channel, use the following RSS feed__Rss2.jpg.

Notes[edit | edit source]

Other Extensions From the same author[edit | edit source]

Consult User Jldupont's page.


  1. The most recent release is always available through the extension's PEAR and SVN repositories. This page is not necessarily up-to-date.
  2. 2.0 2.1 2.2 Extension:ExtensionManager does not require any modification to LocalSettings.php because ExtensionManager includes the extension.
    Note that if PHP code caching is in place (e.g. APC, eAccelerator), then to successfully complete the installation a cache flush might be needed.
  3. Modifications to LocalSettings.php is only necessary if not using Extension:ExtensionManager

TODO[edit | edit source]

  • internationalize
  • Support for customization of scripts directory without touching LocalSettings.php

See also[edit | edit source]