MediaWiki REL1_37
ResourceLoaderUserOptionsModule.php
Go to the documentation of this file.
1<?php
2
5
36 protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
37
38 protected $targets = [ 'desktop', 'mobile' ];
39
44 public function getDependencies( ResourceLoaderContext $context = null ) {
45 return [ 'user.defaults' ];
46 }
47
52 public function getScript( ResourceLoaderContext $context ) {
53 $user = $context->getUserObj();
54
55 $tokens = [
56 'patrolToken' => $user->getEditToken( 'patrol' ),
57 'watchToken' => $user->getEditToken( 'watch' ),
58 'csrfToken' => $user->getEditToken(),
59 ];
60 $script = 'mw.user.tokens.set(' . $context->encodeJson( $tokens ) . ');';
61
62 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
63 $options = $userOptionsLookup->getOptions( $user, UserOptionsLookup::EXCLUDE_DEFAULTS );
64 // Optimisation: Only output this function call if the user has non-default settings.
65 if ( $options ) {
66 $script .= 'mw.user.options.set(' . $context->encodeJson( $options ) . ');';
67 }
68
69 // Use FILTER_NOMIN annotation to prevent needless minification and caching (T84960).
70 return ResourceLoader::FILTER_NOMIN . $script;
71 }
72
76 public function supportsURLLoading() {
77 return false;
78 }
79
83 public function getGroup() {
84 return 'private';
85 }
86}
UserOptionsLookup $userOptionsLookup
MediaWikiServices is the service locator for the application scope of MediaWiki.
Provides access to user options.
getOptions(UserIdentity $user, int $flags=0, int $queryFlags=self::READ_NORMAL)
Get all user's options.
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)