26use Psr\Log\LoggerInterface;
27use Wikimedia\ScopedCallback;
109 [
'replLogger',
'connLogger',
'queryLogger',
'perfLogger' ];
112 $this->localDomain = isset( $conf[
'localDomain'] )
116 $this->maxLag = $conf[
'maxLag'] ??
null;
117 if ( isset( $conf[
'readOnlyReason'] ) && is_string( $conf[
'readOnlyReason'] ) ) {
118 $this->readOnlyReason = $conf[
'readOnlyReason'];
123 $this->wanCache = $conf[
'wanCache'] ?? WANObjectCache::newEmpty();
125 foreach ( self::$loggerFields
as $key ) {
126 $this->$key = $conf[$key] ?? new \Psr\Log\NullLogger();
128 $this->errorLogger = $conf[
'errorLogger'] ??
function ( Exception
$e ) {
129 trigger_error( get_class(
$e ) .
': ' .
$e->getMessage(), E_USER_WARNING );
131 $this->deprecationLogger = $conf[
'deprecationLogger'] ??
function ( $msg ) {
132 trigger_error( $msg, E_USER_DEPRECATED );
135 $this->profiler = $conf[
'profiler'] ??
null;
138 $this->requestInfo = [
139 'IPAddress' => $_SERVER[
'REMOTE_ADDR' ] ??
'',
140 'UserAgent' => $_SERVER[
'HTTP_USER_AGENT'] ??
'',
142 'ChronologyProtection' =>
null,
143 'ChronologyClientId' =>
null,
144 'ChronologyPositionIndex' =>
null
147 $this->cliMode = $conf[
'cliMode'] ?? ( PHP_SAPI ===
'cli' || PHP_SAPI ===
'phpdbg' );
148 $this->hostname = $conf[
'hostname'] ?? gethostname();
149 $this->agent = $conf[
'agent'] ??
'';
150 $this->defaultGroup = $conf[
'defaultGroup'] ??
null;
152 $this->ticket = mt_rand();
156 $this->
shutdown( self::SHUTDOWN_NO_CHRONPROT );
161 return $this->localDomain->getId();
169 $mode = self::SHUTDOWN_CHRONPROT_SYNC,
170 callable $workCallback =
null,
175 if ( $mode === self::SHUTDOWN_CHRONPROT_SYNC ) {
177 } elseif ( $mode === self::SHUTDOWN_CHRONPROT_ASYNC ) {
223 $loadBalancer->$methodName( ...
$args );
225 [ $methodName,
$args ]
242 if ( $this->trxRoundId !==
false ) {
245 "$fname: transaction round '{$this->trxRoundId}' already started."
248 $this->trxRoundId =
$fname;
257 if ( $this->trxRoundId !==
false && $this->trxRoundId !==
$fname ) {
260 "$fname: transaction round '{$this->trxRoundId}' still running."
264 $scope = ScopedCallback::newScopedIgnoreUserAbort();
271 }
while ( $count > 0 );
272 $this->trxRoundId =
false;
284 if (
$e instanceof Exception ) {
291 $this->trxRoundId =
false;
322 return ( $this->trxRoundId !==
false );
326 return ( $this->trxRoundStage === self::ROUND_CURSORY );
338 $callersByDB[$masterName] = $callers;
342 if ( count( $callersByDB ) >= 2 ) {
343 $dbs = implode(
', ', array_keys( $callersByDB ) );
344 $msg =
"Multi-DB transaction [{$dbs}]:\n";
345 foreach ( $callersByDB
as $db => $callers ) {
346 $msg .=
"$db: " . implode(
'; ', $callers ) .
"\n";
348 $this->queryLogger->info( $msg );
382 'timeout' => $this->cliMode ? 60 : 1,
383 'ifWritesSince' =>
null
386 if ( $opts[
'domain'] ===
false && isset( $opts[
'wiki'] ) ) {
387 $opts[
'domain'] = $opts[
'wiki'];
393 if ( $opts[
'cluster'] !==
false ) {
395 } elseif ( $opts[
'domain'] !==
false ) {
396 $lbs[] = $this->
getMainLB( $opts[
'domain'] );
409 $masterPositions = array_fill( 0, count( $lbs ),
false );
410 foreach ( $lbs
as $i => $lb ) {
411 if ( $lb->getServerCount() <= 1 ) {
415 } elseif ( $opts[
'ifWritesSince']
416 && $lb->lastMasterChangeTimestamp() < $opts[
'ifWritesSince']
420 $masterPositions[$i] = $lb->getMasterPos();
425 foreach ( $this->replicationWaitCallbacks
as $callback ) {
430 foreach ( $lbs
as $i => $lb ) {
431 if ( $masterPositions[$i] ) {
433 if ( !$lb->waitForAll( $masterPositions[$i], $opts[
'timeout'] ) ) {
434 $failed[] = $lb->getServerName( $lb->getWriterIndex() );
444 $this->replicationWaitCallbacks[
$name] = $callback;
446 unset( $this->replicationWaitCallbacks[
$name] );
452 $this->queryLogger->error( __METHOD__ .
": $fname does not have outer scope.\n" .
453 (
new RuntimeException() )->getTraceAsString() );
462 if (
$ticket !== $this->ticket ) {
463 $this->perfLogger->error( __METHOD__ .
": $fname does not have outer scope.\n" .
464 (
new RuntimeException() )->getTraceAsString() );
471 if ( $this->trxRoundId !==
false &&
$fname !== $this->trxRoundId ) {
472 $this->queryLogger->info(
"$fname: committing on behalf of {$this->trxRoundId}." );
482 if ( $fnameEffective !==
$fname ) {
485 return $waitSucceeded;
500 if ( $this->chronProt ) {
507 'ip' => $this->requestInfo[
'IPAddress'],
508 'agent' => $this->requestInfo[
'UserAgent'],
509 'clientId' => $this->requestInfo[
'ChronologyClientId']
511 $this->requestInfo[
'ChronologyPositionIndex']
513 $this->chronProt->setLogger( $this->replLogger );
515 if ( $this->cliMode ) {
516 $this->chronProt->setEnabled(
false );
517 } elseif ( $this->requestInfo[
'ChronologyProtection'] ===
'false' ) {
520 $this->chronProt->setWaitEnabled(
false );
523 $this->chronProt->setEnabled(
false );
524 $this->replLogger->info(
'Cannot use ChronologyProtector with EmptyBagOStuff.' );
527 $this->replLogger->debug( __METHOD__ .
': using request info ' .
528 json_encode( $this->requestInfo, JSON_PRETTY_PRINT ) );
550 $unsavedPositions = $cp->
shutdown( $workCallback, $mode, $cpIndex );
551 if ( $unsavedPositions && $workCallback ) {
561 if ( isset( $unsavedPositions[$masterName] ) ) {
562 $lb->
waitForAll( $unsavedPositions[$masterName] );
572 if ( $this->trxRoundStage === self::ROUND_COMMIT_CALLBACKS ) {
573 $initStage = ILoadBalancer::STAGE_POSTCOMMIT_CALLBACKS;
574 } elseif ( $this->trxRoundStage === self::ROUND_ROLLBACK_CALLBACKS ) {
575 $initStage = ILoadBalancer::STAGE_POSTROLLBACK_CALLBACKS;
602 'roundStage' => $initStage
610 if ( $this->trxRoundId !==
false ) {
619 $this->tableAliases = $aliases;
623 $this->indexAliases = $aliases;
636 $this->localDomain->getDatabase(),
637 $this->localDomain->getSchema(),
670 if ( !$usedCluster ) {
674 return strpos( $url,
'?' ) ===
false ?
"$url?cpPosIndex=$index" :
"$url&cpPosIndex=$index";
685 return "$index@$time#$clientId";
695 static $placeholder = [
'index' =>
null,
'clientId' =>
null ];
697 if ( !preg_match(
'/^(\d+)@(\d+)#([0-9a-f]{32})$/',
$value, $m ) ) {
704 } elseif ( isset( $m[2] ) && $m[2] !==
'' && (
int)$m[2] < $minTimestamp ) {
708 $clientId = ( isset( $m[3] ) && $m[3] !==
'' ) ? $m[3] :
null;
710 return [
'index' => $index,
'clientId' => $clientId ];
714 if ( $this->chronProt ) {
715 throw new LogicException(
'ChronologyProtector already initialized.' );
725 if ( $this->trxRoundStage !== $stage ) {
728 "Transaction round stage must be '$stage' (not '{$this->trxRoundStage}')"
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Class representing a cache/ephemeral data store.
A BagOStuff object with no objects in it.
Multi-datacenter aware caching interface.
Class to handle database/prefix specification for IDatabase domains.
static newFromId( $domain)
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
see documentation in includes Linker php for Linker::makeImageLink & $time
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
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Allows to change the fields on the form that will be generated $name
returning false will NOT prevent logging $e
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))