mw.user

User library provided by 'mediawiki.user' ResourceLoader module.

Namespaces

clientPrefs
Manage client preferences.

Properties

options :mw.Mapstatic #

Map of user preferences and their values.

Type:

Source:
Map of user preferences and their values.

tokens :mw.Mapstatic #

Map of retrieved user tokens.

Type:

Source:
Map of retrieved user tokens.

Methods

acquireTempUserName() → {jQuery.Promise}static #

Acquire a temporary user username and stash it in the current session, if temp account creation is enabled and the current user is logged out. If a name has already been stashed, returns the same name.

If the user later performs an action that results in temp account creation, the stashed username will be used for their account. It may also be used in previews. However, the account is not created yet, and the name is not visible to other users.

Source:

Returns:

Promise resolved with the username if we succeeded, or resolved with null if we failed

Type
jQuery.Promise

Acquire a temporary user username and stash it in the current session, if temp account creation is enabled and the current user is logged out.

generateRandomSessionId() → {string}static #

Generate a random user session ID.

This information would potentially be stored in a cookie to identify a user during a session or series of sessions. Its uniqueness should not be depended on unless the browser supports the crypto API.

Known problems with Math.random(): Using the Math.random function we have seen sets with 1% of non uniques among 200,000 values with Safari providing most of these. Given the prevalence of Safari in mobile the percentage of duplicates in mobile usages of this code is probably higher.

Rationale: We need about 80 bits to make sure that probability of collision on 155 billion is <= 1%

See https://en.wikipedia.org/wiki/Birthday_attack#Mathematics

n(p;H) = n(0.01,2^80)= sqrt (2 * 2^80 * ln(1/(1-0.01)))

Source:

Returns:

80 bit integer (20 characters) in hex format, padded

Type
string
Generate a random user session ID.

getFirstRegistration() → {boolean|null|Date}static #

Get date user first registered, if available.

Source:

Returns:

False for anonymous users, null if data is unavailable, or Date for when the user registered. For temporary users that is when their temporary account was created.

Type
boolean | null | Date
Get date user first registered, if available.

getGroups(callback) → {jQuery.Promise}static #

Get the current user's groups.

Parameters:

Name Type Attributes Description
callback function optional
Source:

Returns:

Type
jQuery.Promise
Get the current user's groups.

getId() → {number}static #

Get the current user's database id.

Not to be confused with id.

Source:

Returns:

Current user's id, or 0 if user is anonymous

Type
number
Get the current user's database id.

getName() → {string|null}static #

Get the current user's name.

Source:

Returns:

User name string or null if user is anonymous

Type
string | null
Get the current user's name.

getPageviewToken() → {string}static #

A sticky generateRandomSessionId for the current JS execution context, cached within this class (also known as a page view token).

Since:
  • 1.32
Source:

Returns:

80 bit integer in hex format, padded

Type
string

A sticky generateRandomSessionId for the current JS execution context, cached within this class (also known as a page view token).

getRegistration() → {boolean|null|Date}static #

Get date user registered, if available.

Source:

Returns:

False for anonymous users, null if data is unavailable, or Date for when the user registered.

Type
boolean | null | Date
Get date user registered, if available.

getRights(callback) → {jQuery.Promise}static #

Get the current user's rights.

Parameters:

Name Type Attributes Description
callback function optional
Source:

Returns:

Type
jQuery.Promise
Get the current user's rights.

id() → {string}static #

Get the current user's name or the session ID.

Not to be confused with getId.

Source:

Returns:

User name or random session ID

Type
string
Get the current user's name or the session ID.

isAnon() → {boolean}static #

Check whether the current user is anonymous.

Source:

Returns:

Type
boolean
Check whether the current user is anonymous.

isNamed() → {boolean}static #

Check whether the user is a normal non-temporary registered user.

Source:

Returns:

Type
boolean
Check whether the user is a normal non-temporary registered user.

isTemp() → {boolean}static #

Check whether the user is an autocreated temporary user.

Source:

Returns:

Type
boolean
Check whether the user is an autocreated temporary user.

sessionId() → {string}static #

Retrieve a random ID, generating it if needed.

This ID is shared across windows, tabs, and page views. It is persisted for the duration of one browser session (until the browser app is closed), unless the user evokes a "restore previous session" feature that some browsers have.

Note: Server-side code must never interpret or modify this value.

Source:

Returns:

Random session ID (20 hex characters)

Type
string
Retrieve a random ID, generating it if needed.