Extension:BodyScript

MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
BodyScript
Release status: unmaintained
Implementation Hook
Description Adds scripts just before </body> of the wiki
Author(s)
Latest version 1.1.1 (2020-12-21)
MediaWiki 1.35
Database changes No
License MIT License
Download Download extension

  • $wgBodyScriptName
  • $wgBodyScriptCode

Check usage and version matrix.

The BodyScript extension allows scripts to easily be added just before </body> of the wiki.

The code for the body script is defined in "LocalSettings.php" and is controlled by variables. This implementation makes it easy for inexperienced users to implement Body scripts just before </body> of the wiki. It also makes it possible to add Body scripts that cannot be changed or removed, such as would be possible by wiki administrators if the body script were added to the site notice. This makes the extension particularly useful for placing Cookie Consent plugin or CSS style links, as such content cannot be removed by abusive or rogue administrators.

InstallationEdit

  • Download and place the file(s) in a directory called BodyScript in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'BodyScript' );
    
  • Configure as required.
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

To users running MediaWiki 1.24 or earlier:

The instructions above describe the new way of installing this extension using wfLoadExtension(). If you need to install this extension on these earlier versions (MediaWiki 1.24 and earlier), instead of wfLoadExtension( 'BodyScript' );, you need to use:

require_once "$IP/extensions/BodyScript/BodyScript.php";

ConfigurationEdit

One or more body scripts can be added to the wiki. The body scripts can consist of any HTML and/or JavaScript.

To configure the body script, add the following to "LocalSettings.php" after the installation line:

$wgBodyScriptCode = <<<'START_END_MARKER'
<script></script>
START_END_MARKER;

Leave untouched the first and last line with START_END_MARKER stuff, this is a special syntax of PHP (without it, it would be tricky to deal with apostrophes inside the script). Do not add whitespaces around the last line’s marker, it would break it (more details about this syntax). Do add new line after.

To add additional scripts, simply include them between the markers:

$wgBodyScriptCode = <<<'START_END_MARKER'
<script></script>
<script></script>
<script></script>
START_END_MARKER;

You may specify a name for the script too if needed, add the following after the installation line:

$wgBodyScriptName = 'my-wonderful-script';