Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7491188
ApiGlobalPreferences.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
ApiGlobalPreferences.php
View Options
<?php
namespace
GlobalPreferences
;
use
MediaWiki\Api\ApiMain
;
use
MediaWiki\Api\ApiOptionsBase
;
use
MediaWiki\User\Options\UserOptionsManager
;
class
ApiGlobalPreferences
extends
ApiOptionsBase
{
/** @var mixed[] */
private
$prefs
=
[];
/** @var string[] */
private
$resetPrefTypes
=
[];
public
function
__construct
(
ApiMain
$mainModule
,
string
$moduleName
,
private
readonly
GlobalPreferencesFactory
$factory
,
UserOptionsManager
$userOptionsManager
)
{
parent
::
__construct
(
$mainModule
,
$moduleName
,
$userOptionsManager
,
$factory
);
}
/**
* @inheritDoc
*/
public
function
execute
()
{
$user
=
$this
->
getUserFromPrimaryOrNull
();
if
(
$user
)
{
$factory
=
$this
->
getFactory
();
if
(
!
$factory
->
isUserGlobalized
(
$user
)
)
{
$this
->
dieWithError
(
'apierror-globalpreferences-notglobalized'
,
'notglobalized'
);
}
}
parent
::
execute
();
}
/**
* @return GlobalPreferencesFactory
*/
private
function
getFactory
()
{
return
$this
->
factory
;
}
/**
* @inheritDoc
*/
protected
function
resetPreferences
(
array
$kinds
)
{
if
(
in_array
(
'all'
,
$kinds
)
)
{
$this
->
getFactory
()->
resetGlobalUserSettings
(
$this
->
getUserFromPrimary
()
);
}
else
{
$this
->
resetPrefTypes
=
$kinds
;
}
}
/**
* @inheritDoc
*/
protected
function
setPreference
(
$preference
,
$value
)
{
$this
->
prefs
[
$preference
]
=
$value
;
}
/**
* @inheritDoc
*/
protected
function
commitChanges
()
{
$factory
=
$this
->
getFactory
();
$user
=
$this
->
getUserFromPrimary
();
$prefs
=
$this
->
getFactory
()->
getGlobalPreferencesValues
(
$user
,
true
);
if
(
$prefs
===
false
)
{
return
;
}
if
(
$this
->
resetPrefTypes
)
{
$kinds
=
$this
->
getFactory
()->
getResetKinds
(
$this
->
getUserFromPrimary
(),
$this
->
getContext
(),
$prefs
);
foreach
(
$prefs
as
$pref
=>
$value
)
{
$kind
=
$kinds
[
$pref
];
if
(
in_array
(
$kind
,
$this
->
resetPrefTypes
)
)
{
$prefs
[
$pref
]
=
null
;
}
}
}
$prefs
=
array_merge
(
$prefs
,
$this
->
prefs
);
$factory
->
setGlobalPreferences
(
$user
,
$prefs
,
$this
->
getContext
()
);
}
/**
* @inheritDoc
*/
public
function
getHelpUrls
()
{
return
'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Globalpreferences'
;
}
/**
* @inheritDoc
*/
protected
function
getExamplesMessages
()
{
return
[
'action=globalpreferences&change=skin=&token=123ABC'
=>
'apihelp-globalpreferences-example-reset-one'
,
'action=globalpreferences&reset=&token=123ABC'
=>
'apihelp-globalpreferences-example-reset'
,
'action=globalpreferences&change=skin=vector|hideminor=1&token=123ABC'
=>
'apihelp-globalpreferences-example-change'
,
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 19:21 (6 d, 4 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f8/ff/ed2e7937653d322bdc8eec0b173a
Default Alt Text
ApiGlobalPreferences.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment