Extension:AddScriptCss

From MediaWiki.org

Jump to: navigation, search
Manual on MediaWiki Extensions
List of MediaWiki Extensions
AddScriptCss

Release status: stable

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

Contents

[edit] Purpose

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>.

[edit] Features

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

[edit] Examples

<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).

[edit] Syntax

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'

[edit] USAGE NOTES

  • 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.

[edit] Dependency

[edit] History

  • 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

[edit] 1.0.0

  • Moved to PEAR repository



[edit] Installation

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

[edit] LocalSettings.php

Extension:ExtensionManager: See footnote[2]

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

[edit] PEAR

PEAR is a repository of 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';

[edit] Upgrades through PEAR

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

[edit] PEAR Web Frontend

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.

[edit] RSS feed

To keep kept up-to-date with this channel, use the following RSS feedImage:Rss2.jpg.

[edit] Notes

[edit] Sandbox

You are invited in the author's sandbox to try-out some of his extensions.


  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

[edit] TODO

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

[edit] See also

Personal tools
In other languages