MediaWiki REL1_28
ServiceWiring.php
Go to the documentation of this file.
1<?php
44
45return [
46 'DBLoadBalancerFactory' => function( MediaWikiServices $services ) {
47 $mainConfig = $services->getMainConfig();
48
50 $mainConfig->get( 'LBFactoryConf' ),
51 $mainConfig
52 );
53 $class = MWLBFactory::getLBFactoryClass( $lbConf );
54
55 return new $class( $lbConf );
56 },
57
58 'DBLoadBalancer' => function( MediaWikiServices $services ) {
59 // just return the default LB from the DBLoadBalancerFactory service
60 return $services->getDBLoadBalancerFactory()->getMainLB();
61 },
62
63 'SiteStore' => function( MediaWikiServices $services ) {
64 $rawSiteStore = new DBSiteStore( $services->getDBLoadBalancer() );
65
66 // TODO: replace wfGetCache with a CacheFactory service.
67 // TODO: replace wfIsHHVM with a capabilities service.
69
70 return new CachingSiteStore( $rawSiteStore, $cache );
71 },
72
73 'SiteLookup' => function( MediaWikiServices $services ) {
74 // Use the default SiteStore as the SiteLookup implementation for now
75 return $services->getSiteStore();
76 },
77
78 'ConfigFactory' => function( MediaWikiServices $services ) {
79 // Use the bootstrap config to initialize the ConfigFactory.
80 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
81 $factory = new ConfigFactory();
82
83 foreach ( $registry as $name => $callback ) {
84 $factory->register( $name, $callback );
85 }
86 return $factory;
87 },
88
89 'MainConfig' => function( MediaWikiServices $services ) {
90 // Use the 'main' config from the ConfigFactory service.
91 return $services->getConfigFactory()->makeConfig( 'main' );
92 },
93
94 'InterwikiLookup' => function( MediaWikiServices $services ) {
95 global $wgContLang; // TODO: manage $wgContLang as a service
96 $config = $services->getMainConfig();
97 return new ClassicInterwikiLookup(
99 ObjectCache::getMainWANInstance(),
100 $config->get( 'InterwikiExpiry' ),
101 $config->get( 'InterwikiCache' ),
102 $config->get( 'InterwikiScopes' ),
103 $config->get( 'InterwikiFallbackSite' )
104 );
105 },
106
107 'StatsdDataFactory' => function( MediaWikiServices $services ) {
109 rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
110 );
111 },
112
113 'EventRelayerGroup' => function( MediaWikiServices $services ) {
114 return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
115 },
116
117 'SearchEngineFactory' => function( MediaWikiServices $services ) {
118 return new SearchEngineFactory( $services->getSearchEngineConfig() );
119 },
120
121 'SearchEngineConfig' => function( MediaWikiServices $services ) {
123 return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
124 },
125
126 'SkinFactory' => function( MediaWikiServices $services ) {
127 $factory = new SkinFactory();
128
129 $names = $services->getMainConfig()->get( 'ValidSkinNames' );
130
131 foreach ( $names as $name => $skin ) {
132 $factory->register( $name, $skin, function () use ( $name, $skin ) {
133 $class = "Skin$skin";
134 return new $class( $name );
135 } );
136 }
137 // Register a hidden "fallback" skin
138 $factory->register( 'fallback', 'Fallback', function () {
139 return new SkinFallback;
140 } );
141 // Register a hidden skin for api output
142 $factory->register( 'apioutput', 'ApiOutput', function () {
143 return new SkinApi;
144 } );
145
146 return $factory;
147 },
148
149 'WatchedItemStore' => function( MediaWikiServices $services ) {
150 $store = new WatchedItemStore(
151 $services->getDBLoadBalancer(),
152 new HashBagOStuff( [ 'maxKeys' => 100 ] )
153 );
154 $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
155 return $store;
156 },
157
158 'WatchedItemQueryService' => function( MediaWikiServices $services ) {
159 return new WatchedItemQueryService( $services->getDBLoadBalancer() );
160 },
161
162 'CryptRand' => function( MediaWikiServices $services ) {
163 $secretKey = $services->getMainConfig()->get( 'SecretKey' );
164 return new CryptRand(
165 [
166 // To try vary the system information of the state a bit more
167 // by including the system's hostname into the state
168 'wfHostname',
169 // It's mostly worthless but throw the wiki's id into the data
170 // for a little more variance
171 'wfWikiID',
172 // If we have a secret key set then throw it into the state as well
173 function() use ( $secretKey ) {
174 return $secretKey ?: '';
175 }
176 ],
177 // The config file is likely the most often edited file we know should
178 // be around so include its stat info into the state.
179 // The constant with its location will almost always be defined, as
180 // WebStart.php defines MW_CONFIG_FILE to $IP/LocalSettings.php unless
181 // being configured with MW_CONFIG_CALLBACK (e.g. the installer).
182 defined( 'MW_CONFIG_FILE' ) ? [ MW_CONFIG_FILE ] : [],
183 LoggerFactory::getInstance( 'CryptRand' )
184 );
185 },
186
187 'CryptHKDF' => function( MediaWikiServices $services ) {
188 $config = $services->getMainConfig();
189
190 $secret = $config->get( 'HKDFSecret' ) ?: $config->get( 'SecretKey' );
191 if ( !$secret ) {
192 throw new RuntimeException( "Cannot use MWCryptHKDF without a secret." );
193 }
194
195 // In HKDF, the context can be known to the attacker, but this will
196 // keep simultaneous runs from producing the same output.
197 $context = [ microtime(), getmypid(), gethostname() ];
198
199 // Setup salt cache. Use APC, or fallback to the main cache if it isn't setup
200 $cache = $services->getLocalServerObjectCache();
201 if ( $cache instanceof EmptyBagOStuff ) {
203 }
204
205 return new CryptHKDF( $secret, $config->get( 'HKDFAlgorithm' ),
206 $cache, $context, $services->getCryptRand()
207 );
208 },
209
210 'MediaHandlerFactory' => function( MediaWikiServices $services ) {
211 return new MediaHandlerFactory(
212 $services->getMainConfig()->get( 'MediaHandlers' )
213 );
214 },
215
216 'MimeAnalyzer' => function( MediaWikiServices $services ) {
217 return new MimeMagic(
219 [],
220 $services->getMainConfig()
221 )
222 );
223 },
224
225 'ProxyLookup' => function( MediaWikiServices $services ) {
226 $mainConfig = $services->getMainConfig();
227 return new ProxyLookup(
228 $mainConfig->get( 'SquidServers' ),
229 $mainConfig->get( 'SquidServersNoPurge' )
230 );
231 },
232
233 'LinkCache' => function( MediaWikiServices $services ) {
234 return new LinkCache(
235 $services->getTitleFormatter(),
236 ObjectCache::getMainWANInstance()
237 );
238 },
239
240 'LinkRendererFactory' => function( MediaWikiServices $services ) {
241 return new LinkRendererFactory(
242 $services->getTitleFormatter(),
243 $services->getLinkCache()
244 );
245 },
246
247 'LinkRenderer' => function( MediaWikiServices $services ) {
249
250 if ( defined( 'MW_NO_SESSION' ) ) {
251 return $services->getLinkRendererFactory()->create();
252 } else {
253 return $services->getLinkRendererFactory()->createForUser( $wgUser );
254 }
255 },
256
257 'GenderCache' => function( MediaWikiServices $services ) {
258 return new GenderCache();
259 },
260
261 '_MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
263
264 return new MediaWikiTitleCodec(
266 $services->getGenderCache(),
267 $services->getMainConfig()->get( 'LocalInterwikis' )
268 );
269 },
270
271 'TitleFormatter' => function( MediaWikiServices $services ) {
272 return $services->getService( '_MediaWikiTitleCodec' );
273 },
274
275 'TitleParser' => function( MediaWikiServices $services ) {
276 return $services->getService( '_MediaWikiTitleCodec' );
277 },
278
279 'MainObjectStash' => function( MediaWikiServices $services ) {
280 $mainConfig = $services->getMainConfig();
281
282 $id = $mainConfig->get( 'MainStash' );
283 if ( !isset( $mainConfig->get( 'ObjectCaches' )[$id] ) ) {
284 throw new UnexpectedValueException(
285 "Cache type \"$id\" is not present in \$wgObjectCaches." );
286 }
287
288 return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] );
289 },
290
291 'MainWANObjectCache' => function( MediaWikiServices $services ) {
292 $mainConfig = $services->getMainConfig();
293
294 $id = $mainConfig->get( 'MainWANCache' );
295 if ( !isset( $mainConfig->get( 'WANObjectCaches' )[$id] ) ) {
296 throw new UnexpectedValueException(
297 "WAN cache type \"$id\" is not present in \$wgWANObjectCaches." );
298 }
299
300 $params = $mainConfig->get( 'WANObjectCaches' )[$id];
301 $objectCacheId = $params['cacheId'];
302 if ( !isset( $mainConfig->get( 'ObjectCaches' )[$objectCacheId] ) ) {
303 throw new UnexpectedValueException(
304 "Cache type \"$objectCacheId\" is not present in \$wgObjectCaches." );
305 }
306 $params['store'] = $mainConfig->get( 'ObjectCaches' )[$objectCacheId];
307
308 return \ObjectCache::newWANCacheFromParams( $params );
309 },
310
311 'LocalServerObjectCache' => function( MediaWikiServices $services ) {
312 $mainConfig = $services->getMainConfig();
313
314 if ( function_exists( 'apc_fetch' ) ) {
315 $id = 'apc';
316 } elseif ( function_exists( 'apcu_fetch' ) ) {
317 $id = 'apcu';
318 } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
319 $id = 'xcache';
320 } elseif ( function_exists( 'wincache_ucache_get' ) ) {
321 $id = 'wincache';
322 } else {
323 $id = CACHE_NONE;
324 }
325
326 if ( !isset( $mainConfig->get( 'ObjectCaches' )[$id] ) ) {
327 throw new UnexpectedValueException(
328 "Cache type \"$id\" is not present in \$wgObjectCaches." );
329 }
330
331 return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] );
332 },
333
334 'VirtualRESTServiceClient' => function( MediaWikiServices $services ) {
335 $config = $services->getMainConfig()->get( 'VirtualRestConfig' );
336
337 $vrsClient = new VirtualRESTServiceClient( new MultiHttpClient( [] ) );
338 foreach ( $config['paths'] as $prefix => $serviceConfig ) {
339 $class = $serviceConfig['class'];
340 // Merge in the global defaults
341 $constructArg = isset( $serviceConfig['options'] )
342 ? $serviceConfig['options']
343 : [];
344 $constructArg += $config['global'];
345 // Make the VRS service available at the mount point
346 $vrsClient->mount( $prefix, [ 'class' => $class, 'config' => $constructArg ] );
347 }
348
349 return $vrsClient;
350 },
351
353 // NOTE: When adding a service here, don't forget to add a getter function
354 // in the MediaWikiServices class. The convenience getter should just call
355 // $this->getService( 'FooBarService' ).
357
358];
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
wfGetCache( $cacheType)
Get a specific cache object.
wfIsHHVM()
Check if we are running under HHVM.
$wgUser
Definition Setup.php:806
A factory for application metric data.
Factory class to create Config objects.
A BagOStuff object with no objects in it.
Factory class for spawning EventRelayer objects using configuration.
Caches user genders when needed to use correct namespace aliases.
Simple store for keeping values in an associative array for the current process.
Cache for article titles (prefixed DB keys) and ids linked from one source.
Definition LinkCache.php:31
static applyDefaultConfig(array $lbConf, Config $mainConfig)
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
Class to construct MediaHandler objects.
A codec for MediaWiki page titles.
InterwikiLookup implementing the "classic" interwiki storage (hardcoded up to MW 1....
Factory to create LinkRender objects.
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static applyDefaultParameters(array $params, Config $mainConfig)
Definition MimeMagic.php:38
Class to handle concurrent HTTP requests.
static getLocalClusterInstance()
Get the main cluster-local cache object.
Configuration handling class for SearchEngine.
Factory class for SearchEngine.
SkinTemplate class for API output.
Definition SkinApi.php:33
Factory class to create Skin objects.
SkinTemplate class for the fallback skin.
Virtual HTTP service client loosely styled after a Virtual File System.
Storage layer class for WatchedItems.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
const CACHE_NONE
Definition Defines.php:94
const CACHE_ANYTHING
Definition Defines.php:93
const CACHE_ACCEL
Definition Defines.php:97
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition hooks.txt:2207
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
Definition injection.txt:37
$context
Definition load.php:50
$cache
Definition mcc.php:33
$params