wfWikiID(), 'hostname' => wfHostname(), 'trxProfiler' => Profiler::instance()->getTransactionProfiler(), 'replLogger' => LoggerFactory::getInstance( 'DBReplication' ), 'queryLogger' => LoggerFactory::getInstance( 'wfLogDBError' ), 'connLogger' => LoggerFactory::getInstance( 'wfLogDBError' ), 'perfLogger' => LoggerFactory::getInstance( 'DBPerformance' ), 'errorLogger' => [ MWExceptionHandler::class, 'logException' ] ]; // Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804) $sCache = ObjectCache::getLocalServerInstance(); if ( $sCache->getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) { $defaults['srvCache'] = $sCache; } $cCache = ObjectCache::getLocalClusterInstance(); if ( $cCache->getQoS( $cCache::ATTR_EMULATION ) > $cCache::QOS_EMULATION_SQL ) { $defaults['memCache'] = $cCache; } $wCache = ObjectCache::getMainWANInstance(); if ( $wCache->getQoS( $wCache::ATTR_EMULATION ) > $wCache::QOS_EMULATION_SQL ) { $defaults['wanCache'] = $wCache; } $this->agent = isset( $params['agent'] ) ? $params['agent'] : ''; $this->cliMode = isset( $params['cliMode'] ) ? $params['cliMode'] : $wgCommandLineMode; parent::__construct( $conf + $defaults ); } /** * Returns the LBFactory class to use and the load balancer configuration. * * @todo instead of this, use a ServiceContainer for managing the different implementations. * * @param array $config (e.g. $wgLBFactoryConf) * @return string Class name */ public static function getLBFactoryClass( array $config ) { // For configuration backward compatibility after removing // underscores from class names in MediaWiki 1.23. $bcClasses = [ 'LBFactory_Simple' => 'LBFactorySimple', 'LBFactory_Single' => 'LBFactorySingle', 'LBFactory_Multi' => 'LBFactoryMulti' ]; $class = $config['class']; if ( isset( $bcClasses[$class] ) ) { $class = $bcClasses[$class]; wfDeprecated( '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details', '1.23' ); } return $class; } /** * @return bool * @since 1.27 * @deprecated Since 1.28; use laggedReplicaUsed() */ public function laggedSlaveUsed() { return $this->laggedReplicaUsed(); } protected function newChronologyProtector() { $request = RequestContext::getMain()->getRequest(); $chronProt = new ChronologyProtector( ObjectCache::getMainStashInstance(), [ 'ip' => $request->getIP(), 'agent' => $request->getHeader( 'User-Agent' ), ], $request->getFloat( 'cpPosTime', $request->getCookie( 'cpPosTime', '' ) ) ); if ( PHP_SAPI === 'cli' ) { $chronProt->setEnabled( false ); } elseif ( $request->getHeader( 'ChronologyProtection' ) === 'false' ) { // Request opted out of using position wait logic. This is useful for requests // done by the job queue or background ETL that do not have a meaningful session. $chronProt->setWaitEnabled( false ); } return $chronProt; } /** * Append ?cpPosTime parameter to a URL for ChronologyProtector purposes if needed * * Note that unlike cookies, this works accross domains * * @param string $url * @param float $time UNIX timestamp just before shutdown() was called * @return string * @since 1.28 */ public function appendPreShutdownTimeAsQuery( $url, $time ) { $usedCluster = 0; $this->forEachLB( function ( LoadBalancer $lb ) use ( &$usedCluster ) { $usedCluster |= ( $lb->getServerCount() > 1 ); } ); if ( !$usedCluster ) { return $url; // no master/replica clusters touched } return wfAppendQuery( $url, [ 'cpPosTime' => $time ] ); } }