MediaWiki  master
StaticUserOptionsLookup.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\User;
4 
11 
13  private $userMap;
14 
16  private $defaults;
17 
22  public function __construct( array $userMap, array $defaults = [] ) {
23  $this->userMap = $userMap;
24  $this->defaults = $defaults;
25  }
26 
28  public function getDefaultOptions(): array {
29  return $this->defaults;
30  }
31 
33  public function getOption(
34  UserIdentity $user,
35  string $oname,
36  $defaultOverride = null,
37  bool $ignoreHidden = false,
38  int $queryFlags = self::READ_NORMAL
39  ) {
40  $userOptions = $this->getOptions( $user );
41  if ( array_key_exists( $oname, $userOptions ) ) {
42  return $userOptions[$oname];
43  } else {
44  return $defaultOverride;
45  }
46  }
47 
49  public function getOptions(
50  UserIdentity $user,
51  int $flags = 0,
52  int $queryFlags = self::READ_NORMAL
53  ): array {
54  $userOptions = [];
55  if ( $user->isRegistered() ) {
56  $userOptions = $this->userMap[$user->getName()] ?? [];
57  }
58  if ( !( $flags & self::EXCLUDE_DEFAULTS ) ) {
59  $userOptions += $this->defaults;
60  }
61  return $userOptions;
62  }
63 }
MediaWiki\User\StaticUserOptionsLookup\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: StaticUserOptionsLookup.php:33
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\User\StaticUserOptionsLookup\$defaults
mixed[] $defaults
Definition: StaticUserOptionsLookup.php:16
MediaWiki\User\StaticUserOptionsLookup\getDefaultOptions
getDefaultOptions()
Combine the language default options with any site-specific options and add the default language vari...
Definition: StaticUserOptionsLookup.php:28
MediaWiki\User\UserIdentity\isRegistered
isRegistered()
MediaWiki\User\StaticUserOptionsLookup
A UserOptionsLookup that's just an array.
Definition: StaticUserOptionsLookup.php:10
MediaWiki\User\StaticUserOptionsLookup\$userMap
array[] $userMap
Definition: StaticUserOptionsLookup.php:13
MediaWiki\User\StaticUserOptionsLookup\__construct
__construct(array $userMap, array $defaults=[])
Definition: StaticUserOptionsLookup.php:22
MediaWiki\User\UserIdentity\getName
getName()
MediaWiki\User\StaticUserOptionsLookup\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: StaticUserOptionsLookup.php:49
MediaWiki\User
Definition: ActorCache.php:21
MediaWiki\User\UserOptionsLookup
Provides access to user options.
Definition: UserOptionsLookup.php:29