MediaWiki master
MediaWiki\User\BotPassword Class Reference

Utility class for bot passwords. More...

Public Member Functions

 __construct ( $row, $isSaved, $flags=IDBAccessObject::READ_NORMAL)
 
 delete ()
 Delete the BotPassword from the database.
 
 getAppId ()
 
 getGrants ()
 
 getRestrictions ()
 
 getToken ()
 
 getUserCentralId ()
 Get the central user ID.
 
 isInvalid ()
 Whether the password is currently invalid.
 
 isSaved ()
 Indicate whether this is known to be saved.
 
 save ( $operation, Password $password=null)
 Save the BotPassword to the database.
 

Static Public Member Functions

static canonicalizeLoginData ( $username, $password)
 There are two ways to login with a bot password: "username@appId", "password" and "username", "appId@password".
 
static generatePassword ( $config)
 Returns a (raw, unhashed) random password string.
 
static getPrimaryDatabase ()
 
static getReplicaDatabase ()
 
static getSeparator ()
 Get the separator for combined user name + app ID.
 
static invalidateAllPasswordsForCentralId ( $centralId)
 Invalidate all passwords for a user, by central ID.
 
static invalidateAllPasswordsForUser ( $username)
 Invalidate all passwords for a user, by name.
 
static login ( $username, $password, WebRequest $request)
 Try to log the user in.
 
static newFromCentralId ( $centralId, $appId, $flags=IDBAccessObject::READ_NORMAL)
 Load a BotPassword from the database.
 
static newFromUser (UserIdentity $userIdentity, $appId, $flags=IDBAccessObject::READ_NORMAL)
 Load a BotPassword from the database.
 
static newUnsaved (array $data, $flags=IDBAccessObject::READ_NORMAL)
 Create an unsaved BotPassword.
 
static removeAllPasswordsForCentralId ( $centralId)
 Remove all passwords for a user, by central ID.
 
static removeAllPasswordsForUser ( $username)
 Remove all passwords for a user, by name.
 

Public Attributes

const APPID_MAXLENGTH = 32
 
const GRANTS_MAXLENGTH = 65535
 Maximum length of the json representation of grants.
 
const PASSWORD_MINLENGTH = 32
 Minimum length for a bot password.
 
const RESTRICTIONS_MAXLENGTH = 65535
 Maximum length of the json representation of restrictions.
 

Detailed Description

Utility class for bot passwords.

Since
1.27

Definition at line 50 of file BotPassword.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\BotPassword::__construct ( $row,
$isSaved,
$flags = IDBAccessObject::READ_NORMAL )
Access: internal
only public for construction in BotPasswordStore
Parameters
stdClass$rowbot_passwords database row
bool$isSavedWhether the bot password was read from the database
int$flagsIDBAccessObject read flags

Definition at line 99 of file BotPassword.php.

References MediaWiki\User\BotPassword\isSaved().

Member Function Documentation

◆ canonicalizeLoginData()

static MediaWiki\User\BotPassword::canonicalizeLoginData ( $username,
$password )
static

There are two ways to login with a bot password: "username@appId", "password" and "username", "appId@password".

Transform it so it is always in the first form. Returns [bot username, bot password]. If this cannot be a bot password login just return false.

Parameters
string$username
string$password
Returns
string[]|false

Definition at line 399 of file BotPassword.php.

◆ delete()

MediaWiki\User\BotPassword::delete ( )

Delete the BotPassword from the database.

Returns
bool Success

Definition at line 295 of file BotPassword.php.

◆ generatePassword()

static MediaWiki\User\BotPassword::generatePassword ( $config)
static

Returns a (raw, unhashed) random password string.

Parameters
Config$config
Returns
string

Definition at line 386 of file BotPassword.php.

◆ getAppId()

MediaWiki\User\BotPassword::getAppId ( )
Returns
string

Definition at line 185 of file BotPassword.php.

Referenced by MediaWiki\Session\BotPasswordSessionProvider\newSessionForRequest().

◆ getGrants()

MediaWiki\User\BotPassword::getGrants ( )
Returns
string[]

Definition at line 206 of file BotPassword.php.

Referenced by MediaWiki\Session\BotPasswordSessionProvider\newSessionForRequest().

◆ getPrimaryDatabase()

static MediaWiki\User\BotPassword::getPrimaryDatabase ( )
static

Definition at line 116 of file BotPassword.php.

◆ getReplicaDatabase()

static MediaWiki\User\BotPassword::getReplicaDatabase ( )
static

Definition at line 110 of file BotPassword.php.

◆ getRestrictions()

MediaWiki\User\BotPassword::getRestrictions ( )

◆ getSeparator()

static MediaWiki\User\BotPassword::getSeparator ( )
static

Get the separator for combined user name + app ID.

Returns
string

Definition at line 214 of file BotPassword.php.

◆ getToken()

MediaWiki\User\BotPassword::getToken ( )
Returns
string

Definition at line 192 of file BotPassword.php.

Referenced by MediaWiki\Session\BotPasswordSessionProvider\newSessionForRequest().

◆ getUserCentralId()

MediaWiki\User\BotPassword::getUserCentralId ( )

Get the central user ID.

Returns
int

Definition at line 178 of file BotPassword.php.

Referenced by MediaWiki\Session\BotPasswordSessionProvider\newSessionForRequest().

◆ invalidateAllPasswordsForCentralId()

static MediaWiki\User\BotPassword::invalidateAllPasswordsForCentralId ( $centralId)
static

Invalidate all passwords for a user, by central ID.

Deprecated
since 1.37
Parameters
int$centralId
Returns
bool Whether any passwords were invalidated

Definition at line 325 of file BotPassword.php.

References wfDeprecated().

◆ invalidateAllPasswordsForUser()

static MediaWiki\User\BotPassword::invalidateAllPasswordsForUser ( $username)
static

Invalidate all passwords for a user, by name.

Parameters
string$username
Returns
bool Whether any passwords were invalidated

Definition at line 311 of file BotPassword.php.

◆ isInvalid()

MediaWiki\User\BotPassword::isInvalid ( )

Whether the password is currently invalid.

Since
1.32
Returns
bool

Definition at line 253 of file BotPassword.php.

◆ isSaved()

MediaWiki\User\BotPassword::isSaved ( )

Indicate whether this is known to be saved.

Returns
bool

Definition at line 170 of file BotPassword.php.

Referenced by MediaWiki\User\BotPassword\__construct().

◆ login()

static MediaWiki\User\BotPassword::login ( $username,
$password,
WebRequest $request )
static

Try to log the user in.

Parameters
string$usernameCombined user name and app ID
string$passwordSupplied password
WebRequest$request
Returns
Status On success, the good status's value is the new Session object

Definition at line 425 of file BotPassword.php.

References MediaWiki\Request\WebRequest\getIP(), MediaWiki\Request\WebRequest\getSession(), and wfMessage().

◆ newFromCentralId()

static MediaWiki\User\BotPassword::newFromCentralId ( $centralId,
$appId,
$flags = IDBAccessObject::READ_NORMAL )
static

Load a BotPassword from the database.

Parameters
int$centralIdfrom CentralIdLookup
string$appId
int$flagsIDBAccessObject read flags
Returns
BotPassword|null

Definition at line 142 of file BotPassword.php.

◆ newFromUser()

static MediaWiki\User\BotPassword::newFromUser ( UserIdentity $userIdentity,
$appId,
$flags = IDBAccessObject::READ_NORMAL )
static

Load a BotPassword from the database.

Parameters
UserIdentity$userIdentity
string$appId
int$flagsIDBAccessObject read flags
Returns
BotPassword|null

Definition at line 129 of file BotPassword.php.

◆ newUnsaved()

static MediaWiki\User\BotPassword::newUnsaved ( array $data,
$flags = IDBAccessObject::READ_NORMAL )
static

Create an unsaved BotPassword.

Parameters
array$dataData to use to create the bot password. Keys are:
  • user: (UserIdentity) UserIdentity to create the password for. Overrides username and centralId.
  • username: (string) Username to create the password for. Overrides centralId.
  • centralId: (int) User central ID to create the password for.
  • appId: (string, required) App ID for the password.
  • restrictions: (MWRestrictions, optional) Restrictions.
  • grants: (string[], optional) Grants.
int$flagsIDBAccessObject read flags
Returns
BotPassword|null

Definition at line 160 of file BotPassword.php.

◆ removeAllPasswordsForCentralId()

static MediaWiki\User\BotPassword::removeAllPasswordsForCentralId ( $centralId)
static

Remove all passwords for a user, by central ID.

Deprecated
since 1.37
Parameters
int$centralId
Returns
bool Whether any passwords were removed

Definition at line 363 of file BotPassword.php.

References wfDeprecated().

◆ removeAllPasswordsForUser()

static MediaWiki\User\BotPassword::removeAllPasswordsForUser ( $username)
static

Remove all passwords for a user, by name.

Parameters
string$username
Returns
bool Whether any passwords were removed

Definition at line 349 of file BotPassword.php.

◆ save()

MediaWiki\User\BotPassword::save ( $operation,
Password $password = null )

Save the BotPassword to the database.

Parameters
string$operation'update' or 'insert'
Password | null$passwordPassword to set.
Returns
Status
Exceptions
UnexpectedValueException

Definition at line 264 of file BotPassword.php.

Member Data Documentation

◆ APPID_MAXLENGTH

const MediaWiki\User\BotPassword::APPID_MAXLENGTH = 32

Definition at line 52 of file BotPassword.php.

◆ GRANTS_MAXLENGTH

const MediaWiki\User\BotPassword::GRANTS_MAXLENGTH = 65535

Maximum length of the json representation of grants.

Since
1.36

Definition at line 69 of file BotPassword.php.

◆ PASSWORD_MINLENGTH

const MediaWiki\User\BotPassword::PASSWORD_MINLENGTH = 32

Minimum length for a bot password.

Definition at line 57 of file BotPassword.php.

◆ RESTRICTIONS_MAXLENGTH

const MediaWiki\User\BotPassword::RESTRICTIONS_MAXLENGTH = 65535

Maximum length of the json representation of restrictions.

Since
1.36

Definition at line 63 of file BotPassword.php.


The documentation for this class was generated from the following file: