MediaWiki
1.30.2
|
Default wiring for MediaWiki services. More...
Go to the source code of this file.
Variables | |
return [ 'DBLoadBalancerFactory'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig();$lbConf=MWLBFactory::applyDefaultConfig($mainConfig->get( 'LBFactoryConf'), $mainConfig, $services->getConfiguredReadOnlyMode());$class=MWLBFactory::getLBFactoryClass( $lbConf);return new $class( $lbConf);}, 'DBLoadBalancer'=> function(MediaWikiServices $services) { return $services->getDBLoadBalancerFactory() ->getMainLB();}, 'SiteStore'=> function(MediaWikiServices $services) { $rawSiteStore=new DBSiteStore( $services->getDBLoadBalancer());$cache=wfGetCache(wfIsHHVM() ? CACHE_ACCEL :CACHE_ANYTHING);return new CachingSiteStore( $rawSiteStore, $cache);}, 'SiteLookup'=> function(MediaWikiServices $services) { $cacheFile=$services->getMainConfig() ->get( 'SitesCacheFile');if( $cacheFile !==false) { return new FileBasedSiteLookup( $cacheFile);} else { return $services->getSiteStore();} }, 'ConfigFactory'=> function(MediaWikiServices $services) { $registry=$services->getBootstrapConfig() ->get( 'ConfigRegistry');$factory=new ConfigFactory();foreach( $registry as $name=> $callback) { $factory->register( $name, $callback);} return $factory;}, 'MainConfig'=> function(MediaWikiServices $services) { return $services->getConfigFactory() ->makeConfig( 'main');}, 'InterwikiLookup'=> function(MediaWikiServices $services) { global $wgContLang;$config=$services->getMainConfig();return new ClassicInterwikiLookup($wgContLang, $services->getMainWANObjectCache(), $config->get( 'InterwikiExpiry'), $config->get( 'InterwikiCache'), $config->get( 'InterwikiScopes'), $config->get( 'InterwikiFallbackSite'));}, 'StatsdDataFactory'=> function(MediaWikiServices $services) { return new BufferingStatsdDataFactory(rtrim( $services->getMainConfig() ->get( 'StatsdMetricPrefix'), '.'));}, 'EventRelayerGroup'=> function(MediaWikiServices $services) { return new EventRelayerGroup( $services->getMainConfig() ->get( 'EventRelayerConfig'));}, 'SearchEngineFactory'=> function(MediaWikiServices $services) { return new SearchEngineFactory( $services->getSearchEngineConfig());}, 'SearchEngineConfig'=> function(MediaWikiServices $services) { global $wgContLang;return new SearchEngineConfig( $services->getMainConfig(), $wgContLang);}, 'SkinFactory'=> function(MediaWikiServices $services) { $factory=new SkinFactory();$names=$services->getMainConfig() ->get( 'ValidSkinNames');foreach( $names as $name=> $skin) { $factory->register( $name, $skin, function() use( $name, $skin) { $class="Skin$skin";return new $class( $name);});} $factory->register( 'fallback', 'Fallback', function() { return new SkinFallback;});$factory->register( 'apioutput', 'ApiOutput', function() { return new SkinApi;});return $factory;}, 'WatchedItemStore'=> function(MediaWikiServices $services) { $store=new WatchedItemStore($services->getDBLoadBalancer(), new HashBagOStuff([ 'maxKeys'=> 100]), $services->getReadOnlyMode());$store->setStatsdDataFactory( $services->getStatsdDataFactory());return $store;}, 'WatchedItemQueryService'=> function(MediaWikiServices $services) { return new WatchedItemQueryService( $services->getDBLoadBalancer());}, 'CryptRand'=> function(MediaWikiServices $services) { $secretKey=$services->getMainConfig() ->get( 'SecretKey');return new CryptRand(['wfHostname', 'wfWikiID', function() use( $secretKey) { return $secretKey ?:'';}], defined( 'MW_CONFIG_FILE') ?[MW_CONFIG_FILE] :[], LoggerFactory::getInstance( 'CryptRand'));}, 'CryptHKDF'=> function(MediaWikiServices $services) { $config=$services->getMainConfig();$secret=$config->get( 'HKDFSecret') ?:$config->get( 'SecretKey');if(! $secret) { throw new RuntimeException("Cannot use MWCryptHKDF without a secret.");} $context=[microtime(), getmypid(), gethostname()];$cache=$services->getLocalServerObjectCache();if( $cache instanceof EmptyBagOStuff) { $cache=ObjectCache::getLocalClusterInstance();} return new CryptHKDF( $secret, $config->get( 'HKDFAlgorithm'), $cache, $context, $services->getCryptRand());}, 'MediaHandlerFactory'=> function(MediaWikiServices $services) { return new MediaHandlerFactory($services->getMainConfig() ->get( 'MediaHandlers'));}, 'MimeAnalyzer'=> function(MediaWikiServices $services) { $logger=LoggerFactory::getInstance( 'Mime');$mainConfig=$services->getMainConfig();$params=['typeFile'=> $mainConfig->get( 'MimeTypeFile'), 'infoFile'=> $mainConfig->get( 'MimeInfoFile'), 'xmlTypes'=> $mainConfig->get( 'XMLMimeTypes'), 'guessCallback'=> function( $mimeAnalyzer, &$head, &$tail, $file, &$mime) use( $logger) { $deja=new DjVuImage( $file);if( $deja->isValid()) { $logger->info(__METHOD__ . ": detected $file as image/vnd.djvu\n");$mime='image/vnd.djvu';return;} Hooks::run('MimeMagicGuessFromContent', [ $mimeAnalyzer, &$head, &$tail, $file, &$mime]);}, 'extCallback'=> function( $mimeAnalyzer, $ext, &$mime) { Hooks::run( 'MimeMagicImproveFromExtension', [ $mimeAnalyzer, $ext, &$mime]);}, 'initCallback'=> function( $mimeAnalyzer) { Hooks::run( 'MimeMagicInit', [ $mimeAnalyzer]);}, 'logger'=> $logger];if( $params['infoFile']==='includes/mime.info') { $params['infoFile']=__DIR__ . "/libs/mime/mime.info";} if( $params['typeFile']==='includes/mime.types') { $params['typeFile']=__DIR__ . "/libs/mime/mime.types";} $detectorCmd=$mainConfig->get( 'MimeDetectorCommand');if( $detectorCmd) { $params['detectCallback']=function( $file) use( $detectorCmd) { return wfShellExec("$detectorCmd " . wfEscapeShellArg( $file));};} return new MimeMagic( $params);}, 'ProxyLookup'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig();return new ProxyLookup($mainConfig->get( 'SquidServers'), $mainConfig->get( 'SquidServersNoPurge'));}, 'Parser'=> function(MediaWikiServices $services) { $conf=$services->getMainConfig() ->get( 'ParserConf');return ObjectFactory::constructClassInstance( $conf['class'], [ $conf]);}, 'ParserCache'=> function(MediaWikiServices $services) { $config=$services->getMainConfig();$cache=ObjectCache::getInstance( $config->get( 'ParserCacheType'));wfDebugLog( 'caches', 'parser:' . get_class( $cache));return new ParserCache($cache, $config->get( 'CacheEpoch'));}, 'LinkCache'=> function(MediaWikiServices $services) { return new LinkCache($services->getTitleFormatter(), $services->getMainWANObjectCache());}, 'LinkRendererFactory'=> function(MediaWikiServices $services) { return new LinkRendererFactory($services->getTitleFormatter(), $services->getLinkCache());}, 'LinkRenderer'=> function(MediaWikiServices $services) { global $wgUser;if(defined( 'MW_NO_SESSION')) { return $services->getLinkRendererFactory() ->create();} else { return $services->getLinkRendererFactory() ->createForUser( $wgUser);} }, 'GenderCache'=> function(MediaWikiServices $services) { return new GenderCache();}, '_MediaWikiTitleCodec'=> function(MediaWikiServices $services) { global $wgContLang;return new MediaWikiTitleCodec($wgContLang, $services->getGenderCache(), $services->getMainConfig() ->get( 'LocalInterwikis'));}, 'TitleFormatter'=> function(MediaWikiServices $services) { return $services->getService( '_MediaWikiTitleCodec');}, 'TitleParser'=> function(MediaWikiServices $services) { return $services->getService( '_MediaWikiTitleCodec');}, 'MainObjectStash'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig();$id=$mainConfig->get( 'MainStash');if(!isset( $mainConfig->get( 'ObjectCaches')[$id])) { throw new UnexpectedValueException("Cache type \"$id\" is not present in \$wgObjectCaches.");} return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches')[$id]);}, 'MainWANObjectCache'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig();$id=$mainConfig->get( 'MainWANCache');if(!isset( $mainConfig->get( 'WANObjectCaches')[$id])) { throw new UnexpectedValueException("WAN cache type \"$id\" is not present in \$wgWANObjectCaches.");} $params=$mainConfig->get( 'WANObjectCaches')[$id];$objectCacheId=$params['cacheId'];if(!isset( $mainConfig->get( 'ObjectCaches')[$objectCacheId])) { throw new UnexpectedValueException("Cache type \"$objectCacheId\" is not present in \$wgObjectCaches.");} $params['store']=$mainConfig->get( 'ObjectCaches')[$objectCacheId];return \ObjectCache::newWANCacheFromParams( $params);}, 'LocalServerObjectCache'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig();if(function_exists( 'apc_fetch')) { $id='apc';} elseif(function_exists( 'apcu_fetch')) { $id='apcu';} elseif(function_exists( 'xcache_get') &&wfIniGetBool( 'xcache.var_size')) { $id='xcache';} elseif(function_exists( 'wincache_ucache_get')) { $id='wincache';} else { $id=CACHE_NONE;} if(!isset( $mainConfig->get( 'ObjectCaches')[$id])) { throw new UnexpectedValueException("Cache type \"$id\" is not present in \$wgObjectCaches.");} return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches')[$id]);}, 'VirtualRESTServiceClient'=> function(MediaWikiServices $services) { $config=$services->getMainConfig() ->get( 'VirtualRestConfig');$vrsClient=new VirtualRESTServiceClient(new MultiHttpClient([]));foreach( $config['paths'] as $prefix=> $serviceConfig) { $class=$serviceConfig['class'];$constructArg=isset( $serviceConfig['options']) ? $serviceConfig['options'] :[];$constructArg+=$config['global'];$vrsClient->mount( $prefix, [ 'class'=> $class, 'config'=> $constructArg]);} return $vrsClient;}, 'ConfiguredReadOnlyMode'=> function(MediaWikiServices $services) { return new ConfiguredReadOnlyMode( $services->getMainConfig());}, 'ReadOnlyMode'=> function(MediaWikiServices $services) { return new ReadOnlyMode($services->getConfiguredReadOnlyMode(), $services->getDBLoadBalancer());}, 'ShellCommandFactory'=> function(MediaWikiServices $services) { $config=$services->getMainConfig();$limits=['time'=> $config->get( 'MaxShellTime'), 'walltime'=> $config->get( 'MaxShellWallClockTime'), 'memory'=> $config->get( 'MaxShellMemory'), 'filesize'=> $config->get( 'MaxShellFileSize'),];$cgroup=$config->get( 'ShellCgroup');$factory=new CommandFactory( $limits, $cgroup);$factory->setLogger(LoggerFactory::getInstance( 'exec'));return $factory;},] | |
Default wiring for MediaWiki services.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html
This file is loaded by MediaWiki\MediaWikiServices::getInstance() during the bootstrapping of the dependency injection framework.
This file returns an array that associates service name with instantiator functions that create the default instances for the services used by MediaWiki core. For every service that MediaWiki core requires, an instantiator must be defined in this file.
Definition in file ServiceWiring.php.
return['DBLoadBalancerFactory'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig(); $lbConf=MWLBFactory::applyDefaultConfig( $mainConfig->get('LBFactoryConf'), $mainConfig, $services->getConfiguredReadOnlyMode()); $class=MWLBFactory::getLBFactoryClass($lbConf); return new $class($lbConf);}, 'DBLoadBalancer'=> function(MediaWikiServices $services) { return $services->getDBLoadBalancerFactory() ->getMainLB();}, 'SiteStore'=> function(MediaWikiServices $services) { $rawSiteStore=new DBSiteStore($services->getDBLoadBalancer()); $cache=wfGetCache(wfIsHHVM() ? CACHE_ACCEL :CACHE_ANYTHING); return new CachingSiteStore($rawSiteStore, $cache);}, 'SiteLookup'=> function(MediaWikiServices $services) { $cacheFile=$services->getMainConfig() ->get('SitesCacheFile'); if($cacheFile !==false) { return new FileBasedSiteLookup($cacheFile); } else { return $services->getSiteStore(); } }, 'ConfigFactory'=> function(MediaWikiServices $services) { $registry=$services->getBootstrapConfig() ->get('ConfigRegistry'); $factory=new ConfigFactory(); foreach($registry as $name=> $callback) { $factory->register($name, $callback); } return $factory;}, 'MainConfig'=> function(MediaWikiServices $services) { return $services->getConfigFactory() ->makeConfig('main');}, 'InterwikiLookup'=> function(MediaWikiServices $services) { global $wgContLang; $config=$services->getMainConfig(); return new ClassicInterwikiLookup( $wgContLang, $services->getMainWANObjectCache(), $config->get('InterwikiExpiry'), $config->get('InterwikiCache'), $config->get('InterwikiScopes'), $config->get('InterwikiFallbackSite'));}, 'StatsdDataFactory'=> function(MediaWikiServices $services) { return new BufferingStatsdDataFactory( rtrim($services->getMainConfig() ->get('StatsdMetricPrefix'), '.'));}, 'EventRelayerGroup'=> function(MediaWikiServices $services) { return new EventRelayerGroup($services->getMainConfig() ->get('EventRelayerConfig'));}, 'SearchEngineFactory'=> function(MediaWikiServices $services) { return new SearchEngineFactory($services->getSearchEngineConfig());}, 'SearchEngineConfig'=> function(MediaWikiServices $services) { global $wgContLang; return new SearchEngineConfig($services->getMainConfig(), $wgContLang);}, 'SkinFactory'=> function(MediaWikiServices $services) { $factory=new SkinFactory(); $names=$services->getMainConfig() ->get('ValidSkinNames'); foreach($names as $name=> $skin) { $factory->register($name, $skin, function() use($name, $skin) { $class="Skin$skin"; return new $class($name); }); } $factory->register('fallback', 'Fallback', function() { return new SkinFallback; }); $factory->register('apioutput', 'ApiOutput', function() { return new SkinApi; }); return $factory;}, 'WatchedItemStore'=> function(MediaWikiServices $services) { $store=new WatchedItemStore( $services->getDBLoadBalancer(), new HashBagOStuff(['maxKeys'=> 100]), $services->getReadOnlyMode()); $store->setStatsdDataFactory($services->getStatsdDataFactory()); return $store;}, 'WatchedItemQueryService'=> function(MediaWikiServices $services) { return new WatchedItemQueryService($services->getDBLoadBalancer());}, 'CryptRand'=> function(MediaWikiServices $services) { $secretKey=$services->getMainConfig() ->get('SecretKey'); return new CryptRand([ 'wfHostname', 'wfWikiID', function() use($secretKey) { return $secretKey ?:''; }], defined('MW_CONFIG_FILE') ?[MW_CONFIG_FILE] :[], LoggerFactory::getInstance('CryptRand'));}, 'CryptHKDF'=> function(MediaWikiServices $services) { $config=$services->getMainConfig(); $secret=$config->get('HKDFSecret') ?:$config->get('SecretKey'); if(! $secret) { throw new RuntimeException("Cannot use MWCryptHKDF without a secret."); } $context=[microtime(), getmypid(), gethostname()]; $cache=$services->getLocalServerObjectCache(); if($cache instanceof EmptyBagOStuff) { $cache=ObjectCache::getLocalClusterInstance(); } return new CryptHKDF($secret, $config->get('HKDFAlgorithm'), $cache, $context, $services->getCryptRand());}, 'MediaHandlerFactory'=> function(MediaWikiServices $services) { return new MediaHandlerFactory( $services->getMainConfig() ->get('MediaHandlers'));}, 'MimeAnalyzer'=> function(MediaWikiServices $services) { $logger=LoggerFactory::getInstance('Mime'); $mainConfig=$services->getMainConfig(); $params=[ 'typeFile'=> $mainConfig->get('MimeTypeFile'), 'infoFile'=> $mainConfig->get('MimeInfoFile'), 'xmlTypes'=> $mainConfig->get('XMLMimeTypes'), 'guessCallback'=> function($mimeAnalyzer, & $head, & $tail, $file, & $mime) use($logger) { $deja=new DjVuImage($file); if($deja->isValid()) { $logger->info(__METHOD__ . ": detected $file as image/vnd.djvu\n"); $mime='image/vnd.djvu'; return; } Hooks::run( 'MimeMagicGuessFromContent',[$mimeAnalyzer, & $head, & $tail, $file, & $mime]); }, 'extCallback'=> function($mimeAnalyzer, $ext, & $mime) { Hooks::run('MimeMagicImproveFromExtension',[$mimeAnalyzer, $ext, & $mime]); }, 'initCallback'=> function($mimeAnalyzer) { Hooks::run('MimeMagicInit',[$mimeAnalyzer]); }, 'logger'=> $logger]; if($params[ 'infoFile']==='includes/mime.info') { $params[ 'infoFile']=__DIR__ . "/libs/mime/mime.info"; } if($params[ 'typeFile']==='includes/mime.types') { $params[ 'typeFile']=__DIR__ . "/libs/mime/mime.types"; } $detectorCmd=$mainConfig->get('MimeDetectorCommand'); if($detectorCmd) { $params[ 'detectCallback']=function($file) use($detectorCmd) { return wfShellExec("$detectorCmd " . wfEscapeShellArg($file)); }; } return new MimeMagic($params);}, 'ProxyLookup'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig(); return new ProxyLookup( $mainConfig->get('SquidServers'), $mainConfig->get('SquidServersNoPurge'));}, 'Parser'=> function(MediaWikiServices $services) { $conf=$services->getMainConfig() ->get('ParserConf'); return ObjectFactory::constructClassInstance($conf[ 'class'],[$conf]);}, 'ParserCache'=> function(MediaWikiServices $services) { $config=$services->getMainConfig(); $cache=ObjectCache::getInstance($config->get('ParserCacheType')); wfDebugLog('caches', 'parser:' . get_class($cache)); return new ParserCache( $cache, $config->get('CacheEpoch'));}, 'LinkCache'=> function(MediaWikiServices $services) { return new LinkCache( $services->getTitleFormatter(), $services->getMainWANObjectCache());}, 'LinkRendererFactory'=> function(MediaWikiServices $services) { return new LinkRendererFactory( $services->getTitleFormatter(), $services->getLinkCache());}, 'LinkRenderer'=> function(MediaWikiServices $services) { global $wgUser; if(defined('MW_NO_SESSION')) { return $services->getLinkRendererFactory() ->create(); } else { return $services->getLinkRendererFactory() ->createForUser($wgUser); } }, 'GenderCache'=> function(MediaWikiServices $services) { return new GenderCache();}, '_MediaWikiTitleCodec'=> function(MediaWikiServices $services) { global $wgContLang; return new MediaWikiTitleCodec( $wgContLang, $services->getGenderCache(), $services->getMainConfig() ->get('LocalInterwikis'));}, 'TitleFormatter'=> function(MediaWikiServices $services) { return $services->getService('_MediaWikiTitleCodec');}, 'TitleParser'=> function(MediaWikiServices $services) { return $services->getService('_MediaWikiTitleCodec');}, 'MainObjectStash'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig(); $id=$mainConfig->get('MainStash'); if(!isset($mainConfig->get('ObjectCaches')[ $id])) { throw new UnexpectedValueException( "Cache type \"$id\" is not present in \$wgObjectCaches."); } return \ObjectCache::newFromParams($mainConfig->get('ObjectCaches')[ $id]);}, 'MainWANObjectCache'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig(); $id=$mainConfig->get('MainWANCache'); if(!isset($mainConfig->get('WANObjectCaches')[ $id])) { throw new UnexpectedValueException( "WAN cache type \"$id\" is not present in \$wgWANObjectCaches."); } $params=$mainConfig->get('WANObjectCaches')[ $id]; $objectCacheId=$params[ 'cacheId']; if(!isset($mainConfig->get('ObjectCaches')[ $objectCacheId])) { throw new UnexpectedValueException( "Cache type \"$objectCacheId\" is not present in \$wgObjectCaches."); } $params[ 'store']=$mainConfig->get('ObjectCaches')[ $objectCacheId]; return \ObjectCache::newWANCacheFromParams($params);}, 'LocalServerObjectCache'=> function(MediaWikiServices $services) { $mainConfig=$services->getMainConfig(); if(function_exists('apc_fetch')) { $id='apc'; } elseif(function_exists('apcu_fetch')) { $id='apcu'; } elseif(function_exists('xcache_get') &&wfIniGetBool('xcache.var_size')) { $id='xcache'; } elseif(function_exists('wincache_ucache_get')) { $id='wincache'; } else { $id=CACHE_NONE; } if(!isset($mainConfig->get('ObjectCaches')[ $id])) { throw new UnexpectedValueException( "Cache type \"$id\" is not present in \$wgObjectCaches."); } return \ObjectCache::newFromParams($mainConfig->get('ObjectCaches')[ $id]);}, 'VirtualRESTServiceClient'=> function(MediaWikiServices $services) { $config=$services->getMainConfig() ->get('VirtualRestConfig'); $vrsClient=new VirtualRESTServiceClient(new MultiHttpClient([])); foreach($config[ 'paths'] as $prefix=> $serviceConfig) { $class=$serviceConfig[ 'class']; $constructArg=isset($serviceConfig[ 'options']) ? $serviceConfig[ 'options'] :[]; $constructArg+=$config[ 'global']; $vrsClient->mount($prefix,['class'=> $class, 'config'=> $constructArg]); } return $vrsClient;}, 'ConfiguredReadOnlyMode'=> function(MediaWikiServices $services) { return new ConfiguredReadOnlyMode($services->getMainConfig());}, 'ReadOnlyMode'=> function(MediaWikiServices $services) { return new ReadOnlyMode( $services->getConfiguredReadOnlyMode(), $services->getDBLoadBalancer());}, 'ShellCommandFactory'=> function(MediaWikiServices $services) { $config=$services->getMainConfig(); $limits=[ 'time'=> $config->get('MaxShellTime'), 'walltime'=> $config->get('MaxShellWallClockTime'), 'memory'=> $config->get('MaxShellMemory'), 'filesize'=> $config->get('MaxShellFileSize'),]; $cgroup=$config->get('ShellCgroup'); $factory=new CommandFactory($limits, $cgroup); $factory->setLogger(LoggerFactory::getInstance('exec')); return $factory;},] |
Definition at line 455 of file ServiceWiring.php.