Manual:Hooks/ResourceLoaderGetConfigVars/pl

From Linux Web Expert

Revision as of 14:52, 2 February 2024 by imported>Chrumps (Created page with "== Przykład ==")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

ResourceLoaderGetConfigVars
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate>
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.
<translate> Define function:</translate>
public static function onResourceLoaderGetConfigVars( array &$vars, string $skin, Config $config ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"ResourceLoaderGetConfigVars": "MediaWiki\\Extension\\MyExtension\\Hooks::onResourceLoaderGetConfigVars"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> resourceloader/ResourceLoaderStartUpModule.php
<translate> Interface:</translate> ResourceLoaderGetConfigVarsHook.php

<translate> For more information about attaching hooks, see <tvar name=1>Podręcznik:Haki </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:ResourceLoaderGetConfigVars extensions/pl</tvar>.</translate>

Szczegóły

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 - <translate> (introduced in <tvar Current skin name to restrict config variables to a certain skin (if needed)
  • $config - <translate> (introduced in <tvar

Przykład

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
}

Zobacz też