Manual:Hooks/ResourceLoaderExcludeUserOptions

From Linux Web Expert

The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
ResourceLoaderExcludeUserOptions
<translate> Available from <tvar name=1><translate> version <tvar (Gerrit change 752369)</tvar></translate>
Exclude a user option from the preloaded data for client-side mw.user.options.
<translate> Define function:</translate>
public static function onResourceLoaderExcludeUserOptions( array &$keysToExclude, Context $context ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"ResourceLoaderExcludeUserOptions": "MediaWiki\\Extension\\MyExtension\\Hooks::onResourceLoaderExcludeUserOptions"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> ResourceLoader/ResourceLoader.php, ResourceLoader/UserOptionsModule.php
<translate> Interface:</translate> ResourceLoaderExcludeUserOptionsHook.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:ResourceLoaderExcludeUserOptions extensions</tvar>.</translate>


Details

This hook is called on every index.php pageview (via ResourceLoader\UserOptionsModule), and when building responses for the "mediawiki.base" module. Avoid database queries or other expensive operations as that would increase page load time.

Use this hook to optimize pageview HTML size by omitting user preference values from the export JavaScript data for mw.user.options. For example, when an extension stores large values in a user preference, and rarely or never needs these client-side, you can exclude it via this hook. (T251994)

This will exclude both the default value (via mediawiki.base module) and the current user's value (via pageview HTML).