namespace MediaWiki\Session;
-use BagOStuff;
+use CachedBagOStuff;
use Psr\Log\LoggerInterface;
use User;
use WebRequest;
/** @var string Used to detect subarray modifications */
private $dataHash = null;
- /** @var BagOStuff */
+ /** @var CachedBagOStuff */
private $store;
/** @var LoggerInterface */
/**
* @param SessionId $id Session ID object
* @param SessionInfo $info Session info to populate from
- * @param BagOStuff $store Backend data store
+ * @param CachedBagOStuff $store Backend data store
* @param LoggerInterface $logger
* @param int $lifetime Session data lifetime in seconds
*/
public function __construct(
- SessionId $id, SessionInfo $info, BagOStuff $store, LoggerInterface $logger, $lifetime
+ SessionId $id, SessionInfo $info, CachedBagOStuff $store, LoggerInterface $logger, $lifetime
) {
$phpSessionHandling = \RequestContext::getMain()->getConfig()->get( 'PHPSessionHandling' );
$this->usePhpSessionHandling = $phpSessionHandling !== 'disable';
if ( !$this->persist ) {
$this->persist = true;
$this->forcePersist = true;
+ $this->metaDirty = true;
$this->logger->debug( "SessionBackend $this->id force-persist due to persist()" );
$this->autosave();
} else {
/**
* Fetch provider metadata
* @protected For use by SessionProvider subclasses only
- * @return mixed
+ * @return array|null
*/
public function getProviderMetadata() {
return $this->providerMetadata;
}
+ /**
+ * Set provider metadata
+ * @protected For use by SessionProvider subclasses only
+ * @param array|null $metadata
+ */
+ public function setProviderMetadata( $metadata ) {
+ if ( $metadata !== null && !is_array( $metadata ) ) {
+ throw new \InvalidArgumentException( '$metadata must be an array or null' );
+ }
+ if ( $this->providerMetadata !== $metadata ) {
+ $this->providerMetadata = $metadata;
+ $this->metaDirty = true;
+ $this->logger->debug(
+ "SessionBackend $this->id metadata dirty due to provider metadata change"
+ );
+ $this->autosave();
+ }
+ }
+
/**
* Fetch the session data array
*
// Ensure the user has a token
// @codeCoverageIgnoreStart
$anon = $this->user->isAnon();
- if ( !$anon && !$this->user->getToken() ) {
+ if ( !$anon && !$this->user->getToken( false ) ) {
$this->logger->debug(
"SessionBackend $this->id creating token for user {$this->user} on save"
);
'provider' => (string)$this->provider,
'providerMetadata' => $this->providerMetadata,
'userId' => $anon ? 0 : $this->user->getId(),
- 'userName' => $anon ? null : $this->user->getName(),
+ 'userName' => User::isValidUserName( $this->user->getName() ) ? $this->user->getName() : null,
'userToken' => $anon ? null : $this->user->getToken(),
'remember' => !$anon && $this->remember,
'forceHTTPS' => $this->forceHTTPS,
'expires' => time() + $this->lifetime,
'loggedOut' => $this->loggedOut,
+ 'persisted' => $this->persist,
);
\Hooks::run( 'SessionMetadata', array( $this, &$metadata, $this->requests ) );
'data' => $this->data,
'metadata' => $metadata,
),
- $metadata['expires']
+ $metadata['expires'],
+ $this->persist ? 0 : CachedBagOStuff::WRITE_CACHE_ONLY
);
$this->metaDirty = false;