API:Options
| This page is part of the MediaWiki API documentation. |
| Language: | English |
|---|
Quick overview:
- Quick start guide
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Search suggestions
- Expanding templates and rendering
- Purging pages' caches
- Parameter information
- Changing wiki content
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
| MediaWiki version: | 1.20 |
Contents |
Token [edit]
To change options, an options token is required. It can be obtained as follows:
Obtaining an options token
| Result |
|---|
| The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <tokens optionstoken="58b54e0bab4a1d3fd3f7653af38e75cb+\" /> </api> |
| The above content has been placed in a collapsed box for improved usability. |
Changing options [edit]
Options can be changed using action=options.
While this API is primarily intended for changing options which are registered by MediaWiki core or extensions and available on Special:Preferences, since gerrit change I5f9ba5b0 you can also use it to set arbitrary user options that can be used by user-scripts or external editors.
These arbitrary options have three limits imposed on them:
- the key must start with the prefix
userjs- - the length of the key must not be more than 255 bytes
- the key must consist only of ASCII letters, numbers, hyphens and underscores (a-z, A-Z, 0-9, _, -)
There are currently no hard limits on the length or contents of the value, nor is there a limit on the number of user options you can set at once. You can even store a complex tree of data within a user option by encoding it as a JSON string.
Parameters [edit]
- token: The token obtained in the previous request. Take care to urlencode the trailing
+\as%2B%5C. - reset: Resets all preferences to the site defaults.
- change: Pipe-separated list of changes, formatted name=value (e.g. skin=vector), value cannot contain pipe characters. Providing only names of options without equal sign (e.g. hideminor|skin) results in resetting them.
- optionname: A name of a option which should have an optionvalue set.
- optionvalue: A value of the option specified by the optionname, can contain pipe characters.
The change parameter cannot be used to set a value which contains a pipe character "|", as it is used by the API to separate options. If you need to set such a value (for example, a user signature) use an optionname & optionvalue pair.
Example [edit]
Note: In this example, all parameters are passed in a GET request for the sake of simplicity. However, action=options requires POST requests; GET requests will cause an error. Changing a single option
| Result |
|---|
| The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api options="success" /> |
| The above content has been placed in a collapsed box for improved usability. |
Resetting all options and changing a single option
| Result |
|---|
| The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api options="success" /> |
| The above content has been placed in a collapsed box for improved usability. |
Changing three options
| Result |
|---|
| The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api options="success" /> |
| The above content has been placed in a collapsed box for improved usability. |
Possible errors [edit]
In addition to the usual stuff:
- code: notloggedin
- info: Anonymous users cannot change preferences
- code: nochanges
- info: No changes were requested