/** * @param bool|string $wiki Wiki ID * @return JobQueueGroup */ public static function singleton($wiki = false) { $wiki = $wiki === false ? wfWikiID() : $wiki; if (!isset(self::$instances[$wiki])) { self::$instances[$wiki] = new self($wiki, wfConfiguredReadOnlyReason()); } return self::$instances[$wiki]; }
/** * @param array $lbConf Config for LBFactory::__construct() * @param Config $mainConfig Main config object from MediaWikiServices * @return array */ public static function applyDefaultConfig(array $lbConf, Config $mainConfig) { global $wgCommandLineMode; $lbConf += ['localDomain' => new DatabaseDomain($mainConfig->get('DBname'), null, $mainConfig->get('DBprefix')), 'profiler' => Profiler::instance(), 'trxProfiler' => Profiler::instance()->getTransactionProfiler(), 'replLogger' => LoggerFactory::getInstance('DBReplication'), 'queryLogger' => LoggerFactory::getInstance('DBQuery'), 'connLogger' => LoggerFactory::getInstance('DBConnection'), 'perfLogger' => LoggerFactory::getInstance('DBPerformance'), 'errorLogger' => [MWExceptionHandler::class, 'logException'], 'cliMode' => $wgCommandLineMode, 'hostname' => wfHostname(), 'readOnlyReason' => wfConfiguredReadOnlyReason()]; if ($lbConf['class'] === 'LBFactorySimple') { if (isset($lbConf['servers'])) { // Server array is already explicitly configured; leave alone } elseif (is_array($mainConfig->get('DBservers'))) { foreach ($mainConfig->get('DBservers') as $i => $server) { if ($server['type'] === 'sqlite') { $server += ['dbDirectory' => $mainConfig->get('SQLiteDataDir')]; } elseif ($server['type'] === 'postgres') { $server += ['port' => $mainConfig->get('DBport')]; } $lbConf['servers'][$i] = $server + ['schema' => $mainConfig->get('DBmwschema'), 'tablePrefix' => $mainConfig->get('DBprefix'), 'flags' => DBO_DEFAULT, 'sqlMode' => $mainConfig->get('SQLMode'), 'utf8Mode' => $mainConfig->get('DBmysql5')]; } } else { $flags = DBO_DEFAULT; $flags |= $mainConfig->get('DebugDumpSql') ? DBO_DEBUG : 0; $flags |= $mainConfig->get('DBssl') ? DBO_SSL : 0; $flags |= $mainConfig->get('DBcompress') ? DBO_COMPRESS : 0; $server = ['host' => $mainConfig->get('DBserver'), 'user' => $mainConfig->get('DBuser'), 'password' => $mainConfig->get('DBpassword'), 'dbname' => $mainConfig->get('DBname'), 'schema' => $mainConfig->get('DBmwschema'), 'tablePrefix' => $mainConfig->get('DBprefix'), 'type' => $mainConfig->get('DBtype'), 'load' => 1, 'flags' => $flags, 'sqlMode' => $mainConfig->get('SQLMode'), 'utf8Mode' => $mainConfig->get('DBmysql5')]; if ($server['type'] === 'sqlite') { $server['dbDirectory'] = $mainConfig->get('SQLiteDataDir'); } elseif ($server['type'] === 'postgres') { $server['port'] = $mainConfig->get('DBport'); } $lbConf['servers'] = [$server]; } if (!isset($lbConf['externalClusters'])) { $lbConf['externalClusters'] = $mainConfig->get('ExternalServers'); } } elseif ($lbConf['class'] === 'LBFactoryMulti') { if (isset($lbConf['serverTemplate'])) { $lbConf['serverTemplate']['schema'] = $mainConfig->get('DBmwschema'); $lbConf['serverTemplate']['sqlMode'] = $mainConfig->get('SQLMode'); $lbConf['serverTemplate']['utf8Mode'] = $mainConfig->get('DBmysql5'); } } // Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804) $sCache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); if ($sCache->getQoS($sCache::ATTR_EMULATION) > $sCache::QOS_EMULATION_SQL) { $lbConf['srvCache'] = $sCache; } $cCache = ObjectCache::getLocalClusterInstance(); if ($cCache->getQoS($cCache::ATTR_EMULATION) > $cCache::QOS_EMULATION_SQL) { $lbConf['memCache'] = $cCache; } $wCache = MediaWikiServices::getInstance()->getMainWANObjectCache(); if ($wCache->getQoS($wCache::ATTR_EMULATION) > $wCache::QOS_EMULATION_SQL) { $lbConf['wanCache'] = $wCache; } return $lbConf; }
/** * Get an LBFactory instance * * @return LBFactory */ public static function singleton() { global $wgLBFactoryConf; if (is_null(self::$instance)) { $class = self::getLBFactoryClass($wgLBFactoryConf); $config = $wgLBFactoryConf; if (!isset($config['readOnlyReason'])) { $config['readOnlyReason'] = wfConfiguredReadOnlyReason(); } self::$instance = new $class($config); } return self::$instance; }
/** * Check if the site is in read-only mode and return the message if so * * This checks wfConfiguredReadOnlyReason() and the main load balancer * for slave lag. This may result in DB_SLAVE connection being made. * * @return string|bool String when in read-only mode; false otherwise */ function wfReadOnlyReason() { $readOnly = wfConfiguredReadOnlyReason(); if ($readOnly !== false) { return $readOnly; } static $autoReadOnly = null; if ($autoReadOnly === null) { // Callers use this method to be aware that data presented to a user // may be very stale and thus allowing submissions can be problematic. try { if (wfGetLB()->getLaggedSlaveMode()) { $autoReadOnly = 'The database has been automatically locked ' . 'while the slave database servers catch up to the master'; } else { $autoReadOnly = false; } } catch (DBConnectionError $e) { $autoReadOnly = 'The database has been automatically locked ' . 'until the slave database servers become available'; } } return $autoReadOnly; }
/** * Check if the site is in read-only mode and return the message if so * * This checks wfConfiguredReadOnlyReason() and the main load balancer * for slave lag. This may result in DB_SLAVE connection being made. * * @return string|bool String when in read-only mode; false otherwise */ function wfReadOnlyReason() { $readOnly = wfConfiguredReadOnlyReason(); if ($readOnly !== false) { return $readOnly; } static $lbReadOnly = null; if ($lbReadOnly === null) { // Callers use this method to be aware that data presented to a user // may be very stale and thus allowing submissions can be problematic. $lbReadOnly = wfGetLB()->getReadOnlyReason(); } return $lbReadOnly; }
/** * Register file backends from the global variables */ protected function initFromGlobals() { global $wgLocalFileRepo, $wgForeignFileRepos, $wgFileBackends; // Register explicitly defined backends $this->register($wgFileBackends, wfConfiguredReadOnlyReason()); $autoBackends = array(); // Automatically create b/c backends for file repos... $repos = array_merge($wgForeignFileRepos, array($wgLocalFileRepo)); foreach ($repos as $info) { $backendName = $info['backend']; if (is_object($backendName) || isset($this->backends[$backendName])) { continue; // already defined (or set to the object for some reason) } $repoName = $info['name']; // Local vars that used to be FSRepo members... $directory = $info['directory']; $deletedDir = isset($info['deletedDir']) ? $info['deletedDir'] : false; // deletion disabled $thumbDir = isset($info['thumbDir']) ? $info['thumbDir'] : "{$directory}/thumb"; $transcodedDir = isset($info['transcodedDir']) ? $info['transcodedDir'] : "{$directory}/transcoded"; $fileMode = isset($info['fileMode']) ? $info['fileMode'] : 0644; // Get the FS backend configuration $autoBackends[] = array('name' => $backendName, 'class' => 'FSFileBackend', 'lockManager' => 'fsLockManager', 'containerPaths' => array("{$repoName}-public" => "{$directory}", "{$repoName}-thumb" => $thumbDir, "{$repoName}-transcoded" => $transcodedDir, "{$repoName}-deleted" => $deletedDir, "{$repoName}-temp" => "{$directory}/temp"), 'fileMode' => $fileMode); } // Register implicitly defined backends $this->register($autoBackends, wfConfiguredReadOnlyReason()); }
* much of the code still relies on global state for this accessing services. * * @since 1.27 * * @see docs/injection.txt for an overview of using dependency injection in the * MediaWiki code base. */ use MediaWiki\Interwiki\ClassicInterwikiLookup; use MediaWiki\Linker\LinkRendererFactory; use MediaWiki\MediaWikiServices; return ['DBLoadBalancerFactory' => function (MediaWikiServices $services) { $config = $services->getMainConfig()->get('LBFactoryConf'); $class = LBFactory::getLBFactoryClass($config); if (!isset($config['readOnlyReason'])) { // TODO: replace the global wfConfiguredReadOnlyReason() with a service. $config['readOnlyReason'] = wfConfiguredReadOnlyReason(); } return new $class($config); }, 'DBLoadBalancer' => function (MediaWikiServices $services) { // just return the default LB from the DBLoadBalancerFactory service return $services->getDBLoadBalancerFactory()->getMainLB(); }, 'SiteStore' => function (MediaWikiServices $services) { $rawSiteStore = new DBSiteStore($services->getDBLoadBalancer()); // TODO: replace wfGetCache with a CacheFactory service. // TODO: replace wfIsHHVM with a capabilities service. $cache = wfGetCache(wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING); return new CachingSiteStore($rawSiteStore, $cache); }, 'SiteLookup' => function (MediaWikiServices $services) { // Use the default SiteStore as the SiteLookup implementation for now return $services->getSiteStore(); }, 'ConfigFactory' => function (MediaWikiServices $services) {