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,
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 \ScopedCallback(
function () {
614 public function save( $closing =
false ) {
615 $anon = $this->
user->isAnon();
617 if ( !$anon && $this->provider->getManager()->isUserSessionPrevented( $this->
user->getName() ) ) {
618 $this->logger->debug(
619 'SessionBackend "{session}" not saving, user {user} was ' .
620 'passed to SessionManager::preventSessionsForUser',
622 'session' => $this->
id,
623 'user' => $this->
user,
630 if ( !$anon && !$this->
user->getToken(
false ) ) {
631 $this->logger->debug(
632 'SessionBackend "{session}" creating token for user {user} on save',
634 'session' => $this->
id,
635 'user' => $this->
user,
637 $this->
user->setToken();
639 $this->
user->saveSettings();
641 $this->metaDirty =
true;
645 if ( !$this->metaDirty && !$this->dataDirty &&
648 $this->logger->debug(
649 'SessionBackend "{session}" data dirty due to hash mismatch, {expected} !== {got}',
651 'session' => $this->
id,
652 'expected' => $this->dataHash,
655 $this->dataDirty =
true;
658 if ( !$this->metaDirty && !$this->dataDirty && !$this->forcePersist ) {
662 $this->logger->debug(
663 'SessionBackend "{session}" save: dataDirty={dataDirty} ' .
664 'metaDirty={metaDirty} forcePersist={forcePersist}',
666 'session' => $this->
id,
667 'dataDirty' => (
int)$this->dataDirty,
668 'metaDirty' => (
int)$this->metaDirty,
669 'forcePersist' => (
int)$this->forcePersist,
673 if ( $this->metaDirty || $this->forcePersist ) {
677 $this->provider->persistSession( $this, $request );
684 if ( $request->getSessionId() ===
$this->id ) {
685 $this->provider->unpersistSession( $request );
691 $this->forcePersist =
false;
693 if ( !$this->metaDirty && !$this->dataDirty ) {
698 $metadata = $origMetadata = [
699 'provider' => (
string)$this->provider,
700 'providerMetadata' => $this->providerMetadata,
701 'userId' => $anon ? 0 : $this->
user->getId(),
703 'userToken' => $anon ? null : $this->
user->getToken(),
711 \Hooks::run(
'SessionMetadata', [ $this, &$metadata, $this->requests ] );
713 foreach ( $origMetadata
as $k => $v ) {
714 if ( $metadata[$k] !== $v ) {
715 throw new \UnexpectedValueException(
"SessionMetadata hook changed metadata key \"$k\"" );
720 wfMemcKey(
'MWSession', (
string)$this->
id ),
722 'data' => $this->
data,
723 'metadata' => $metadata,
725 $metadata[
'expires'],
729 $this->metaDirty =
false;
730 $this->dataDirty =
false;
732 $this->expires = $metadata[
'expires'];
740 if ( !$this->checkPHPSessionRecursionGuard ) {
741 $this->checkPHPSessionRecursionGuard =
true;
742 $reset = new \ScopedCallback(
function () {
743 $this->checkPHPSessionRecursionGuard =
false;
749 $this->logger->debug(
750 'SessionBackend "{session}" Taking over PHP session',
752 'session' => $this->
id,
754 session_id( (
string)$this->
id );
755 \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.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
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
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.
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.