Go to the documentation of this file.
42 [
'apierror-mustbeloggedin', $this->
msg(
'action-editmyoptions' ) ],
'notloggedin'
51 if ( isset(
$params[
'optionvalue'] ) && !isset(
$params[
'optionname'] ) ) {
52 $this->
dieWithError( [
'apierror-missingparam',
'optionname' ] );
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;
71 if ( !$changed && !
count( $changes ) ) {
79 foreach ( $changes
as $key =>
$value ) {
80 switch ( $prefsKinds[$key] ) {
88 if ( $htmlForm ===
null ) {
90 $htmlForm =
new HTMLForm( [], $this );
93 $validation = $field->validate(
$value,
$user->getOptions() );
96 case 'registered-multiselect':
97 case 'registered-checkmatrix':
104 if ( strlen( $key ) > 255 ) {
105 $validation = $this->
msg(
'apiwarn-validationfailed-keytoolong', Message::numParam( 255 ) );
106 } elseif ( preg_match(
'/[^a-zA-Z0-9_-]/', $key ) !== 0 ) {
107 $validation = $this->
msg(
'apiwarn-validationfailed-badchars' );
113 $validation = $this->
msg(
'apiwarn-validationfailed-cannotset' );
117 $validation = $this->
msg(
'apiwarn-validationfailed-badpref' );
120 if ( $validation ===
true ) {
141 if ( !$this->userForUpdates ) {
142 $this->userForUpdates = $this->
getUser()->getInstanceForUpdate();
153 $preferencesFactory = MediaWikiServices::getInstance()->getPreferencesFactory();
192 $optionKinds[] =
'all';
218 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Options';
223 'action=options&reset=&token=123ABC'
224 =>
'apihelp-options-example-reset',
225 'action=options&change=skin=vector|hideminor=1&token=123ABC'
226 =>
'apihelp-options-example-change',
227 'action=options&reset=&change=skin=monobook&optionname=nickname&' .
228 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC'
229 =>
'apihelp-options-example-complex',
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
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.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
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.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
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.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
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.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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.
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
resetPreferences(array $kinds)
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
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.