Manual:Hooks/ResourceLoaderGetConfigVars
From MediaWiki.org
ResourceLoaderGetConfigVars | |
---|---|
Available from version 1.17.0 Called right before ResourceLoaderStartUpModule::getConfig returns, to set static (not request-specific) configuration variables |
|
Define function: |
public static function onResourceLoaderGetConfigVars( &$vars ) { ... } |
Attach hook: |
$wgHooks['ResourceLoaderGetConfigVars'][] = 'MyExtensionHooks::onResourceLoaderGetConfigVars'; |
Called from: | ResourceLoaderStartUpModule.php |
For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:ResourceLoaderGetConfigVars extensions.
Contents
Details[edit | edit source]
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 through MakeGlobalVariablesScript instead.
- &$vars: Array of variables to be added into the output of the startup module.
Example[edit | edit source]
Example[edit | edit source]
Register the configuration variables from the hook:
class VisualEditorHooks { public static function onResourceLoaderGetConfigVars( array &$vars ) { global $wgVisualEditorDisableForAnons, $wgVisualEditorEnableExperimentalCode; $vars['wgVisualEditor'] = array( 'disableForAnons' => $wgVisualEditorDisableForAnons, 'enableExperimentalCode' => $wgVisualEditorEnableExperimentalCode, ); return true; } }
Retrieve them using mw.config, like:
conf = mw.config.get( 'wgVisualEditor' ); if ( conf.disableForAnons ) { // Do stuff }