26use Psr\Log\LoggerInterface;
56 \RequestContext::getMain()->getConfig()->
get(
'PHPSessionHandling' )
70 switch ( $PHPSessionHandling ) {
82 $this->enable =
false;
101 return self::$instance && self::$instance->enable;
109 if ( self::$instance ) {
115 if ( defined(
'MW_NO_SESSION_HANDLER' ) ) {
116 throw new \BadMethodCallException(
'MW_NO_SESSION_HANDLER is defined' );
120 self::$instance =
new self(
$manager );
123 session_write_close();
126 \Wikimedia\suppressWarnings();
129 ini_set(
'session.use_cookies', 0 );
130 ini_set(
'session.use_trans_sid', 0 );
136 session_cache_limiter(
'' );
139 \Wikimedia\PhpSessionSerializer::setSerializeHandler();
143 session_set_save_handler( self::$instance,
true );
145 \Wikimedia\restoreWarnings();
159 if ( $this->manager !==
$manager ) {
161 if ( $this->manager ) {
162 session_write_close();
167 \Wikimedia\PhpSessionSerializer::setLogger( $this->logger );
178 public function open( $save_path, $session_name ) {
179 if ( self::$instance !== $this ) {
180 throw new \UnexpectedValueException( __METHOD__ .
': Wrong instance called!' );
182 if ( !$this->enable ) {
183 throw new \BadMethodCallException(
'Attempt to use PHP session management' );
194 if ( self::$instance !== $this ) {
195 throw new \UnexpectedValueException( __METHOD__ .
': Wrong instance called!' );
197 $this->sessionFieldCache = [];
208 if ( self::$instance !== $this ) {
209 throw new \UnexpectedValueException( __METHOD__ .
': Wrong instance called!' );
211 if ( !$this->enable ) {
212 throw new \BadMethodCallException(
'Attempt to use PHP session management' );
215 $session = $this->manager->getSessionById( $id,
false );
221 $data = iterator_to_array( $session );
222 $this->sessionFieldCache[$id] = $data;
223 return (
string)\Wikimedia\PhpSessionSerializer::encode( $data );
235 public function write( $id, $dataStr ) {
236 if ( self::$instance !== $this ) {
237 throw new \UnexpectedValueException( __METHOD__ .
': Wrong instance called!' );
239 if ( !$this->enable ) {
240 throw new \BadMethodCallException(
'Attempt to use PHP session management' );
243 $session = $this->manager->getSessionById( $id,
true );
247 $this->logger->warning(
248 __METHOD__ .
': Session "{session}" cannot be loaded, skipping write.',
256 $data = \Wikimedia\PhpSessionSerializer::decode( $dataStr );
257 if ( $data ===
null ) {
265 $cache = $this->sessionFieldCache[$id] ?? [];
266 foreach ( $data
as $key =>
$value ) {
267 if ( !array_key_exists( $key,
$cache ) ) {
268 if ( $session->exists( $key ) ) {
270 $this->logger->warning(
271 __METHOD__ .
": Key \"$key\" added in both Session and \$_SESSION!"
275 $session->set( $key,
$value );
280 } elseif ( !$session->exists( $key ) ) {
282 $this->logger->warning(
283 __METHOD__ .
": Key \"$key\" deleted in Session and changed in \$_SESSION!"
285 $session->set( $key,
$value );
287 } elseif (
$cache[$key] === $session->get( $key ) ) {
289 $session->set( $key,
$value );
293 $this->logger->warning(
294 __METHOD__ .
": Key \"$key\" changed in both Session and \$_SESSION!"
300 \Wikimedia\PhpSessionSerializer::setLogger(
new \Psr\Log\NullLogger() );
302 if ( !array_key_exists( $key, $data ) && $session->exists( $key ) &&
303 \
Wikimedia\PhpSessionSerializer::encode( [ $key =>
true ] )
305 if (
$cache[$key] === $session->get( $key ) ) {
307 $session->remove( $key );
311 $this->logger->warning(
312 __METHOD__ .
": Key \"$key\" changed in Session and deleted in \$_SESSION!"
317 \Wikimedia\PhpSessionSerializer::setLogger( $this->logger );
323 $this->logger->warning(
'Something wrote to $_SESSION!' );
327 $this->sessionFieldCache[$id] = iterator_to_array( $session );
342 if ( self::$instance !== $this ) {
343 throw new \UnexpectedValueException( __METHOD__ .
': Wrong instance called!' );
345 if ( !$this->enable ) {
346 throw new \BadMethodCallException(
'Attempt to use PHP session management' );
348 $session = $this->manager->getSessionById( $id,
false );
362 public function gc( $maxlifetime ) {
363 if ( self::$instance !== $this ) {
364 throw new \UnexpectedValueException( __METHOD__ .
': Wrong instance called!' );
366 $before = date(
'YmdHis', time() );
367 $this->
store->deleteObjectsExpiringBefore( $before );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Class representing a cache/ephemeral data store.
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
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
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