MediaWiki master
MediaWiki\Session\SessionBackend Class Reference

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

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.
 
 getRestrictions ()
 Fetch any restrictions imposed on logins or actions when this session is active.
 
 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)
 
 setProviderMetadata ( $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.
 

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 56 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 588 of file SessionBackend.php.

References wfGetAllCallers().

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

◆ canSetUser()

MediaWiki\Session\SessionBackend::canSetUser ( )

Indicate whether the session user info can be changed.

Returns
bool

Definition at line 449 of file SessionBackend.php.

◆ 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 654 of file SessionBackend.php.

◆ deregisterSession()

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

Deregister a Session.

Access: internal
For use by \MediaWiki\Session\Session::__destruct() only
Parameters
int$index

Definition at line 237 of file SessionBackend.php.

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

◆ dirty()

MediaWiki\Session\SessionBackend::dirty ( )

Mark data as dirty.

Access: internal
For use by \MediaWiki\Session\Session only.

Definition at line 608 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 432 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.

Access: internal
For use by \MediaWiki\Session\Session only.
Returns
array

Definition at line 577 of file SessionBackend.php.

◆ getId()

MediaWiki\Session\SessionBackend::getId ( )

◆ getLoggedOutTimestamp()

MediaWiki\Session\SessionBackend::getLoggedOutTimestamp ( )

Fetch the "logged out" timestamp.

Returns
int

Definition at line 518 of file SessionBackend.php.

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

◆ getProvider()

MediaWiki\Session\SessionBackend::getProvider ( )

Fetch the SessionProvider for this session.

Returns
SessionProviderInterface

Definition at line 315 of file SessionBackend.php.

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 544 of file SessionBackend.php.

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 413 of file SessionBackend.php.

◆ getRestrictions()

MediaWiki\Session\SessionBackend::getRestrictions ( )

Fetch any restrictions imposed on logins or actions when this session is active.

Returns
MWRestrictions|null

Definition at line 441 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 225 of file SessionBackend.php.

◆ getSessionId()

MediaWiki\Session\SessionBackend::getSessionId ( )

Fetch the SessionId object.

Access: internal
For internal use by WebRequest
Returns
SessionId

Definition at line 267 of file SessionBackend.php.

Referenced by MediaWiki\Session\SessionManager\changeBackendId(), and MediaWiki\Session\SessionManager\deregisterSessionBackend().

◆ getUser()

MediaWiki\Session\SessionBackend::getUser ( )

Returns the authenticated user for this session.

Returns
User

Definition at line 424 of file SessionBackend.php.

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

◆ isPersistent()

MediaWiki\Session\SessionBackend::isPersistent ( )

Indicate whether this session is persisted across requests.

For example, if cookies are set.

Returns
bool

Definition at line 326 of file SessionBackend.php.

◆ persist()

MediaWiki\Session\SessionBackend::persist ( )

Make this session persisted across requests.

If the session is already persistent, equivalent to calling $this->renew().

Definition at line 336 of file SessionBackend.php.

References MediaWiki\Session\SessionBackend\persist(), and MediaWiki\Session\SessionBackend\renew().

Referenced by MediaWiki\Session\SessionBackend\__construct(), MediaWiki\Session\SessionBackend\persist(), and MediaWiki\Session\SessionBackend\unpersist().

◆ 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 624 of file SessionBackend.php.

References 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 275 of file SessionBackend.php.

References MediaWiki\Session\PHPSessionHandler\isEnabled().

◆ save()

MediaWiki\Session\SessionBackend::save ( $closing = false)

Save the session.

Update both the backend data and the associated WebRequest(s) to reflect the state of the SessionBackend. This might include persisting or unpersisting the session.

Parameters
bool$closingWhether the session is being closed

Definition at line 683 of file SessionBackend.php.

References MediaWiki\User\User\saveSettings().

Referenced by MediaWiki\Session\SessionBackend\deregisterSession(), and MediaWiki\Session\SessionBackend\shutdown().

◆ setForceHTTPS()

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

Set whether HTTPS should be forced.

Parameters
bool$force

Definition at line 501 of file SessionBackend.php.

◆ setLoggedOutTimestamp()

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

Definition at line 525 of file SessionBackend.php.

◆ setProviderMetadata()

MediaWiki\Session\SessionBackend::setProviderMetadata ( $metadata)
Note
For use by SessionProvider subclasses only
Parameters
array | null$metadata

Definition at line 552 of file SessionBackend.php.

◆ setRememberUser()

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

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

Parameters
bool$remember

Definition at line 395 of file SessionBackend.php.

◆ 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 460 of file SessionBackend.php.

◆ 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 386 of file SessionBackend.php.

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

◆ shutdown()

MediaWiki\Session\SessionBackend::shutdown ( )

Shut down a session.

Access: internal
For use by \MediaWiki\Session\SessionManager::shutdown() only

Definition at line 249 of file SessionBackend.php.

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

Referenced by MediaWiki\Session\SessionBackend\deregisterSession(), and 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 482 of file SessionBackend.php.

◆ unpersist()

MediaWiki\Session\SessionBackend::unpersist ( )

Make this session not persisted across requests.

Definition at line 355 of file SessionBackend.php.

References MediaWiki\Session\PHPSessionHandler\isEnabled(), and MediaWiki\Session\SessionBackend\persist().


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