MediaWiki  1.28.0
ServiceWiring.php
Go to the documentation of this file.
1 <?php
44 
45 return [
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(
98  $wgContLang,
100  $config->get( 'InterwikiExpiry' ),
101  $config->get( 'InterwikiCache' ),
102  $config->get( 'InterwikiScopes' ),
103  $config->get( 'InterwikiFallbackSite' )
104  );
105  },
106 
107  'StatsdDataFactory' => function( MediaWikiServices $services ) {
108  return new BufferingStatsdDataFactory(
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(),
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 ) {
248  global $wgUser;
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(
265  $wgContLang,
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 ];
static applyDefaultParameters(array $params, Config $mainConfig)
Definition: MimeMagic.php:38
A factory for application metric data.
A codec for MediaWiki page titles.
static getMainWANInstance()
Get the main WAN cache object.
$context
Definition: load.php:50
wfIsHHVM()
Check if we are running under HHVM.
const CACHE_ACCEL
Definition: Defines.php:97
SkinTemplate class for API output.
Definition: SkinApi.php:33
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static getLocalClusterInstance()
Get the main cluster-local cache object.
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 MediaWikiServices
Definition: injection.txt:23
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
InterwikiLookup implementing the "classic" interwiki storage (hardcoded up to MW 1.26).
wfGetCache($cacheType)
Get a specific cache object.
wfIniGetBool($setting)
Safety wrapper around ini_get() for boolean settings.
$cache
Definition: mcc.php:33
$params
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1936
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:2159
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
SkinTemplate class for the fallback skin.
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:35
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
const CACHE_ANYTHING
Definition: Defines.php:93
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:56
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method.MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances.The"Spi"in MediaWiki\Logger\Spi stands for"service provider interface".An SPI is an API intended to be implemented or extended by a third party.This software design pattern is intended to enable framework extension and replaceable components.It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki.The service provider interface allows the backend logging library to be implemented in multiple ways.The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime.This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance.Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
Factory to create LinkRender objects.
Class to handle concurrent HTTP requests.
const CACHE_NONE
Definition: Defines.php:94
MediaWikiServices is the service locator for the application scope of MediaWiki.
static applyDefaultConfig(array $lbConf, Config $mainConfig)
Definition: MWLBFactory.php:37
$wgUser
Definition: Setup.php:806
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300