Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4077611
StaticUserOptionsLookup.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
StaticUserOptionsLookup.php
View Options
<?php
namespace
MediaWiki\User\Options
;
use
MediaWiki\User\UserIdentity
;
use
Wikimedia\Rdbms\IDBAccessObject
;
/**
* A UserOptionsLookup that's just an array. Useful for testing and creating staging environments.
* Note that unlike UserOptionsManager, no attempt is made to canonicalize user names.
* @since 1.36
*/
class
StaticUserOptionsLookup
extends
UserOptionsLookup
{
/** @var array[] */
private
$userMap
;
/** @var mixed[] */
private
$defaults
;
/**
* @param array[] $userMap User options, username => [ option name => value ]
* @param mixed[] $defaults Defaults for each option, option name => value
*/
public
function
__construct
(
array
$userMap
,
array
$defaults
=
[]
)
{
$this
->
userMap
=
$userMap
;
$this
->
defaults
=
$defaults
;
}
/** @inheritDoc */
public
function
getDefaultOptions
(
?
UserIdentity
$userIdentity
=
null
):
array
{
return
$this
->
defaults
;
}
/** @inheritDoc */
public
function
getOption
(
UserIdentity
$user
,
string
$oname
,
$defaultOverride
=
null
,
bool
$ignoreHidden
=
false
,
int
$queryFlags
=
IDBAccessObject
::
READ_NORMAL
)
{
$userOptions
=
$this
->
getOptions
(
$user
);
if
(
array_key_exists
(
$oname
,
$userOptions
)
)
{
return
$userOptions
[
$oname
];
}
else
{
return
$defaultOverride
;
}
}
/** @inheritDoc */
public
function
getOptions
(
UserIdentity
$user
,
int
$flags
=
0
,
int
$queryFlags
=
IDBAccessObject
::
READ_NORMAL
):
array
{
$userOptions
=
[];
if
(
$user
->
isRegistered
()
)
{
$userOptions
=
$this
->
userMap
[
$user
->
getName
()]
??
[];
}
if
(
!(
$flags
&
self
::
EXCLUDE_DEFAULTS
)
)
{
$userOptions
+=
$this
->
defaults
;
}
return
$userOptions
;
}
public
function
getOptionBatchForUserNames
(
array
$users
,
string
$key
)
{
$options
=
[];
foreach
(
$users
as
$name
)
{
$options
[
$name
]
=
$this
->
userMap
[
$name
][
$key
]
??
$this
->
defaults
[
$key
]
??
''
;
}
return
$options
;
}
}
/** @deprecated class alias since 1.42 */
class_alias
(
StaticUserOptionsLookup
::
class
,
'MediaWiki
\U
ser
\S
taticUserOptionsLookup'
);
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 18 2026, 03:27 (9 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f1/2a/ad51c9ef0f2bf48f15137f273758
Default Alt Text
StaticUserOptionsLookup.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment