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