MediaWiki REL1_35
MediaWiki\Session\SessionBackend Class Reference

This is the actual workhorse for Session. More...

Collaboration diagram for MediaWiki\Session\SessionBackend:

Public Member Functions

 __construct (SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger, HookContainer $hookContainer, $lifetime)
 
 addData (array $newData)
 Add data to the session.
 
 canSetUser ()
 Indicate whether the session user info can be changed.
 
 delaySave ()
 Delay automatic saving while multiple updates are being made.
 
 deregisterSession ( $index)
 Deregister a Session.
 
 dirty ()
 Mark data as dirty.
 
 getAllowedUserRights ()
 Fetch the rights allowed the user when this session is active.
 
getData ()
 Fetch the session data array.
 
 getId ()
 Returns the session ID.
 
 getLoggedOutTimestamp ()
 Fetch the "logged out" timestamp.
 
 getProvider ()
 Fetch the SessionProvider for this session.
 
 getProviderMetadata ()
 Fetch provider metadata.
 
 getRequest ( $index)
 Returns the request associated with a Session.
 
 getSession (WebRequest $request)
 Return a new Session for this backend.
 
 getSessionId ()
 Fetch the SessionId object.
 
 getUser ()
 Returns the authenticated user for this session.
 
 isPersistent ()
 Indicate whether this session is persisted across requests.
 
 persist ()
 Make this session persisted across requests.
 
 renew ()
 Renew the session by resaving everything.
 
 resetId ()
 Changes the session ID.
 
 save ( $closing=false)
 Save the session.
 
 setForceHTTPS ( $force)
 Set whether HTTPS should be forced.
 
 setLoggedOutTimestamp ( $ts=null)
 Set the "logged out" timestamp.
 
 setProviderMetadata ( $metadata)
 Set provider metadata.
 
 setRememberUser ( $remember)
 Set whether the user should be remembered independently of the session ID.
 
 setUser ( $user)
 Set a new user for this session.
 
 shouldForceHTTPS ()
 Whether HTTPS should be forced.
 
 shouldRememberUser ()
 Indicate whether the user should be remembered independently of the session ID.
 
 shutdown ()
 Shut down a session.
 
 suggestLoginUsername ( $index)
 Get a suggested username for the login form.
 
 unpersist ()
 Make this session not persisted across requests.
 

Private Member Functions

 autosave ()
 Save the session, unless delayed.
 
 checkPHPSession ()
 For backwards compatibility, open the PHP session when the global session is persisted.
 

Private Attributes

bool $checkPHPSessionRecursionGuard = false
 
int $curIndex = 0
 
array null $data = null
 
bool $dataDirty = false
 
string $dataHash = null
 Used to detect subarray modifications.
 
int $delaySave = 0
 
int $expires = 0
 
bool $forceHTTPS = false
 
bool $forcePersist = false
 
HookRunner $hookRunner
 
SessionId $id
 
int $lifetime
 
int $loggedOut = 0
 
LoggerInterface $logger
 
bool $metaDirty = false
 
bool $persist = false
 
SessionProvider $provider
 provider
 
array null $providerMetadata = null
 provider-specified metadata
 
bool $remember = false
 
WebRequest[] $requests = []
 Session requests.
 
bool $shutdown = false
 
CachedBagOStuff $store
 
bool $usePhpSessionHandling = true
 
User $user
 

Detailed Description

This is the actual workhorse for Session.

Most code does not need to use this class, you want \MediaWiki\Session\Session. The exceptions are SessionProviders and SessionMetadata hook functions, which get an instance of this class rather than Session.

The reasons for this split are:

  1. A session can be attached to multiple requests, but we want the Session object to have some features that correspond to just one of those requests.
  2. We want reasonable garbage collection behavior, but we also want the SessionManager to hold a reference to every active session so it can be saved when the request ends.
Since
1.27

Definition at line 52 of file SessionBackend.php.

Constructor & Destructor Documentation

◆ __construct()

Member Function Documentation

◆ addData()

MediaWiki\Session\SessionBackend::addData ( array  $newData)

Add data to the session.

Overwrites any existing data under the same keys.

Parameters
array$newDataKey-value pairs to add to the session

Definition at line 556 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$data, MediaWiki\Session\SessionBackend\getData(), and wfGetAllCallers().

Referenced by MediaWiki\Session\CookieSessionProvider\persistSession().

◆ autosave()

◆ canSetUser()

MediaWiki\Session\SessionBackend::canSetUser ( )

Indicate whether the session user info can be changed.

Returns
bool

Definition at line 415 of file SessionBackend.php.

Referenced by MediaWiki\Session\SessionBackend\setUser().

◆ checkPHPSession()

MediaWiki\Session\SessionBackend::checkPHPSession ( )
private

For backwards compatibility, open the PHP session when the global session is persisted.

Definition at line 781 of file SessionBackend.php.

References MediaWiki\Session\SessionManager\getGlobalSession(), MediaWiki\Session\SessionBackend\getId(), and MediaWiki\Session\PHPSessionHandler\isEnabled().

Referenced by MediaWiki\Session\SessionBackend\save().

◆ delaySave()

MediaWiki\Session\SessionBackend::delaySave ( )

Delay automatic saving while multiple updates are being made.

Calls to save() will not be delayed.

Returns
\Wikimedia\ScopedCallback When this goes out of scope, a save will be triggered

Definition at line 621 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\delaySave(), and MediaWiki\Session\SessionBackend\save().

Referenced by MediaWiki\Session\SessionBackend\autosave(), and MediaWiki\Session\SessionBackend\delaySave().

◆ deregisterSession()

MediaWiki\Session\SessionBackend::deregisterSession (   $index)

Deregister a Session.

Definition at line 212 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\save(), and MediaWiki\Session\SessionBackend\shutdown().

◆ dirty()

MediaWiki\Session\SessionBackend::dirty ( )

Mark data as dirty.

Definition at line 576 of file SessionBackend.php.

References wfGetAllCallers().

◆ getAllowedUserRights()

MediaWiki\Session\SessionBackend::getAllowedUserRights ( )

Fetch the rights allowed the user when this session is active.

Returns
null|string[] Allowed user rights, or null to allow all.

Definition at line 407 of file SessionBackend.php.

◆ getData()

& MediaWiki\Session\SessionBackend::getData ( )

Fetch the session data array.

Note the caller is responsible for calling $this->dirty() if anything in the array is changed.

Definition at line 545 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$data.

Referenced by MediaWiki\Session\SessionBackend\addData().

◆ getId()

◆ getLoggedOutTimestamp()

MediaWiki\Session\SessionBackend::getLoggedOutTimestamp ( )

Fetch the "logged out" timestamp.

Returns
int

Definition at line 484 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$loggedOut.

Referenced by MediaWiki\Session\CookieSessionProvider\persistSession().

◆ getProvider()

MediaWiki\Session\SessionBackend::getProvider ( )

Fetch the SessionProvider for this session.

Returns
SessionProviderInterface

Definition at line 290 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$provider.

Referenced by MediaWiki\Session\BotPasswordSessionProvider\getAllowedUserRights(), and MediaWiki\Session\SessionProvider\getAllowedUserRights().

◆ getProviderMetadata()

MediaWiki\Session\SessionBackend::getProviderMetadata ( )

Fetch provider metadata.

Note
For use by SessionProvider subclasses only
Returns
array|null

Definition at line 511 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$providerMetadata.

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

◆ getRequest()

MediaWiki\Session\SessionBackend::getRequest (   $index)

Returns the request associated with a Session.

Parameters
int$indexSession index
Returns
WebRequest

Definition at line 388 of file SessionBackend.php.

◆ getSession()

MediaWiki\Session\SessionBackend::getSession ( WebRequest  $request)

Return a new Session for this backend.

Parameters
WebRequest$request
Returns
Session

Definition at line 200 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$curIndex.

◆ getSessionId()

MediaWiki\Session\SessionBackend::getSessionId ( )

◆ getUser()

MediaWiki\Session\SessionBackend::getUser ( )

◆ isPersistent()

MediaWiki\Session\SessionBackend::isPersistent ( )

Indicate whether this session is persisted across requests.

For example, if cookies are set.

Returns
bool

Definition at line 301 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$persist.

◆ persist()

MediaWiki\Session\SessionBackend::persist ( )

◆ renew()

MediaWiki\Session\SessionBackend::renew ( )

Renew the session by resaving everything.

Resets the TTL in the backend store if the session is near expiring, and re-persists the session to any active WebRequests if persistent.

Definition at line 592 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\autosave(), MediaWiki\Session\SessionBackend\persist(), and wfGetAllCallers().

Referenced by MediaWiki\Session\SessionBackend\persist().

◆ resetId()

MediaWiki\Session\SessionBackend::resetId ( )

Changes the session ID.

Returns
string New ID (might be the same as the old)

Definition at line 250 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$id, MediaWiki\Session\SessionBackend\autosave(), and MediaWiki\Session\PHPSessionHandler\isEnabled().

◆ save()

◆ setForceHTTPS()

MediaWiki\Session\SessionBackend::setForceHTTPS (   $force)

Set whether HTTPS should be forced.

Parameters
bool$force

Definition at line 467 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\autosave().

◆ setLoggedOutTimestamp()

MediaWiki\Session\SessionBackend::setLoggedOutTimestamp (   $ts = null)

Set the "logged out" timestamp.

Parameters
int | null$ts

Definition at line 492 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\autosave().

◆ setProviderMetadata()

MediaWiki\Session\SessionBackend::setProviderMetadata (   $metadata)

Set provider metadata.

Note
For use by SessionProvider subclasses only
Parameters
array | null$metadata

Definition at line 520 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\autosave().

◆ setRememberUser()

MediaWiki\Session\SessionBackend::setRememberUser (   $remember)

Set whether the user should be remembered independently of the session ID.

Parameters
bool$remember

Definition at line 370 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$remember, and MediaWiki\Session\SessionBackend\autosave().

◆ setUser()

MediaWiki\Session\SessionBackend::setUser (   $user)

Set a new user for this session.

Note
This should only be called when the user has been authenticated via a login process
Parameters
User$userUser to set on the session. This may become a "UserValue" in the future, or User may be refactored into such.

Definition at line 426 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$user, MediaWiki\Session\SessionBackend\autosave(), and MediaWiki\Session\SessionBackend\canSetUser().

◆ shouldForceHTTPS()

MediaWiki\Session\SessionBackend::shouldForceHTTPS ( )

◆ shouldRememberUser()

MediaWiki\Session\SessionBackend::shouldRememberUser ( )

Indicate whether the user should be remembered independently of the session ID.

Returns
bool

Definition at line 361 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\$remember.

Referenced by MediaWiki\Session\CookieSessionProvider\persistSession(), and MediaWiki\Session\CookieSessionProvider\setForceHTTPSCookie().

◆ shutdown()

MediaWiki\Session\SessionBackend::shutdown ( )

◆ suggestLoginUsername()

MediaWiki\Session\SessionBackend::suggestLoginUsername (   $index)

Get a suggested username for the login form.

Parameters
int$indexSession index
Returns
string|null

Definition at line 448 of file SessionBackend.php.

◆ unpersist()

MediaWiki\Session\SessionBackend::unpersist ( )

Member Data Documentation

◆ $checkPHPSessionRecursionGuard

bool MediaWiki\Session\SessionBackend::$checkPHPSessionRecursionGuard = false
private

Definition at line 119 of file SessionBackend.php.

◆ $curIndex

int MediaWiki\Session\SessionBackend::$curIndex = 0
private

Definition at line 96 of file SessionBackend.php.

Referenced by MediaWiki\Session\SessionBackend\getSession().

◆ $data

array null MediaWiki\Session\SessionBackend::$data = null
private

◆ $dataDirty

bool MediaWiki\Session\SessionBackend::$dataDirty = false
private

Definition at line 75 of file SessionBackend.php.

◆ $dataHash

string MediaWiki\Session\SessionBackend::$dataHash = null
private

Used to detect subarray modifications.

Definition at line 78 of file SessionBackend.php.

◆ $delaySave

int MediaWiki\Session\SessionBackend::$delaySave = 0
private

Definition at line 114 of file SessionBackend.php.

◆ $expires

int MediaWiki\Session\SessionBackend::$expires = 0
private

Definition at line 108 of file SessionBackend.php.

◆ $forceHTTPS

bool MediaWiki\Session\SessionBackend::$forceHTTPS = false
private

◆ $forcePersist

bool MediaWiki\Session\SessionBackend::$forcePersist = false
private

Definition at line 69 of file SessionBackend.php.

◆ $hookRunner

HookRunner MediaWiki\Session\SessionBackend::$hookRunner
private

Definition at line 87 of file SessionBackend.php.

◆ $id

◆ $lifetime

int MediaWiki\Session\SessionBackend::$lifetime
private

◆ $loggedOut

int MediaWiki\Session\SessionBackend::$loggedOut = 0
private

◆ $logger

LoggerInterface MediaWiki\Session\SessionBackend::$logger
private

Definition at line 84 of file SessionBackend.php.

Referenced by MediaWiki\Session\SessionBackend\__construct().

◆ $metaDirty

bool MediaWiki\Session\SessionBackend::$metaDirty = false
private

Definition at line 72 of file SessionBackend.php.

◆ $persist

bool MediaWiki\Session\SessionBackend::$persist = false
private

◆ $provider

SessionProvider MediaWiki\Session\SessionBackend::$provider
private

provider

Definition at line 102 of file SessionBackend.php.

Referenced by MediaWiki\Session\SessionBackend\getProvider().

◆ $providerMetadata

array null MediaWiki\Session\SessionBackend::$providerMetadata = null
private

provider-specified metadata

Definition at line 105 of file SessionBackend.php.

Referenced by MediaWiki\Session\SessionBackend\getProviderMetadata().

◆ $remember

bool MediaWiki\Session\SessionBackend::$remember = false
private

◆ $requests

WebRequest [] MediaWiki\Session\SessionBackend::$requests = []
private

Session requests.

Definition at line 99 of file SessionBackend.php.

◆ $shutdown

bool MediaWiki\Session\SessionBackend::$shutdown = false
private

Definition at line 122 of file SessionBackend.php.

◆ $store

CachedBagOStuff MediaWiki\Session\SessionBackend::$store
private

Definition at line 81 of file SessionBackend.php.

Referenced by MediaWiki\Session\SessionBackend\__construct().

◆ $usePhpSessionHandling

bool MediaWiki\Session\SessionBackend::$usePhpSessionHandling = true
private

Definition at line 117 of file SessionBackend.php.

◆ $user

User MediaWiki\Session\SessionBackend::$user
private

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