MediaWiki master
UserOptionsModule.php
Go to the documentation of this file.
1<?php
2
4
9
41
43 protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
44
49 public function getScript( Context $context ) {
50 $user = $context->getUserObj();
51
52 $tokens = [
53 // Replacement is tricky - T287542
54 'patrolToken' => $user->getEditToken( 'patrol' ),
55 'watchToken' => $user->getEditToken( 'watch' ),
56 'csrfToken' => $user->getEditToken(),
57 ];
58 $script = 'mw.user.tokens.set(' . $context->encodeJson( $tokens ) . ');' . "\n";
59
60 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
61
62 // Optimisation: Exclude the defaults, which we load separately and allow the browser
63 // to cache across page views. The defaults are loaded before this code executes,
64 // as part of the "mediawiki.base" module.
65 $options = $userOptionsLookup->getOptions( $user, UserOptionsLookup::EXCLUDE_DEFAULTS );
66
67 $keysToExclude = [];
68 $this->getHookRunner()->onResourceLoaderExcludeUserOptions( $keysToExclude, $context );
69 foreach ( $keysToExclude as $excludedKey ) {
70 unset( $options[ $excludedKey ] );
71 }
72
73 // Update timezone offset (T323193)
74 if ( isset( $options['timecorrection'] ) ) {
75 $corr = new UserTimeCorrection(
76 $options['timecorrection'],
77 null,
79 );
80 $options['timecorrection'] = $corr->toString();
81 }
82
83 // Optimisation: Only output this function call if the user has non-default settings.
84 if ( $options ) {
85 $script .= 'mw.user.options.set(' . $context->encodeJson( $options ) . ');' . "\n";
86 }
87
88 return $script;
89 }
90
94 public function supportsURLLoading() {
95 return false;
96 }
97
101 public function getGroup() {
102 return self::GROUP_PRIVATE;
103 }
104}
A class containing constants representing the names of configuration variables.
const LocalTZoffset
Name constant for the LocalTZoffset setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Context object that contains information about the state of a specific ResourceLoader web request.
Definition Context.php:46
encodeJson( $data)
Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
Definition Context.php:470
getUserObj()
Get the possibly-cached User object for the specified username.
Definition Context.php:291
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition Module.php:47
getHookRunner()
Get a HookRunner for running core hooks.
Definition Module.php:316
Module for per-user private data that is transmitted on all HTML web responses.
Provides access to user options.
getOptions(UserIdentity $user, int $flags=0, int $queryFlags=IDBAccessObject::READ_NORMAL)
Get all user's options.
Utility class to parse the TimeCorrection string value.