38 if ( $this->
getUser()->isAnon() ) {
39 $this->
dieUsage(
'Anonymous users cannot change preferences',
'notloggedin' );
40 } elseif ( !$this->
getUser()->isAllowed(
'editmyoptions' ) ) {
41 $this->
dieUsage(
"You don't have permission to edit your options",
'permissiondenied' );
47 if ( isset(
$params[
'optionvalue'] ) && !isset(
$params[
'optionname'] ) ) {
48 $this->
dieUsageMsg( [
'missingparam',
'optionname' ] );
54 $this->
dieUsage(
'Anonymous users cannot change preferences',
'notloggedin' );
63 if ( count(
$params[
'change'] ) ) {
65 $array = explode(
'=', $entry, 2 );
66 $changes[$array[0]] = isset( $array[1] ) ? $array[1] :
null;
69 if ( isset(
$params[
'optionname'] ) ) {
70 $newValue = isset(
$params[
'optionvalue'] ) ?
$params[
'optionvalue'] :
null;
71 $changes[
$params[
'optionname']] = $newValue;
73 if ( !$changed && !count( $changes ) ) {
74 $this->
dieUsage(
'No changes were requested',
'nochanges' );
81 foreach ( $changes
as $key =>
$value ) {
82 switch ( $prefsKinds[$key] ) {
85 if ( $htmlForm ===
null ) {
87 $htmlForm =
new HTMLForm( [], $this );
90 $validation = $field->validate(
$value,
$user->getOptions() );
92 case 'registered-multiselect':
93 case 'registered-checkmatrix':
100 if ( strlen( $key ) > 255 ) {
101 $validation =
'key too long (no more than 255 bytes allowed)';
102 } elseif ( preg_match(
'/[^a-zA-Z0-9_-]/', $key ) !== 0 ) {
103 $validation =
'invalid key (only a-z, A-Z, 0-9, _, - allowed)';
109 $validation =
'cannot be set by this module';
113 $validation =
'not a valid preference';
116 if ( $validation ===
true ) {
120 $this->
setWarning(
"Validation error for '$key': $validation" );
126 $user->saveSettings();
141 $optionKinds = User::listOptionKinds();
142 $optionKinds[] =
'all';
168 return 'https://www.mediawiki.org/wiki/API:Options';
173 'action=options&reset=&token=123ABC'
174 =>
'apihelp-options-example-reset',
175 'action=options&change=skin=vector|hideminor=1&token=123ABC'
176 =>
'apihelp-options-example-change',
177 'action=options&reset=&change=skin=monobook&optionname=nickname&' .
178 'optionvalue=[[User:Beau|Beau]]%20([[User_talk:Beau|talk]])&token=123ABC'
179 =>
'apihelp-options-example-complex',
This abstract class implements many basic API functions, and is the base of all API classes.
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,...
dieUsageMsg( $error)
Output the error message related to a certain array.
setWarning( $warning)
Set warning section for this module.
getResult()
Get the result object.
getModuleName()
Get the name of the module being executed by this instance.
dieUsage( $description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
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.
getUser()
Get the User object.
getContext()
Get the base IContextSource object.
static getPreferences( $user, IContextSource $context)
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
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 local account $user
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 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