MediaWiki  1.34.0
MediaWiki\Session\UserInfo Class Reference

Object holding data about a session's user. More...

Collaboration diagram for MediaWiki\Session\UserInfo:

Public Member Functions

 __toString ()
 
 getId ()
 Return the user ID. More...
 
 getName ()
 Return the user name. More...
 
 getToken ()
 Return the user token. More...
 
 getUser ()
 Return a User object. More...
 
 isAnon ()
 Return whether this is an anonymous user. More...
 
 isVerified ()
 Return whether this represents a verified user. More...
 
 verified ()
 Return a verified version of this object. More...
 

Static Public Member Functions

static newAnonymous ()
 Create an instance for an anonymous (i.e. More...
 
static newFromId ( $id, $verified=false)
 Create an instance for a logged-in user by ID. More...
 
static newFromName ( $name, $verified=false)
 Create an instance for a logged-in user by name. More...
 
static newFromUser (User $user, $verified=false)
 Create an instance from an existing User object. More...
 

Private Member Functions

 __construct (User $user=null, $verified)
 

Private Attributes

User null $user = null
 
bool $verified = false
 

Detailed Description

Object holding data about a session's user.

In general, this class exists for two purposes:

  • User doesn't distinguish between "anonymous user" and "non-anonymous user that doesn't exist locally", while we do need to.
  • We also need the "verified" property described below; tracking it via another data item to SessionInfo's constructor makes things much more confusing.

A UserInfo may be "verified". This indicates that the creator knows that the request really comes from that user, whether that's by validating OAuth credentials, SSL client certificates, or by having both the user ID and token available from cookies.

An "unverified" UserInfo should be used when it's not possible to authenticate the user, e.g. the user ID cookie is set but the user Token cookie isn't. If the Token is available but doesn't match, don't return a UserInfo at all.

Since
1.27

Definition at line 51 of file UserInfo.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Session\UserInfo::__construct ( User  $user = null,
  $verified 
)
private

Member Function Documentation

◆ __toString()

MediaWiki\Session\UserInfo::__toString ( )

◆ getId()

MediaWiki\Session\UserInfo::getId ( )

Return the user ID.

Note
Do not use this to test for anonymous users!
Returns
int

Definition at line 142 of file UserInfo.php.

Referenced by MediaWiki\Session\UserInfo\__toString().

◆ getName()

MediaWiki\Session\UserInfo::getName ( )

Return the user name.

Returns
string|null

Definition at line 150 of file UserInfo.php.

Referenced by MediaWiki\Session\UserInfo\__toString().

◆ getToken()

MediaWiki\Session\UserInfo::getToken ( )

Return the user token.

Returns
string

Definition at line 158 of file UserInfo.php.

◆ getUser()

MediaWiki\Session\UserInfo::getUser ( )

Return a User object.

Returns
User

Definition at line 166 of file UserInfo.php.

References MediaWiki\Session\UserInfo\$user.

◆ isAnon()

MediaWiki\Session\UserInfo::isAnon ( )

Return whether this is an anonymous user.

Returns
bool

Definition at line 125 of file UserInfo.php.

◆ isVerified()

MediaWiki\Session\UserInfo::isVerified ( )

Return whether this represents a verified user.

Returns
bool

Definition at line 133 of file UserInfo.php.

References MediaWiki\Session\UserInfo\$verified.

◆ newAnonymous()

static MediaWiki\Session\UserInfo::newAnonymous ( )
static

Create an instance for an anonymous (i.e.

not logged in) user

Logged-out users are always "verified".

Returns
UserInfo

Definition at line 75 of file UserInfo.php.

References true.

Referenced by MediaWiki\Session\SessionManager\loadSessionInfoFromStore(), and MediaWiki\Session\CookieSessionProvider\provideSessionInfo().

◆ newFromId()

static MediaWiki\Session\UserInfo::newFromId (   $id,
  $verified = false 
)
static

Create an instance for a logged-in user by ID.

Parameters
int$idUser ID
bool$verifiedTrue if the user is verified
Returns
UserInfo

Definition at line 85 of file UserInfo.php.

References MediaWiki\Session\UserInfo\$user, MediaWiki\Session\UserInfo\$verified, User\isAnon(), User\load(), and User\newFromId().

Referenced by MediaWiki\Session\SessionManager\loadSessionInfoFromStore(), and MediaWiki\Session\CookieSessionProvider\provideSessionInfo().

◆ newFromName()

static MediaWiki\Session\UserInfo::newFromName (   $name,
  $verified = false 
)
static

Create an instance for a logged-in user by name.

Parameters
string$nameUser name (need not exist locally)
bool$verifiedTrue if the user is verified
Returns
UserInfo

Definition at line 103 of file UserInfo.php.

References MediaWiki\Session\UserInfo\$user, MediaWiki\Session\UserInfo\$verified, and User\newFromName().

Referenced by MediaWiki\Session\SessionManager\loadSessionInfoFromStore().

◆ newFromUser()

static MediaWiki\Session\UserInfo::newFromUser ( User  $user,
  $verified = false 
)
static

Create an instance from an existing User object.

Parameters
User$user(need not exist locally)
bool$verifiedTrue if the user is verified
Returns
UserInfo

Definition at line 117 of file UserInfo.php.

References MediaWiki\Session\UserInfo\$user, and MediaWiki\Session\UserInfo\$verified.

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

◆ verified()

MediaWiki\Session\UserInfo::verified ( )

Return a verified version of this object.

Returns
UserInfo

Definition at line 174 of file UserInfo.php.

References MediaWiki\Session\UserInfo\$user, and true.

Referenced by MediaWiki\Session\UserInfo\__construct(), and MediaWiki\Session\UserInfo\__toString().

Member Data Documentation

◆ $user

◆ $verified


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