Go to the documentation of this file.
40 if ( !$user || $user->isAnon() ) {
42 [
'apierror-mustbeloggedin', $this->
msg(
'action-editmyoptions' ) ],
'notloggedin'
51 if ( isset( $params[
'optionvalue'] ) && !isset( $params[
'optionname'] ) ) {
52 $this->
dieWithError( [
'apierror-missingparam',
'optionname' ] );
55 $resetKinds = $params[
'resetkinds'];
56 if ( !$params[
'reset'] ) {
61 if ( $params[
'change'] ) {
62 foreach ( $params[
'change'] as $entry ) {
63 $array = explode(
'=', $entry, 2 );
64 $changes[$array[0]] = $array[1] ??
null;
67 if ( isset( $params[
'optionname'] ) ) {
68 $newValue = $params[
'optionvalue'] ??
null;
69 $changes[$params[
'optionname']] = $newValue;
72 Hooks::run(
'ApiOptions', [ $this, $user, $changes, $resetKinds ] );
79 if ( !$changed && !count( $changes ) ) {
84 $prefsKinds = $user->getOptionKinds( $this->
getContext(), $changes );
87 foreach ( $changes as $key => $value ) {
88 switch ( $prefsKinds[$key] ) {
91 if ( $value ===
null ) {
96 if ( $htmlForm ===
null ) {
98 $htmlForm =
new HTMLForm( [], $this );
101 $validation = $field->validate( $value, $user->getOptions() );
104 case 'registered-multiselect':
105 case 'registered-checkmatrix':
108 $value = $value !==
null ? (bool)$value :
null;
112 if ( strlen( $key ) > 255 ) {
113 $validation = $this->
msg(
'apiwarn-validationfailed-keytoolong', Message::numParam( 255 ) );
114 } elseif ( preg_match(
'/[^a-zA-Z0-9_-]/', $key ) !== 0 ) {
115 $validation = $this->
msg(
'apiwarn-validationfailed-badchars' );
121 $validation = $this->
msg(
'apiwarn-validationfailed-cannotset' );
125 $validation = $this->
msg(
'apiwarn-validationfailed-badpref' );
128 if ( $validation ===
true ) {
149 if ( !$this->userForUpdates ) {
150 $this->userForUpdates = $this->
getUser()->getInstanceForUpdate();
161 $preferencesFactory = MediaWikiServices::getInstance()->getPreferencesFactory();
200 $optionKinds[] =
'all';
226 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Options';
231 'action=options&reset=&token=123ABC'
232 =>
'apihelp-options-example-reset',
233 'action=options&change=skin=vector|hideminor=1&token=123ABC'
234 =>
'apihelp-options-example-change',
235 'action=options&reset=&change=skin=monobook&optionname=nickname&' .
236 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC'
237 =>
'apihelp-options-example-complex',
getContext()
Get the base IContextSource object.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getUserForUpdates()
Load the user from the master to reduce CAS errors on double post (T95839)
commitChanges()
Applies changes to user preferences.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
isWriteMode()
Indicates whether this module requires write mode.
getPreferences()
Returns preferences form descriptor.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
This abstract class implements many basic API functions, and is the base of all API classes.
setPreference( $preference, $value)
Sets one user preference to be applied by commitChanges()
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Changes preferences of the current user.
getExamplesMessages()
Returns usage examples for this module.
mustBePosted()
Indicates whether this module must be called with a POST request.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
API module that facilitates the changing of user's preferences.
needsToken()
Returns the token type this module requires in order to execute.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
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.
resetPreferences(array $kinds)
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
getHelpUrls()
Return links to more detailed help pages about the module.
static listOptionKinds()
Return a list of the types of user options currently returned by User::getOptionKinds().
User $userForUpdates
User account to modify.