Manual:フック/ResourceLoaderGetConfigVars

From mediawiki.org
This page is a translated version of the page Manual:Hooks/ResourceLoaderGetConfigVars and the translation is 36% complete.
ResourceLoaderGetConfigVars
バージョン 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.
関数の定義:
public static function onResourceLoaderGetConfigVars( array &$vars, string $skin, Config $config ) { ... }
フックのアタッチ: extension.json 内:
{
	"Hooks": {
		"ResourceLoaderGetConfigVars": "MediaWiki\\Extension\\MyExtension\\Hooks::onResourceLoaderGetConfigVars"
	}
}
呼び出し元: ファイル: resourceloader/ResourceLoaderStartUpModule.php
インターフェイス: ResourceLoaderGetConfigVarsHook.php

フックの設定についての詳細情報は Manual:フック を参照してください。
このフックを使用する拡張機能の例については、Category:ResourceLoaderGetConfigVars extensions/ja を参照してください。

詳細

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.
  • $skin - (1.32 で導入) Current skin name to restrict config variables to a certain skin (if needed)
  • $config - (1.34 で導入)

Register the configuration variables from the hook:

class VisualEditorHooks {
	public static function onResourceLoaderGetConfigVars( array &$vars, string $skin, Config $config ) {
		$vars['wgVisualEditor'] = [
			'disableForAnons' => $config->get( 'VisualEditorDisableForAnons' ),
			'enableExperimentalCode' => $config->get( 'VisualEditorEnableExperimentalCode' ),
		];

		return true;
	}
}

Retrieve them using mw.config , like:

conf = mw.config.get( 'wgVisualEditor' );
if ( conf.disableForAnons ) {
	// Do stuff
}

関連項目