Movatterモバイル変換


[0]ホーム

URL:


Jump to content
MediaWiki
Search

Extension:HeadScript

From mediawiki.org
Translate this page
Languages:
MediaWiki extensions manual
HeadScript
Release status: stable
ImplementationHook
DescriptionAdds scripts just before</head> of the wiki
Author(s)
Latest version1.1.1 (2021-12-03)
MediaWiki>= 1.29.0
Database changesNo
LicenseMIT License
Download

  • $wgHeadScriptName
  • $wgHeadScriptCode
Translate the HeadScript extension if it is available at translatewiki.net

TheHeadScript extension allows scripts to easily be added just before‎</head> of the wiki.

The code for the head script is defined in "LocalSettings.php" and is controlled by variables.This implementation makes it easy for inexperienced users to implement head scripts just before</head> of the wiki.It also makes it possible to add head scripts that cannot be changed or removed, such as would be possible by wikiAdministrators if the head script were added to theSitenotice.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.


Installation

[edit]
  • Download and move the extractedHeadScript folder to yourextensions/ directory.
    Developers and code contributors should install the extensionfrom Git instead, using:
    cdextensions/gitclonehttps://gerrit.wikimedia.org/r/mediawiki/extensions/HeadScript
  • Add the following code at the bottom of yourLocalSettings.php file:
    wfLoadExtension('HeadScript');
  • Configure as required.
  • YesDone – Navigate toSpecial:Version on your wiki to verify that the extension is successfully installed.

Configuration

[edit]

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

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

$wgHeadScriptCode=<<<'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:

$wgHeadScriptCode=<<<'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:

$wgHeadScriptName='my-wonderful-script';

META and LINK elements can also be added, such as:

$wgHeadScriptCode=<<<'START_END_MARKER'<meta name="author" content="Wikimedia Foundation" /><link rel="author" type="text/plain" href="/humans.txt" /><script></script>START_END_MARKER;

See also

[edit]
Retrieved from "https://www.mediawiki.org/w/index.php?title=Extension:HeadScript&oldid=6709049"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp