36 if ( $this->
getUser()->isAnon() ) {
38 [
'apierror-mustbeloggedin', $this->
msg(
'action-editmyoptions' ) ],
'notloggedin'
47 if ( isset(
$params[
'optionvalue'] ) && !isset(
$params[
'optionname'] ) ) {
48 $this->
dieWithError( [
'apierror-missingparam',
'optionname' ] );
52 $user = $this->
getUser()->getInstanceForUpdate();
55 [
'apierror-mustbeloggedin', $this->
msg(
'action-editmyoptions' ) ],
'notloggedin'
66 foreach (
$params[
'change'] as $entry ) {
67 $array = explode(
'=', $entry, 2 );
68 $changes[$array[0]] = isset( $array[1] ) ? $array[1] :
null;
71 if ( isset(
$params[
'optionname'] ) ) {
72 $newValue = isset(
$params[
'optionvalue'] ) ?
$params[
'optionvalue'] :
null;
73 $changes[
$params[
'optionname']] = $newValue;
75 if ( !$changed && !count( $changes ) ) {
79 $preferencesFactory = MediaWikiServices::getInstance()->getPreferencesFactory();
80 $prefs = $preferencesFactory->getFormDescriptor( $user, $this->
getContext() );
81 $prefsKinds = $user->getOptionKinds( $this->
getContext(), $changes );
84 foreach ( $changes as $key =>
$value ) {
85 switch ( $prefsKinds[$key] ) {
88 if ( $htmlForm ===
null ) {
90 $htmlForm =
new HTMLForm( [], $this );
92 $field = HTMLForm::loadInputFromParameters( $key, $prefs[$key], $htmlForm );
93 $validation = $field->validate(
$value, $user->getOptions() );
95 case 'registered-multiselect':
96 case 'registered-checkmatrix':
103 if ( strlen( $key ) > 255 ) {
104 $validation = $this->
msg(
'apiwarn-validationfailed-keytoolong', Message::numParam( 255 ) );
105 } elseif ( preg_match(
'/[^a-zA-Z0-9_-]/', $key ) !== 0 ) {
106 $validation = $this->
msg(
'apiwarn-validationfailed-badchars' );
112 $validation = $this->
msg(
'apiwarn-validationfailed-cannotset' );
116 $validation = $this->
msg(
'apiwarn-validationfailed-badpref' );
119 if ( $validation ===
true ) {
120 $user->setOption( $key,
$value );
129 $user->saveSettings();
145 $optionKinds[] =
'all';
171 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Options';
176 'action=options&reset=&token=123ABC'
177 =>
'apihelp-options-example-reset',
178 'action=options&change=skin=vector|hideminor=1&token=123ABC'
179 =>
'apihelp-options-example-change',
180 'action=options&reset=&change=skin=monobook&optionname=nickname&' .
181 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC'
182 =>
'apihelp-options-example-complex',
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This abstract class implements many basic API functions, and is the base of all API classes.
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getResult()
Get the result object.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
API module that facilitates the changing of user's preferences.
isWriteMode()
Indicates whether this module requires write mode.
getExamplesMessages()
Returns usage examples for this module.
needsToken()
Returns the token type this module requires in order to execute.
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Changes preferences of the current user.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
mustBePosted()
Indicates whether this module must be called with a POST request.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
getContext()
Get the base IContextSource object.
static listOptionKinds()
Return a list of the types of user options currently returned by User::getOptionKinds().
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true