MediaWiki master
UserOptionsModule.php
Go to the documentation of this file.
1<?php
2
4
9
27
29 protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
30
35 public function getScript( Context $context ) {
36 $user = $context->getUserObj();
37
38 $tokens = [
39 // Replacement is tricky - T287542
40 'patrolToken' => $user->getEditToken( 'patrol' ),
41 'watchToken' => $user->getEditToken( 'watch' ),
42 'csrfToken' => $user->getEditToken(),
43 ];
44 $script = 'mw.user.tokens.set(' . $context->encodeJson( $tokens ) . ');' . "\n";
45
46 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
47
48 // Optimisation: Exclude the defaults, which we load separately and allow the browser
49 // to cache across page views. The defaults are loaded before this code executes,
50 // as part of the "mediawiki.base" module.
51 $options = $userOptionsLookup->getOptions( $user, UserOptionsLookup::EXCLUDE_DEFAULTS );
52
53 $keysToExclude = [];
54 $this->getHookRunner()->onResourceLoaderExcludeUserOptions( $keysToExclude, $context );
55 foreach ( $keysToExclude as $excludedKey ) {
56 unset( $options[ $excludedKey ] );
57 }
58
59 // Update timezone offset (T323193)
60 if ( isset( $options['timecorrection'] ) ) {
61 $corr = new UserTimeCorrection(
62 $options['timecorrection'],
63 null,
65 );
66 $options['timecorrection'] = $corr->toString();
67 }
68
69 // Optimisation: Only output this function call if the user has non-default settings.
70 if ( $options ) {
71 $script .= 'mw.user.options.set(' . $context->encodeJson( $options ) . ');' . "\n";
72 }
73
74 return $script;
75 }
76
80 public function supportsURLLoading() {
81 return false;
82 }
83
87 public function getGroup() {
88 return self::GROUP_PRIVATE;
89 }
90}
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:32
encodeJson( $data)
Wrapper around json_encode that avoids needless escapes, and pretty-prints in debug mode.
Definition Context.php:456
getUserObj()
Get the possibly-cached User object for the specified username.
Definition Context.php:277
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
Definition Module.php:34
getHookRunner()
Get a HookRunner for running core hooks.
Definition Module.php:288
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.