MediaWiki REL1_35
ResourceLoaderUserOptionsModule.php
Go to the documentation of this file.
1<?php
32 protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
33
34 protected $targets = [ 'desktop', 'mobile' ];
35
40 public function getDependencies( ResourceLoaderContext $context = null ) {
41 return [ 'user.defaults' ];
42 }
43
48 public function getScript( ResourceLoaderContext $context ) {
49 $user = $context->getUserObj();
50
51 $tokens = [
52 'patrolToken' => $user->getEditToken( 'patrol' ),
53 'watchToken' => $user->getEditToken( 'watch' ),
54 'csrfToken' => $user->getEditToken(),
55 ];
56 $script = 'mw.user.tokens.set(' . $context->encodeJson( $tokens ) . ');';
57
58 $options = $user->getOptions( User::GETOPTIONS_EXCLUDE_DEFAULTS );
59 // Optimisation: Only output this function call if the user has non-default settings.
60 if ( $options ) {
61 $script .= 'mw.user.options.set(' . $context->encodeJson( $options ) . ');';
62 }
63
64 // Use FILTER_NOMIN annotation to prevent needless minification and caching (T84960).
65 return ResourceLoader::FILTER_NOMIN . $script;
66 }
67
71 public function supportsURLLoading() {
72 return false;
73 }
74
78 public function getGroup() {
79 return 'private';
80 }
81}
Context object that contains information about the state of a specific ResourceLoader web request.
getUserObj()
Get the possibly-cached User object for the specified username.
encodeJson( $data)
Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Module for per-user private data that is transmitted on all HTML web responses.
getDependencies(ResourceLoaderContext $context=null)
const GETOPTIONS_EXCLUDE_DEFAULTS
Exclude user options that are set to their default value.
Definition User.php:84