Extension:GlobalPreferences/API

From Linux Web Expert

Getting global preferences

If only the effective preferences for a user are required, the usual meta=userinfo&uiprop=options can be used, however if you need to know where is every preference value coming from, you will need to use this API.

Parameters

  • <translate> <tvar1>{{{maxallowed}}}</> (<tvar (<translate> Default:</translate> preferences|localoverrides)
    • <translate> <tvar1>{{{maxallowed}}}</> (<tvar
    • <translate> <tvar1>{{{maxallowed}}}</> (<tvar

Example

Getting global preferences

<translate> Result</translate>
{
    "batchcomplete": "",
    "query": {
        "globalpreferences": {
            "preferences": {
                "advancedsearch": "1",
                "ccmeonemails": "1",
                "disablemail": "0",
                "email-allow-new-users": 1
            },
            "localoverrides": {
                "ccmeonemails": 0,
                "email-allow-new-users": 0
            }
        }
    }
}

Possible errors

None.

Setting global preferences and local overrides

Token

To change options, a CSRF token is required.

Tokens can be obtained via action=query&meta=tokens

Obtaining a token

<translate> Result</translate>
{
    "query": {
        "tokens": {
            "csrftoken": "f38d52ee5c9b49ce17f5e55c48bb1166547cbc71+\\"
        }
    }
}

Changing options

GlobalPreferences provides two modules to change preferences, action=globalpreferences and action=globalpreferenceoverrides. They work exactly like action=options and have the same parameters.

Parameters

  • <translate> <tvar1>{{{maxallowed}}}</> (<tvar
    • Resetting a global preference means it will not be global anymore while resetting a local override means that the global preference will be used.
  • <translate> <tvar1>{{{maxallowed}}}</> (<tvar (<translate> Default:</translate> all)
  • <translate> <tvar1>{{{maxallowed}}}</> (<tvar
Note: Providing only names of preferences without equal sign (e.g. hideminor|skin) results in resetting them. In the case of an arbitrary userjs- name/value pair, the resetting should result in the removal of the name/value pair—except it doesn't currently.
  • <translate> <tvar1>{{{maxallowed}}}</> (<tvar
  • <translate> <tvar1>{{{maxallowed}}}</> (<tvar
  • <translate> <tvar1>{{{maxallowed}}}</> (<tvar

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

Note: In this example, all parameters are passed in a GET request for the sake of simplicity. However, changing preferences requires POST requests; GET requests will cause an error. Changing a single preference

<translate> Result</translate>
{
    "globalpreferences": "success"
}

Resetting all preferences and then setting a single one

<translate> Result</translate>
{
    "globalpreferences": "success"
}

Changing three preferences

<translate> Result</translate>
{
    "globalpreferenceoverrides": "success"
}

Possible errors

In addition to the usual stuff :

Code Info
notloggedin Anonymous users cannot change preferences
nochanges No changes were requested