// specifically set it to the (undocumented) 'warn'. $wgPHPSessionHandling = MW_NO_SESSION === 'warn' ? 'warn' : 'disable'; } Profiler::instance()->scopedProfileOut($ps_default); // Disable MWDebug for command line mode, this prevents MWDebug from eating up // all the memory from logging SQL queries on maintenance scripts global $wgCommandLineMode; if ($wgDebugToolbar && !$wgCommandLineMode) { MWDebug::init(); } if (!class_exists('AutoLoader')) { require_once "{$IP}/includes/AutoLoader.php"; } // Reset the global service locator, so any services that have already been created will be // re-created while taking into account any custom settings and extensions. MediaWikiServices::resetGlobalInstance(new GlobalVarConfig(), 'quick'); if ($wgSharedDB && $wgSharedTables) { // Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections) MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(array_fill_keys($wgSharedTables, ['dbname' => $wgSharedDB, 'schema' => $wgSharedSchema, 'prefix' => $wgSharedPrefix])); } // Define a constant that indicates that the bootstrapping of the service locator // is complete. define('MW_SERVICE_BOOTSTRAP_COMPLETE', 1); // Install a header callback to prevent caching of responses with cookies (T127993) if (!$wgCommandLineMode) { header_register_callback(function () { $headers = []; foreach (headers_list() as $header) { list($name, $value) = explode(':', $header, 2); $headers[strtolower(trim($name))][] = trim($value); }
/** * Constructor, always call this from child classes. */ public function __construct() { global $wgMemc, $wgUser, $wgObjectCaches; $defaultConfig = new GlobalVarConfig(); // all the stuff from DefaultSettings.php $installerConfig = self::getInstallerConfig($defaultConfig); // Reset all services and inject config overrides MediaWiki\MediaWikiServices::resetGlobalInstance($installerConfig); // Don't attempt to load user language options (T126177) // This will be overridden in the web installer with the user-specified language RequestContext::getMain()->setLanguage('en'); // Disable the i18n cache // TODO: manage LocalisationCache singleton in MediaWikiServices Language::getLocalisationCache()->disableBackend(); // Disable all global services, since we don't have any configuration yet! MediaWiki\MediaWikiServices::disableStorageBackend(); // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and // SqlBagOStuff will then throw since we just disabled wfGetDB) $wgObjectCaches = MediaWikiServices::getInstance()->getMainConfig()->get('ObjectCaches'); $wgMemc = ObjectCache::getInstance(CACHE_NONE); // Having a user with id = 0 safeguards us from DB access via User::loadOptions(). $wgUser = User::newFromId(0); RequestContext::getMain()->setUser($wgUser); $this->settings = $this->internalDefaults; foreach ($this->defaultVarNames as $var) { $this->settings[$var] = $GLOBALS[$var]; } $this->doEnvironmentPreps(); $this->compiledDBs = []; foreach (self::getDBTypes() as $type) { $installer = $this->getDBInstaller($type); if (!$installer->isCompiled()) { continue; } $this->compiledDBs[] = $type; } $this->parserTitle = Title::newFromText('Installer'); $this->parserOptions = new ParserOptions($wgUser); // language will be wrong :( $this->parserOptions->setEditSection(false); }
/** * Set up LBFactory so that wfGetDB() etc. works. * We set up a special LBFactory instance which returns the current * installer connection. */ public function enableLB() { $status = $this->getConnection(); if (!$status->isOK()) { throw new MWException(__METHOD__ . ': unexpected DB connection error'); } \MediaWiki\MediaWikiServices::resetGlobalInstance(); $services = \MediaWiki\MediaWikiServices::getInstance(); $connection = $status->value; $services->redefineService('DBLoadBalancerFactory', function () use($connection) { return new LBFactorySingle(['connection' => $connection]); }); }
public function testResetGlobalInstance_quick() { $newServices = $this->newMediaWikiServices(); $oldServices = MediaWikiServices::forceGlobalInstance($newServices); $service1 = $this->getMock(SalvageableService::class); $service1->expects($this->never())->method('salvage'); $service2 = $this->getMock(SalvageableService::class); $service2->expects($this->once())->method('salvage')->with($service1); // sequence of values the instantiator will return $instantiatorReturnValues = [$service1, $service2]; $newServices->defineService('Test', function () use(&$instantiatorReturnValues) { return array_shift($instantiatorReturnValues); }); // force instantiation $newServices->getService('Test'); MediaWikiServices::resetGlobalInstance($this->newTestConfig(), 'quick'); $theServices = MediaWikiServices::getInstance(); $this->assertSame($service2, $theServices->getService('Test')); $this->assertNotSame($theServices, $newServices); $this->assertNotSame($theServices, $oldServices); MediaWikiServices::forceGlobalInstance($oldServices); }
/** * Reset global services, and install testing environment. * This is the testing equivalent of MediaWikiServices::resetGlobalInstance(). * This should only be used to set up the testing environment, not when * running unit tests. Use MediaWikiTestCase::overrideMwServices() for that. * * @see MediaWikiServices::resetGlobalInstance() * @see prepareServices() * @see MediaWikiTestCase::overrideMwServices() * * @param Config|null $bootstrapConfig The bootstrap config to use with the new * MediaWikiServices. */ protected static function resetGlobalServices(Config $bootstrapConfig = null) { $oldServices = MediaWikiServices::getInstance(); $oldConfigFactory = $oldServices->getConfigFactory(); $testConfig = self::makeTestConfig($bootstrapConfig); MediaWikiServices::resetGlobalInstance($testConfig); $serviceLocator = MediaWikiServices::getInstance(); self::installTestServices($oldConfigFactory, $serviceLocator); return $serviceLocator; }