Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5951985
GlobalUserOptionsStore.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
GlobalUserOptionsStore.php
View Options
<?php
namespace
GlobalPreferences
;
use
MediaWiki\Logger\LoggerFactory
;
use
MediaWiki\User\CentralId\CentralIdLookup
;
use
MediaWiki\User\Options\UserOptionsStore
;
use
MediaWiki\User\UserIdentity
;
use
Psr\Log\LoggerInterface
;
use
Wikimedia\Rdbms\DBAccessObjectUtils
;
use
Wikimedia\Rdbms\IDBAccessObject
;
/**
* An interface which allows core to update pre-existing global preferences
*/
class
GlobalUserOptionsStore
implements
UserOptionsStore
{
/** @var CentralIdLookup */
private
$centralIdLookup
;
/** @var LoggerInterface */
private
$logger
;
public
function
__construct
(
CentralIdLookup
$centralIdLookup
)
{
$this
->
centralIdLookup
=
$centralIdLookup
;
$this
->
logger
=
LoggerFactory
::
getInstance
(
'preferences'
);
}
/**
* @param UserIdentity $user
* @param int $recency
* @return array|string[]
*/
public
function
fetch
(
UserIdentity
$user
,
int
$recency
)
{
$storage
=
$this
->
getStorage
(
$user
);
if
(
!
$storage
)
{
return
[];
}
if
(
DBAccessObjectUtils
::
hasFlags
(
$recency
,
IDBAccessObject
::
READ_LATEST
)
)
{
$dbType
=
DB_PRIMARY
;
}
else
{
$dbType
=
DB_REPLICA
;
}
return
$storage
->
loadFromDB
(
$dbType
,
$recency
);
}
/**
* @param UserIdentity $user
* @param array $updates
* @return bool
*/
public
function
store
(
UserIdentity
$user
,
array
$updates
)
{
$storage
=
$this
->
getStorage
(
$user
);
if
(
!
$storage
)
{
$this
->
logger
->
warning
(
'Unable to store preference for non-global user "{userName}"'
,
[
'userName'
=>
$user
->
getName
()
]
);
return
false
;
}
$replacements
=
[];
$deletions
=
[];
foreach
(
$updates
as
$key
=>
$value
)
{
if
(
$value
===
null
)
{
$deletions
[]
=
$key
;
}
else
{
$replacements
[
$key
]
=
$value
;
}
}
$storage
->
replaceAndDelete
(
$replacements
,
$deletions
);
return
$replacements
||
$deletions
;
}
private
function
getStorage
(
UserIdentity
$user
):
?
Storage
{
if
(
!
$this
->
centralIdLookup
->
isOwned
(
$user
)
)
{
return
null
;
}
$id
=
$this
->
centralIdLookup
->
centralIdFromName
(
$user
->
getName
()
);
if
(
!
$id
)
{
return
null
;
}
return
new
Storage
(
$id
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 3 2026, 01:10 (4 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f0/d0/32e9e30818ff23309b80c894c242
Default Alt Text
GlobalUserOptionsStore.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment