Manual:Hooks/MakeGlobalVariablesScript

From Linux Web Expert

MakeGlobalVariablesScript
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate>
right before OutputPage->getJSVars returns the vars.
<translate> Define function:</translate>
public static function onMakeGlobalVariablesScript( array &$vars, OutputPage $out ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"MakeGlobalVariablesScript": "MediaWiki\\Extension\\MyExtension\\Hooks::onMakeGlobalVariablesScript"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> OutputPage.php
<translate> Interface:</translate> MakeGlobalVariablesScriptHook.php

<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:MakeGlobalVariablesScript extensions</tvar>.</translate>

Details

This hook is fired via getJsVars(), from OutputPage::headElement(). This hook should only be used to add variables that depend on the current page/request; static configuration should be added through [[../ResourceLoaderGetConfigVars|ResourceLoaderGetConfigVars]] instead.

  • &$vars: variable (or multiple variables) to be added into the output of OutputPage::headElement.
  • $out (r96015): OutputPage instance calling the hook

See also