Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7481221
ApiQueryGlobalPreferences.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
ApiQueryGlobalPreferences.php
View Options
<?php
namespace
GlobalPreferences
;
use
MediaWiki\Api\ApiBase
;
use
MediaWiki\Api\ApiQuery
;
use
MediaWiki\Api\ApiQueryBase
;
use
MediaWiki\Api\ApiResult
;
use
MediaWiki\User\Options\UserOptionsLookup
;
use
Wikimedia\ParamValidator\ParamValidator
;
class
ApiQueryGlobalPreferences
extends
ApiQueryBase
{
public
function
__construct
(
ApiQuery
$queryModule
,
string
$moduleName
,
private
readonly
GlobalPreferencesFactory
$preferencesFactory
,
private
readonly
UserOptionsLookup
$userOptionsLookup
,
)
{
parent
::
__construct
(
$queryModule
,
$moduleName
,
'gpr'
);
}
/**
* @inheritDoc
*/
public
function
execute
()
{
if
(
!
$this
->
getUser
()->
isNamed
()
)
{
$this
->
dieWithError
(
[
'apierror-mustbeloggedin'
,
$this
->
msg
(
'action-editmyoptions'
)
],
'notloggedin'
);
}
if
(
!
$this
->
preferencesFactory
->
isUserGlobalized
(
$this
->
getUser
()
)
)
{
$this
->
dieWithError
(
'apierror-globalpreferences-notglobalized'
,
'notglobalized'
);
}
$params
=
$this
->
extractRequestParams
();
$prop
=
array_flip
(
$params
[
'prop'
]
);
$result
=
[];
ApiResult
::
setArrayType
(
$result
,
'assoc'
);
if
(
isset
(
$prop
[
'preferences'
]
)
)
{
$prefs
=
$this
->
preferencesFactory
->
getGlobalPreferencesValues
(
$this
->
getUser
()
);
$result
[
'preferences'
]
=
$prefs
;
ApiResult
::
setArrayType
(
$result
[
'preferences'
],
'assoc'
);
}
if
(
isset
(
$prop
[
'localoverrides'
]
)
)
{
$overriddenPrefs
=
[];
$userOptions
=
$this
->
userOptionsLookup
->
getOptions
(
$this
->
getUser
()
);
foreach
(
$userOptions
as
$pref
=>
$value
)
{
if
(
GlobalPreferencesFactory
::
isLocalPrefName
(
$pref
)
)
{
$mainPref
=
substr
(
$pref
,
0
,
-
strlen
(
UserOptionsLookup
::
LOCAL_EXCEPTION_SUFFIX
)
);
if
(
isset
(
$userOptions
[
$mainPref
]
)
)
{
$overriddenPrefs
[
$mainPref
]
=
$userOptions
[
$mainPref
];
}
}
}
$result
[
'localoverrides'
]
=
$overriddenPrefs
;
ApiResult
::
setArrayType
(
$result
[
'localoverrides'
],
'assoc'
);
}
$this
->
getResult
()->
addValue
(
'query'
,
$this
->
getModuleName
(),
$result
);
}
/**
* @inheritDoc
*/
public
function
getAllowedParams
()
{
return
[
'prop'
=>
[
ParamValidator
::
PARAM_TYPE
=>
[
'preferences'
,
'localoverrides'
,
],
ParamValidator
::
PARAM_ISMULTI
=>
true
,
ParamValidator
::
PARAM_DEFAULT
=>
'preferences|localoverrides'
,
ApiBase
::
PARAM_HELP_MSG_PER_VALUE
=>
[],
],
];
}
/**
* @inheritDoc
*/
public
function
getHelpUrls
()
{
return
[
'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:GlobalPreferences/API'
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 12:35 (1 w, 8 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
24/86/5f6b65eb3a79d398a57a25f7460b
Default Alt Text
ApiQueryGlobalPreferences.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment