| ResourceLoaderGetConfigVars | |
|---|---|
| Available fromversion 1.17.0 Called right before ResourceLoaderStartUpModule::getConfig returns, to set static (not request-specific) configuration variables. Can not depend on current page, current user or current request; see below. | |
| Define function: | publicstaticfunctiononResourceLoaderGetConfigVars(array&$vars,string$skin,Config$config){...} |
| Attach hook: | Inextension.json:{"Hooks":{"ResourceLoaderGetConfigVars":"MediaWiki\\Extension\\MyExtension\\Hooks::onResourceLoaderGetConfigVars"}} |
| Called from: | File(s):resourceloader/ResourceLoaderStartUpModule.php |
| Interface: | ResourceLoaderGetConfigVarsHook.php |
For more information about attaching hooks, seeManual:Hooks.
For examples of extensions using this hook, seeCategory:ResourceLoaderGetConfigVars extensions.
ResourceLoaderStartUpModule::getConfig() runs this hook. Use it to export static configuration variables to JavaScript.Values that depend on the current page, user or request state must be added throughMakeGlobalVariablesScript instead.
Register the configuration variables from the hook:
classVisualEditorHooks{publicstaticfunctiononResourceLoaderGetConfigVars(array&$vars,string$skin,Config$config){$vars['wgVisualEditor']=['disableForAnons'=>$config->get('VisualEditorDisableForAnons'),'enableExperimentalCode'=>$config->get('VisualEditorEnableExperimentalCode'),];returntrue;}}
Retrieve them usingmw.config, like:
conf=mw.config.get('wgVisualEditor');if(conf.disableForAnons){// Do stuff}