27use Psr\Log\LoggerInterface;
109 $phpSessionHandling = \RequestContext::getMain()->getConfig()->get(
'PHPSessionHandling' );
110 $this->usePhpSessionHandling = $phpSessionHandling !==
'disable';
113 throw new \InvalidArgumentException(
114 "Refusing to create session for unverified user {$info->getUserInfo()}"
118 throw new \InvalidArgumentException(
'Cannot create session without a provider' );
121 throw new \InvalidArgumentException(
'SessionId and SessionInfo don\'t match' );
136 if ( !is_array(
$blob ) ||
137 !isset(
$blob[
'metadata'] ) || !is_array(
$blob[
'metadata'] ) ||
138 !isset(
$blob[
'data'] ) || !is_array(
$blob[
'data'] )
141 $this->dataDirty =
true;
142 $this->metaDirty =
true;
143 $this->logger->debug(
144 'SessionBackend "{session}" is unsaved, marking dirty in constructor',
146 'session' => $this->
id,
149 $this->data =
$blob[
'data'];
150 if ( isset(
$blob[
'metadata'][
'loggedOut'] ) ) {
151 $this->loggedOut = (int)
$blob[
'metadata'][
'loggedOut'];
153 if ( isset(
$blob[
'metadata'][
'expires'] ) ) {
154 $this->expires = (int)
$blob[
'metadata'][
'expires'];
156 $this->metaDirty =
true;
157 $this->logger->debug(
158 'SessionBackend "{session}" metadata dirty due to missing expiration timestamp',
160 'session' => $this->
id,
164 $this->dataHash = md5(
serialize( $this->data ) );
175 $session =
new Session( $this, $index, $this->logger );
185 unset( $this->requests[$index] );
186 if ( !$this->
shutdown && !count( $this->requests ) ) {
188 $this->provider->getManager()->deregisterSessionBackend( $this );
223 if ( $this->provider->persistsSessionId() ) {
224 $oldId = (
string)$this->
id;
225 $restart = $this->usePhpSessionHandling && $oldId === session_id() &&
231 session_write_close();
234 $this->provider->getManager()->changeBackendId( $this );
235 $this->provider->sessionIdWasReset( $this, $oldId );
236 $this->metaDirty =
true;
237 $this->logger->debug(
238 'SessionBackend "{session}" metadata dirty due to ID reset (formerly "{oldId}")',
240 'session' => $this->
id,
245 session_id( (
string)$this->
id );
246 \MediaWiki\quietCall(
'session_start' );
252 $this->store->delete( $this->store->makeKey(
'MWSession', $oldId ) );
284 $this->forcePersist =
true;
285 $this->metaDirty =
true;
286 $this->logger->debug(
287 'SessionBackend "{session}" force-persist due to persist()',
289 'session' => $this->
id,
304 session_id() === (
string)$this->
id
306 $this->logger->debug(
307 'SessionBackend "{session}" Closing PHP session for unpersist',
308 [
'session' => $this->
id ]
310 session_write_close();
315 $this->forcePersist =
true;
316 $this->metaDirty =
true;
320 $this->store->delete( $this->store->makeKey(
'MWSession', (
string)$this->id ) );
341 if ( $this->remember !== (
bool)
$remember ) {
343 $this->metaDirty =
true;
344 $this->logger->debug(
345 'SessionBackend "{session}" metadata dirty due to remember-user change',
347 'session' => $this->
id,
359 if ( !isset( $this->requests[$index] ) ) {
360 throw new \InvalidArgumentException(
'Invalid session index' );
362 return $this->requests[$index];
378 return $this->provider->getAllowedUserRights( $this );
386 return $this->provider->canChangeUser();
398 throw new \BadMethodCallException(
399 'Cannot set user on this session; check $session->canSetUser() first'
404 $this->metaDirty =
true;
405 $this->logger->debug(
406 'SessionBackend "{session}" metadata dirty due to user change',
408 'session' => $this->
id,
419 if ( !isset( $this->requests[$index] ) ) {
420 throw new \InvalidArgumentException(
'Invalid session index' );
422 return $this->provider->suggestLoginUsername( $this->requests[$index] );
438 if ( $this->forceHTTPS !== (
bool)$force ) {
439 $this->forceHTTPS = (bool)$force;
440 $this->metaDirty =
true;
441 $this->logger->debug(
442 'SessionBackend "{session}" metadata dirty due to force-HTTPS change',
444 'session' => $this->
id,
464 if ( $this->loggedOut !== $ts ) {
465 $this->loggedOut = $ts;
466 $this->metaDirty =
true;
467 $this->logger->debug(
468 'SessionBackend "{session}" metadata dirty due to logged-out-timestamp change',
470 'session' => $this->
id,
491 if ( $metadata !==
null && !is_array( $metadata ) ) {
492 throw new \InvalidArgumentException(
'$metadata must be an array or null' );
494 if ( $this->providerMetadata !== $metadata ) {
495 $this->providerMetadata = $metadata;
496 $this->metaDirty =
true;
497 $this->logger->debug(
498 'SessionBackend "{session}" metadata dirty due to provider metadata change',
500 'session' => $this->
id,
528 foreach ( $newData as $key =>
$value ) {
531 $this->dataDirty =
true;
532 $this->logger->debug(
533 'SessionBackend "{session}" data dirty due to addData(): {callers}',
535 'session' => $this->
id,
547 $this->dataDirty =
true;
548 $this->logger->debug(
549 'SessionBackend "{session}" data dirty due to dirty(): {callers}',
551 'session' => $this->
id,
563 if ( time() + $this->lifetime / 2 > $this->expires ) {
564 $this->metaDirty =
true;
565 $this->logger->debug(
566 'SessionBackend "{callers}" metadata dirty for renew(): {callers}',
568 'session' => $this->
id,
572 $this->forcePersist =
true;
573 $this->logger->debug(
574 'SessionBackend "{session}" force-persist for renew(): {callers}',
576 'session' => $this->
id,
593 return new \Wikimedia\ScopedCallback(
function () {
620 public function save( $closing =
false ) {
621 $anon = $this->user->isAnon();
623 if ( !$anon && $this->provider->getManager()->isUserSessionPrevented( $this->user->getName() ) ) {
624 $this->logger->debug(
625 'SessionBackend "{session}" not saving, user {user} was ' .
626 'passed to SessionManager::preventSessionsForUser',
628 'session' => $this->
id,
629 'user' => $this->user,
636 if ( !$anon && !$this->user->getToken(
false ) ) {
637 $this->logger->debug(
638 'SessionBackend "{session}" creating token for user {user} on save',
640 'session' => $this->
id,
641 'user' => $this->user,
643 $this->user->setToken();
647 \DeferredUpdates::addCallableUpdate(
function () use ( $user ) {
648 $user->saveSettings();
651 $this->metaDirty =
true;
655 if ( !$this->metaDirty && !$this->dataDirty &&
656 $this->dataHash !== md5(
serialize( $this->data ) )
658 $this->logger->debug(
659 'SessionBackend "{session}" data dirty due to hash mismatch, {expected} !== {got}',
661 'session' => $this->
id,
662 'expected' => $this->dataHash,
663 'got' => md5(
serialize( $this->data ) ),
665 $this->dataDirty =
true;
668 if ( !$this->metaDirty && !$this->dataDirty && !$this->forcePersist ) {
672 $this->logger->debug(
673 'SessionBackend "{session}" save: dataDirty={dataDirty} ' .
674 'metaDirty={metaDirty} forcePersist={forcePersist}',
676 'session' => $this->
id,
677 'dataDirty' => (
int)$this->dataDirty,
678 'metaDirty' => (
int)$this->metaDirty,
679 'forcePersist' => (
int)$this->forcePersist,
683 if ( $this->metaDirty || $this->forcePersist ) {
685 foreach ( $this->requests as
$request ) {
687 $this->provider->persistSession( $this,
$request );
693 foreach ( $this->requests as
$request ) {
694 if (
$request->getSessionId() === $this->id ) {
695 $this->provider->unpersistSession(
$request );
701 $this->forcePersist =
false;
703 if ( !$this->metaDirty && !$this->dataDirty ) {
708 $metadata = $origMetadata = [
709 'provider' => (
string)$this->provider,
710 'providerMetadata' => $this->providerMetadata,
711 'userId' => $anon ? 0 : $this->user->getId(),
712 'userName' => User::isValidUserName( $this->user->getName() ) ? $this->user->getName() :
null,
713 'userToken' => $anon ? null : $this->user->getToken(),
721 \Hooks::run(
'SessionMetadata', [ $this, &$metadata, $this->requests ] );
723 foreach ( $origMetadata as $k => $v ) {
724 if ( $metadata[$k] !== $v ) {
725 throw new \UnexpectedValueException(
"SessionMetadata hook changed metadata key \"$k\"" );
729 $flags = $this->
persist ? 0 : CachedBagOStuff::WRITE_CACHE_ONLY;
730 $flags |= CachedBagOStuff::WRITE_SYNC;
732 $this->store->makeKey(
'MWSession', (
string)$this->id ),
734 'data' => $this->data,
735 'metadata' => $metadata,
737 $metadata[
'expires'],
741 $this->metaDirty =
false;
742 $this->dataDirty =
false;
743 $this->dataHash = md5(
serialize( $this->data ) );
744 $this->expires = $metadata[
'expires'];
752 if ( !$this->checkPHPSessionRecursionGuard ) {
753 $this->checkPHPSessionRecursionGuard =
true;
754 $reset = new \Wikimedia\ScopedCallback(
function () {
755 $this->checkPHPSessionRecursionGuard =
false;
761 $this->logger->debug(
762 'SessionBackend "{session}" Taking over PHP session',
764 'session' => $this->
id,
766 session_id( (
string)$this->
id );
767 \MediaWiki\quietCall(
'session_start' );
wfReadOnly()
Check whether the wiki is in read-only mode.
wfGetAllCallers( $limit=3)
Return a string consisting of callers in the stack.
get( $key, $flags=0, $oldFlags=null)
Get an item with the given key.
Wrapper around a BagOStuff that caches data in memory.
makeKey()
Make a cache key, scoped to this instance's keyspace.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a save
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
it s the revision text itself In either if gzip is the revision text is gzipped $flags