MediaWiki  master
UserOptionsManager.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\User;
22 
24 use HTMLCheckMatrix;
25 use HTMLFormField;
27 use IContextSource;
28 use InvalidArgumentException;
29 use LanguageCode;
35 use Psr\Log\LoggerInterface;
36 use User;
38 
44 
48  public const CONSTRUCTOR_OPTIONS = [
49  'HiddenPrefs',
50  'LocalTZoffset',
51  ];
52 
54  private $serviceOptions;
55 
58 
61 
63  private $loadBalancer;
64 
66  private $logger;
67 
69  private $modifiedOptions = [];
70 
76  private $originalOptionsCache = [];
77 
82  private $optionsFromDb = [];
83 
85  private $hookRunner;
86 
89 
98  public function __construct(
99  ServiceOptions $options,
103  LoggerInterface $logger,
104  HookContainer $hookContainer
105  ) {
106  $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
107  $this->serviceOptions = $options;
108  $this->defaultOptionsLookup = $defaultOptionsLookup;
109  $this->languageConverterFactory = $languageConverterFactory;
110  $this->loadBalancer = $loadBalancer;
111  $this->logger = $logger;
112  $this->hookRunner = new HookRunner( $hookContainer );
113  }
114 
118  public function getDefaultOptions(): array {
119  return $this->defaultOptionsLookup->getDefaultOptions();
120  }
121 
125  public function getOption(
126  UserIdentity $user,
127  string $oname,
128  $defaultOverride = null,
129  bool $ignoreHidden = false,
130  int $queryFlags = self::READ_NORMAL
131  ) {
132  # We want 'disabled' preferences to always behave as the default value for
133  # users, even if they have set the option explicitly in their settings (ie they
134  # set it, and then it was disabled removing their ability to change it). But
135  # we don't want to erase the preferences in the database in case the preference
136  # is re-enabled again. So don't touch $mOptions, just override the returned value
137  if ( !$ignoreHidden && in_array( $oname, $this->serviceOptions->get( 'HiddenPrefs' ) ) ) {
138  return $this->defaultOptionsLookup->getDefaultOption( $oname );
139  }
140 
141  $options = $this->loadUserOptions( $user, $queryFlags );
142  if ( array_key_exists( $oname, $options ) ) {
143  return $options[$oname];
144  }
145  return $defaultOverride;
146  }
147 
151  public function getOptions(
152  UserIdentity $user,
153  int $flags = 0,
154  int $queryFlags = self::READ_NORMAL
155  ): array {
156  $options = $this->loadUserOptions( $user, $queryFlags );
157 
158  # We want 'disabled' preferences to always behave as the default value for
159  # users, even if they have set the option explicitly in their settings (ie they
160  # set it, and then it was disabled removing their ability to change it). But
161  # we don't want to erase the preferences in the database in case the preference
162  # is re-enabled again. So don't touch $mOptions, just override the returned value
163  foreach ( $this->serviceOptions->get( 'HiddenPrefs' ) as $pref ) {
164  $default = $this->defaultOptionsLookup->getDefaultOption( $pref );
165  if ( $default !== null ) {
166  $options[$pref] = $default;
167  }
168  }
169 
170  if ( $flags & self::EXCLUDE_DEFAULTS ) {
171  $defaultOptions = $this->defaultOptionsLookup->getDefaultOptions();
172  foreach ( $options as $option => $value ) {
173  if ( isset( $defaultOptions[$option] )
174  && $this->isValueEqual( $value, $defaultOptions[$option] )
175  ) {
176  unset( $options[$option] );
177  }
178  }
179  }
180 
181  return $options;
182  }
183 
193  public function setOption( UserIdentity $user, string $oname, $val ) {
194  // Explicitly NULL values should refer to defaults
195  if ( $val === null ) {
196  $val = $this->defaultOptionsLookup->getDefaultOption( $oname );
197  }
198  $this->modifiedOptions[$this->getCacheKey( $user )][$oname] = $val;
199  }
200 
215  public function resetOptions(
216  UserIdentity $user,
218  $resetKinds = [ 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused' ]
219  ) {
220  $oldOptions = $this->loadUserOptions( $user, self::READ_LATEST );
221  $defaultOptions = $this->defaultOptionsLookup->getDefaultOptions();
222 
223  if ( !is_array( $resetKinds ) ) {
224  $resetKinds = [ $resetKinds ];
225  }
226 
227  if ( in_array( 'all', $resetKinds ) ) {
228  $newOptions = $defaultOptions + array_fill_keys( array_keys( $oldOptions ), null );
229  } else {
230  $optionKinds = $this->getOptionKinds( $user, $context );
231  $resetKinds = array_intersect( $resetKinds, $this->listOptionKinds() );
232  $newOptions = [];
233 
234  // Use default values for the options that should be deleted, and
235  // copy old values for the ones that shouldn't.
236  foreach ( $oldOptions as $key => $value ) {
237  if ( in_array( $optionKinds[$key], $resetKinds ) ) {
238  if ( array_key_exists( $key, $defaultOptions ) ) {
239  $newOptions[$key] = $defaultOptions[$key];
240  }
241  } else {
242  $newOptions[$key] = $value;
243  }
244  }
245  }
246 
247  // TODO: Deprecate passing full user to the hook
248  $this->hookRunner->onUserResetAllOptions(
249  User::newFromIdentity( $user ), $newOptions, $oldOptions, $resetKinds
250  );
251 
252  $this->modifiedOptions[$this->getCacheKey( $user )] = $newOptions;
253  }
254 
278  public function listOptionKinds(): array {
279  return [
280  'registered',
281  'registered-multiselect',
282  'registered-checkmatrix',
283  'userjs',
284  'special',
285  'unused'
286  ];
287  }
288 
302  public function getOptionKinds(
303  UserIdentity $userIdentity,
305  $options = null
306  ): array {
307  if ( $options === null ) {
308  $options = $this->loadUserOptions( $userIdentity );
309  }
310 
311  // TODO: injecting the preferences factory creates a cyclic dependency between
312  // PreferencesFactory and UserOptionsManager. See T250822
313  $preferencesFactory = MediaWikiServices::getInstance()->getPreferencesFactory();
314  $user = User::newFromIdentity( $userIdentity );
315  $prefs = $preferencesFactory->getFormDescriptor( $user, $context );
316  $mapping = [];
317 
318  // Pull out the "special" options, so they don't get converted as
319  // multiselect or checkmatrix.
320  $specialOptions = array_fill_keys( $preferencesFactory->getSaveBlacklist(), true );
321  foreach ( $specialOptions as $name => $value ) {
322  unset( $prefs[$name] );
323  }
324 
325  // Multiselect and checkmatrix options are stored in the database with
326  // one key per option, each having a boolean value. Extract those keys.
327  $multiselectOptions = [];
328  foreach ( $prefs as $name => $info ) {
329  if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
330  ( isset( $info['class'] ) && $info['class'] == HTMLMultiSelectField::class )
331  ) {
332  $opts = HTMLFormField::flattenOptions( $info['options'] ?? $info['options-messages'] );
333  $prefix = $info['prefix'] ?? $name;
334 
335  foreach ( $opts as $value ) {
336  $multiselectOptions["$prefix$value"] = true;
337  }
338 
339  unset( $prefs[$name] );
340  }
341  }
342  $checkmatrixOptions = [];
343  foreach ( $prefs as $name => $info ) {
344  if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
345  ( isset( $info['class'] ) && $info['class'] == HTMLCheckMatrix::class )
346  ) {
347  $columns = HTMLFormField::flattenOptions( $info['columns'] );
348  $rows = HTMLFormField::flattenOptions( $info['rows'] );
349  $prefix = $info['prefix'] ?? $name;
350 
351  foreach ( $columns as $column ) {
352  foreach ( $rows as $row ) {
353  $checkmatrixOptions["$prefix$column-$row"] = true;
354  }
355  }
356 
357  unset( $prefs[$name] );
358  }
359  }
360 
361  // $value is ignored
362  foreach ( $options as $key => $value ) {
363  if ( isset( $prefs[$key] ) ) {
364  $mapping[$key] = 'registered';
365  } elseif ( isset( $multiselectOptions[$key] ) ) {
366  $mapping[$key] = 'registered-multiselect';
367  } elseif ( isset( $checkmatrixOptions[$key] ) ) {
368  $mapping[$key] = 'registered-checkmatrix';
369  } elseif ( isset( $specialOptions[$key] ) ) {
370  $mapping[$key] = 'special';
371  } elseif ( substr( $key, 0, 7 ) === 'userjs-' ) {
372  $mapping[$key] = 'userjs';
373  } else {
374  $mapping[$key] = 'unused';
375  }
376  }
377 
378  return $mapping;
379  }
380 
388  public function saveOptions( UserIdentity $user ) {
389  if ( !$user->isRegistered() ) {
390  throw new InvalidArgumentException( __METHOD__ . ' was called on anon user' );
391  }
392 
393  $userKey = $this->getCacheKey( $user );
394  $modifiedOptions = $this->modifiedOptions[$userKey] ?? [];
395  $originalOptions = $this->loadOriginalOptions( $user, self::READ_LATEST );
396  if ( !$this->hookRunner->onSaveUserOptions( $user, $modifiedOptions, $originalOptions ) ) {
397  return;
398  }
399 
400  // TODO: only needed for old hook.
401  $optionsToSave = array_merge( $originalOptions, $modifiedOptions );
402  // Allow hooks to abort, for instance to save to a global profile.
403  // Reset options to default state before saving.
404  if ( !$this->hookRunner->onUserSaveOptions(
405  User::newFromIdentity( $user ), $optionsToSave, $originalOptions )
406  ) {
407  return;
408  }
409 
410  // Delete any rows that were in the DB but are not in $optionsToSave
411  $keysToDelete = array_keys(
412  array_diff_key( $this->optionsFromDb[$userKey], $optionsToSave )
413  );
414 
415  // Update rows that have changed
416  $userId = $user->getId();
417  $rowsToInsert = []; // all the new preference rows
418  $rowsToPreserve = [];
419  foreach ( $optionsToSave as $key => $value ) {
420  // Don't store unchanged or default values
421  $defaultValue = $this->defaultOptionsLookup->getDefaultOption( $key );
422  $oldValue = $this->optionsFromDb[$userKey][$key] ?? null;
423  if ( !$this->isValueEqual( $value, $defaultValue ) ) {
424  $row = [
425  'up_user' => $userId,
426  'up_property' => $key,
427  'up_value' => $value,
428  ];
429  if ( !$this->isValueEqual( $value, $oldValue ) ) {
430  // Update by deleting and reinserting
431  $rowsToInsert[] = $row;
432  if ( $oldValue !== null ) {
433  $keysToDelete[] = $key;
434  }
435  } else {
436  // Preserve old value -- save the row for caching
437  $rowsToPreserve[] = $row;
438  }
439  } elseif ( $oldValue !== null ) {
440  // Delete row that is being set to its default
441  $keysToDelete[] = $key;
442  }
443  }
444 
445  if ( !count( $keysToDelete ) && !count( $rowsToInsert ) ) {
446  // Nothing to do
447  return;
448  }
449 
450  // Do the DELETE
451  $dbw = $this->loadBalancer->getConnectionRef( DB_PRIMARY );
452  if ( $keysToDelete ) {
453  $dbw->delete(
454  'user_properties',
455  [
456  'up_user' => $userId,
457  'up_property' => $keysToDelete
458  ],
459  __METHOD__
460  );
461  }
462  if ( $rowsToInsert ) {
463  // Insert the new preference rows
464  $dbw->insert( 'user_properties', $rowsToInsert, __METHOD__, [ 'IGNORE' ] );
465  }
466 
467  // We are storing these into the database, so that's what we will get if we fetch again
468  // So, set the just saved options to the cache, but don't prevent some other part of the
469  // code from locking the options again but saying READ_LATEST was used for caching.
470  $this->setOptionsFromDb( $user, self::READ_LATEST,
471  array_merge( $rowsToPreserve, $rowsToInsert ) );
472 
473  // It's pretty cheap to recalculate new original later
474  // to apply whatever adjustments we apply when fetching from DB
475  // and re-merge with the defaults.
476  unset( $this->originalOptionsCache[$userKey] );
477  // And nothing is modified anymore
478  unset( $this->modifiedOptions[$userKey] );
479  }
480 
495  public function loadUserOptions(
496  UserIdentity $user,
497  int $queryFlags = self::READ_NORMAL,
498  array $data = null
499  ): array {
500  $userKey = $this->getCacheKey( $user );
501  $originalOptions = $this->loadOriginalOptions( $user, $queryFlags, $data );
502  return array_merge( $originalOptions, $this->modifiedOptions[$userKey] ?? [] );
503  }
504 
510  public function clearUserOptionsCache( UserIdentity $user ) {
511  $cacheKey = $this->getCacheKey( $user );
512  unset( $this->modifiedOptions[$cacheKey] );
513  unset( $this->optionsFromDb[$cacheKey] );
514  unset( $this->originalOptionsCache[$cacheKey] );
515  unset( $this->queryFlagsUsedForCaching[$cacheKey] );
516  }
517 
526  private function loadOptionsFromDb(
527  UserIdentity $user,
528  int $queryFlags,
529  array $prefetchedOptions = null
530  ): array {
531  if ( $prefetchedOptions === null ) {
532  $this->logger->debug( 'Loading options from database', [ 'user_id' => $user->getId() ] );
533  [ $dbr, $options ] = $this->getDBAndOptionsForQueryFlags( $queryFlags );
534  $res = $dbr->select(
535  'user_properties',
536  [ 'up_property', 'up_value' ],
537  [ 'up_user' => $user->getId() ],
538  __METHOD__,
539  $options
540  );
541  } else {
542  $res = [];
543  foreach ( $prefetchedOptions as $name => $value ) {
544  $res[] = [
545  'up_property' => $name,
546  'up_value' => $value,
547  ];
548  }
549  }
550  return $this->setOptionsFromDb( $user, $queryFlags, $res );
551  }
552 
561  private function setOptionsFromDb(
562  UserIdentity $user,
563  int $queryFlags,
564  iterable $rows
565  ): array {
566  $userKey = $this->getCacheKey( $user );
567  $options = [];
568  foreach ( $rows as $row ) {
569  $row = (object)$row;
570  // Convert '0' to 0. PHP's boolean conversion considers them both
571  // false, but e.g. JavaScript considers the former as true.
572  // @todo: T54542 Somehow determine the desired type (string/int/bool)
573  // and convert all values here.
574  if ( $row->up_value === '0' ) {
575  $row->up_value = 0;
576  }
577  $options[$row->up_property] = $row->up_value;
578  }
579  $this->optionsFromDb[$userKey] = $options;
580  $this->queryFlagsUsedForCaching[$userKey] = $queryFlags;
581  return $options;
582  }
583 
593  private function loadOriginalOptions(
594  UserIdentity $user,
595  int $queryFlags = self::READ_NORMAL,
596  array $data = null
597  ): array {
598  $userKey = $this->getCacheKey( $user );
599  $defaultOptions = $this->defaultOptionsLookup->getDefaultOptions();
600  if ( !$user->isRegistered() ) {
601  // For unlogged-in users, load language/variant options from request.
602  // There's no need to do it for logged-in users: they can set preferences,
603  // and handling of page content is done by $pageLang->getPreferredVariant() and such,
604  // so don't override user's choice (especially when the user chooses site default).
605  $variant = $this->languageConverterFactory->getLanguageConverter()->getDefaultVariant();
606  $defaultOptions['variant'] = $variant;
607  $defaultOptions['language'] = $variant;
608  $this->originalOptionsCache[$userKey] = $defaultOptions;
609  return $defaultOptions;
610  }
611 
612  // In case options were already loaded from the database before and no options
613  // changes were saved to the database, we can use the cached original options.
614  if ( $this->canUseCachedValues( $user, $queryFlags )
615  && isset( $this->originalOptionsCache[$userKey] )
616  ) {
617  return $this->originalOptionsCache[$userKey];
618  }
619 
620  $options = $this->loadOptionsFromDb( $user, $queryFlags, $data ) + $defaultOptions;
621  // Replace deprecated language codes
622  $options['language'] = LanguageCode::replaceDeprecatedCodes( $options['language'] );
623  // Fix up timezone offset (Due to DST it can change from what was stored in the DB)
624  // ZoneInfo|offset|TimeZoneName
625  if ( isset( $options['timecorrection'] ) ) {
626  $options['timecorrection'] = ( new UserTimeCorrection(
627  $options['timecorrection'],
628  null,
629  $this->serviceOptions->get( 'LocalTZoffset' )
630  ) )->toString();
631  }
632 
633  // Need to store what we have so far before the hook to prevent
634  // infinite recursion if the hook attempts to reload options
635  $this->originalOptionsCache[$userKey] = $options;
636  $this->queryFlagsUsedForCaching[$userKey] = $queryFlags;
637  // TODO: Remove deprecated hook.
638  $this->hookRunner->onUserLoadOptions(
639  User::newFromIdentity( $user ), $options
640  );
641  $this->hookRunner->onLoadUserOptions( $user, $options );
642  $this->originalOptionsCache[$userKey] = $options;
643  return $options;
644  }
645 
651  private function getCacheKey( UserIdentity $user ): string {
652  return $user->isRegistered() ? "u:{$user->getId()}" : 'anon';
653  }
654 
659  private function getDBAndOptionsForQueryFlags( $queryFlags ): array {
660  list( $mode, $options ) = DBAccessObjectUtils::getDBOptions( $queryFlags );
661  return [ $this->loadBalancer->getConnectionRef( $mode, [] ), $options ];
662  }
663 
670  private function canUseCachedValues( UserIdentity $user, int $queryFlags ): bool {
671  if ( !$user->isRegistered() ) {
672  // Anon users don't have options stored in the database,
673  // so $queryFlags are ignored.
674  return true;
675  }
676  $userKey = $this->getCacheKey( $user );
677  $queryFlagsUsed = $this->queryFlagsUsedForCaching[$userKey] ?? self::READ_NONE;
678  return $queryFlagsUsed >= $queryFlags;
679  }
680 
690  private function isValueEqual( $a, $b ) {
691  if ( is_bool( $a ) ) {
692  $a = (int)$a;
693  }
694  if ( is_bool( $b ) ) {
695  $b = (int)$b;
696  }
697  return (string)$a === (string)$b;
698  }
699 }
MediaWiki\User\UserOptionsManager\setOption
setOption(UserIdentity $user, string $oname, $val)
Set the given option for a user.
Definition: UserOptionsManager.php:193
LanguageCode\replaceDeprecatedCodes
static replaceDeprecatedCodes( $code)
Replace deprecated language codes that were used in previous versions of MediaWiki to up-to-date,...
Definition: LanguageCode.php:161
MediaWiki\User\UserTimeCorrection
Utility class to parse the TimeCorrection string value.
Definition: UserTimeCorrection.php:41
MediaWiki\User\UserOptionsManager\$modifiedOptions
array $modifiedOptions
options modified withing this request
Definition: UserOptionsManager.php:69
MediaWiki\User\UserOptionsManager\isValueEqual
isValueEqual( $a, $b)
Determines whether two values are sufficiently similar that the database does not need to be updated ...
Definition: UserOptionsManager.php:690
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:199
MediaWiki\User\UserOptionsManager\saveOptions
saveOptions(UserIdentity $user)
Saves the non-default options for this user, as previously set e.g.
Definition: UserOptionsManager.php:388
MediaWiki\User\UserOptionsManager\$optionsFromDb
array $optionsFromDb
Cached original user options as fetched from database, no adjustments applied.
Definition: UserOptionsManager.php:82
MediaWiki\User\UserOptionsManager\getDefaultOptions
getDefaultOptions()
Combine the language default options with any site-specific options and add the default language vari...
Definition: UserOptionsManager.php:118
MediaWiki\User\UserOptionsManager\$hookRunner
HookRunner $hookRunner
Definition: UserOptionsManager.php:85
MediaWiki\User\UserOptionsManager\getOptions
getOptions(UserIdentity $user, int $flags=0, int $queryFlags=self::READ_NORMAL)
Get all user's options.The user to get the option for Bitwise combination of: UserOptionsManager::EXC...
Definition: UserOptionsManager.php:151
User\newFromIdentity
static newFromIdentity(UserIdentity $identity)
Returns a User object corresponding to the given UserIdentity.
Definition: User.php:683
MediaWiki\User\UserIdentity\getId
getId( $wikiId=self::LOCAL)
DBAccessObjectUtils\getDBOptions
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
Definition: DBAccessObjectUtils.php:52
$res
$res
Definition: testCompression.php:57
MediaWiki\Languages\LanguageConverterFactory
An interface for creating language converters.
Definition: LanguageConverterFactory.php:46
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\User\UserOptionsManager\listOptionKinds
listOptionKinds()
Return a list of the types of user options currently returned by UserOptionsManager::getOptionKinds()...
Definition: UserOptionsManager.php:278
MediaWiki\User\UserOptionsManager\getOption
getOption(UserIdentity $user, string $oname, $defaultOverride=null, bool $ignoreHidden=false, int $queryFlags=self::READ_NORMAL)
Get the user's current setting for a given option.The user to get the option for The option to check ...
Definition: UserOptionsManager.php:125
$dbr
$dbr
Definition: testCompression.php:54
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:260
MediaWiki\User\DefaultOptionsLookup
A service class to control default user options.
Definition: DefaultOptionsLookup.php:35
MediaWiki\Config\ServiceOptions
A class for passing options to services.
Definition: ServiceOptions.php:27
MediaWiki\User\UserOptionsManager\$loadBalancer
ILoadBalancer $loadBalancer
Definition: UserOptionsManager.php:63
MediaWiki\User\UserIdentity\isRegistered
isRegistered()
MediaWiki\User\UserOptionsManager\getCacheKey
getCacheKey(UserIdentity $user)
Gets a key for various caches.
Definition: UserOptionsManager.php:651
MediaWiki\User\UserOptionsManager\$originalOptionsCache
array $originalOptionsCache
Cached original user options with all the adjustments like time correction and hook changes applied.
Definition: UserOptionsManager.php:76
HTMLFormField
The parent class to generate form fields.
Definition: HTMLFormField.php:9
MediaWiki\User\UserOptionsManager\getDBAndOptionsForQueryFlags
getDBAndOptionsForQueryFlags( $queryFlags)
Definition: UserOptionsManager.php:659
MediaWiki\User\UserOptionsManager\clearUserOptionsCache
clearUserOptionsCache(UserIdentity $user)
Clears cached user options.
Definition: UserOptionsManager.php:510
MediaWiki\User\UserOptionsManager\$defaultOptionsLookup
DefaultOptionsLookup $defaultOptionsLookup
Definition: UserOptionsManager.php:57
MediaWiki\User\UserOptionsManager\getOptionKinds
getOptionKinds(UserIdentity $userIdentity, IContextSource $context, $options=null)
Return an associative array mapping preferences keys to the kind of a preference they're used for.
Definition: UserOptionsManager.php:302
IDBAccessObject\READ_NONE
const READ_NONE
Constants for object loading bitfield flags (higher => higher QoS)
Definition: IDBAccessObject.php:75
DBAccessObjectUtils
Helper class for DAO classes.
Definition: DBAccessObjectUtils.php:29
MediaWiki\User\UserOptionsManager\$queryFlagsUsedForCaching
array $queryFlagsUsedForCaching
Query flags used to retrieve options from database.
Definition: UserOptionsManager.php:88
MediaWiki\User\UserOptionsManager\loadUserOptions
loadUserOptions(UserIdentity $user, int $queryFlags=self::READ_NORMAL, array $data=null)
Loads user options either from cache or from the database.
Definition: UserOptionsManager.php:495
MediaWiki\User\UserOptionsManager\resetOptions
resetOptions(UserIdentity $user, IContextSource $context, $resetKinds=[ 'registered', 'registered-multiselect', 'registered-checkmatrix', 'unused'])
Reset certain (or all) options to the site defaults.
Definition: UserOptionsManager.php:215
MediaWiki\User\UserOptionsManager\$logger
LoggerInterface $logger
Definition: UserOptionsManager.php:66
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
MediaWiki\User
Definition: ActorCache.php:21
MediaWiki\User\UserOptionsLookup
Provides access to user options.
Definition: UserOptionsLookup.php:29
MediaWiki\User\UserOptionsManager\$serviceOptions
ServiceOptions $serviceOptions
Definition: UserOptionsManager.php:54
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
MediaWiki\User\UserOptionsManager
A service class to control user options.
Definition: UserOptionsManager.php:43
HTMLCheckMatrix
A checkbox matrix Operates similarly to HTMLMultiSelectField, but instead of using an array of option...
Definition: HTMLCheckMatrix.php:27
MediaWiki\User\UserOptionsManager\$languageConverterFactory
LanguageConverterFactory $languageConverterFactory
Definition: UserOptionsManager.php:60
HTMLMultiSelectField
Multi-select field.
Definition: HTMLMultiSelectField.php:8
MediaWiki\User\UserOptionsManager\CONSTRUCTOR_OPTIONS
const CONSTRUCTOR_OPTIONS
Definition: UserOptionsManager.php:48
MediaWiki\User\UserOptionsManager\loadOriginalOptions
loadOriginalOptions(UserIdentity $user, int $queryFlags=self::READ_NORMAL, array $data=null)
Loads the original user options from the database and applies various transforms, like timecorrection...
Definition: UserOptionsManager.php:593
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition: HookContainer.php:45
LanguageCode
Methods for dealing with language codes.
Definition: LanguageCode.php:27
HTMLFormField\flattenOptions
static flattenOptions( $options)
flatten an array of options to a single array, for instance, a set of "<options>" inside "<optgroups>...
Definition: HTMLFormField.php:1154
MediaWiki\User\UserOptionsManager\canUseCachedValues
canUseCachedValues(UserIdentity $user, int $queryFlags)
Determines if it's ok to use cached options values for a given user and query flags.
Definition: UserOptionsManager.php:670
MediaWiki\HookContainer\HookRunner
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
Definition: HookRunner.php:557
MediaWiki\User\UserOptionsManager\loadOptionsFromDb
loadOptionsFromDb(UserIdentity $user, int $queryFlags, array $prefetchedOptions=null)
Fetches the options directly from the database with no caches.
Definition: UserOptionsManager.php:526
MediaWiki\$context
IContextSource $context
Definition: MediaWiki.php:40
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:68
MediaWiki\User\UserOptionsManager\setOptionsFromDb
setOptionsFromDb(UserIdentity $user, int $queryFlags, iterable $rows)
Builds associative options array from rows fetched from DB.
Definition: UserOptionsManager.php:561
Wikimedia\Rdbms\ILoadBalancer
Database cluster connection, tracking, load balancing, and transaction manager interface.
Definition: ILoadBalancer.php:81
MediaWiki\Config\ServiceOptions\assertRequiredOptions
assertRequiredOptions(array $expectedKeys)
Assert that the list of options provided in this instance exactly match $expectedKeys,...
Definition: ServiceOptions.php:71
MediaWiki\User\UserOptionsManager\__construct
__construct(ServiceOptions $options, DefaultOptionsLookup $defaultOptionsLookup, LanguageConverterFactory $languageConverterFactory, ILoadBalancer $loadBalancer, LoggerInterface $logger, HookContainer $hookContainer)
Definition: UserOptionsManager.php:98