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,
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,
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' );
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(
wfMemcKey(
'MWSession', (
string)$this->
id ) );
341 if ( $this->remember !== (
bool)
$remember ) {
342 $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();
651 $this->metaDirty =
true;
655 if ( !$this->metaDirty && !$this->dataDirty &&
658 $this->logger->debug(
659 'SessionBackend "{session}" data dirty due to hash mismatch, {expected} !== {got}',
661 'session' => $this->
id,
662 'expected' => $this->dataHash,
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 ) {
687 $this->provider->persistSession( $this, $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(),
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\"" );
732 wfMemcKey(
'MWSession', (
string)$this->
id ),
734 'data' => $this->
data,
735 'metadata' => $metadata,
737 $metadata[
'expires'],
741 $this->metaDirty =
false;
742 $this->dataDirty =
false;
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' );
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
the array() calling protocol came about after MediaWiki 1.4rc1.
saveSettings()
Save this user's settings into the database.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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
MediaWiki s SiteStore can be cached and stored in a flat in a json format If the SiteStore is frequently the file cache may provide a performance benefit over a database store
static isValidUserName($name)
Is the input a valid username?
wfReadOnly()
Check whether the wiki is in read-only mode.
static getMain()
Static methods.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
const WRITE_SYNC
Bitfield constants for set()/merge()
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
wfGetAllCallers($limit=3)
Return a string consisting of callers in the stack.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
error also a ContextSource you ll probably need to make sure the header is varied on $request
get($key, $flags=0, $oldFlags=null)
Get an item with the given key.
wfMemcKey()
Make a cache key for the local wiki.
static addCallableUpdate($callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.