MediaWiki  master
UserOptionsLookup.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\User;
22 
23 use IDBAccessObject;
24 
29 abstract class UserOptionsLookup implements IDBAccessObject {
30 
34  public const EXCLUDE_DEFAULTS = 1;
35 
42  abstract public function getDefaultOptions(): array;
43 
50  public function getDefaultOption( string $opt ) {
51  $defaultOptions = $this->getDefaultOptions();
52  return $defaultOptions[$opt] ?? null;
53  }
54 
67  abstract public function getOption(
68  UserIdentity $user,
69  string $oname,
70  $defaultOverride = null,
71  bool $ignoreHidden = false,
72  int $queryFlags = self::READ_NORMAL
73  );
74 
85  abstract public function getOptions(
86  UserIdentity $user,
87  int $flags = 0,
88  int $queryFlags = self::READ_NORMAL
89  ): array;
90 
100  public function getBoolOption(
101  UserIdentity $user,
102  string $oname,
103  int $queryFlags = self::READ_NORMAL
104  ): bool {
105  return (bool)$this->getOption(
106  $user, $oname, null, false, $queryFlags );
107  }
108 
119  public function getIntOption(
120  UserIdentity $user,
121  string $oname,
122  int $defaultOverride = 0,
123  int $queryFlags = self::READ_NORMAL
124  ): int {
125  $val = $this->getOption(
126  $user, $oname, $defaultOverride, false, $queryFlags );
127  if ( $val == '' ) {
128  $val = $defaultOverride;
129  }
130  return intval( $val );
131  }
132 }
MediaWiki\User\UserOptionsLookup\getOptions
getOptions(UserIdentity $user, int $flags=0, int $queryFlags=self::READ_NORMAL)
Get all user's options.
MediaWiki\User\UserOptionsLookup\EXCLUDE_DEFAULTS
const EXCLUDE_DEFAULTS
Exclude user options that are set to their default value.
Definition: UserOptionsLookup.php:34
MediaWiki\User\UserOptionsLookup\getIntOption
getIntOption(UserIdentity $user, string $oname, int $defaultOverride=0, int $queryFlags=self::READ_NORMAL)
Get the user's current setting for a given option, as an integer value.
Definition: UserOptionsLookup.php:119
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:57
MediaWiki\User\UserIdentity
Interface for objects representing user identity.
Definition: UserIdentity.php:39
MediaWiki\User\UserOptionsLookup\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.
MediaWiki\User\UserOptionsLookup\getDefaultOption
getDefaultOption(string $opt)
Get a given default option value.
Definition: UserOptionsLookup.php:50
MediaWiki\User
Definition: ActorCache.php:21
MediaWiki\User\UserOptionsLookup\getBoolOption
getBoolOption(UserIdentity $user, string $oname, int $queryFlags=self::READ_NORMAL)
Get the user's current setting for a given option, as a boolean value.
Definition: UserOptionsLookup.php:100
MediaWiki\User\UserOptionsLookup
Provides access to user options.
Definition: UserOptionsLookup.php:29
MediaWiki\User\UserOptionsLookup\getDefaultOptions
getDefaultOptions()
Combine the language default options with any site-specific options and add the default language vari...