3 * Default wiring for MediaWiki services.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 * This file is loaded by MediaWiki\MediaWikiServices::getInstance() during the
23 * bootstrapping of the dependency injection framework.
25 * This file returns an array that associates service name with instantiator functions
26 * that create the default instances for the services used by MediaWiki core.
27 * For every service that MediaWiki core requires, an instantiator must be defined in
30 * @note As of version 1.27, MediaWiki is only beginning to use dependency injection.
31 * The services defined here do not yet fully represent all services used by core,
32 * much of the code still relies on global state for this accessing services.
36 * @see docs/injection.txt for an overview of using dependency injection in the
37 * MediaWiki code base.
40 use MediaWiki\MediaWikiServices
;
43 'DBLoadBalancerFactory' => function( MediaWikiServices
$services ) {
44 $config = $services->getMainConfig()->get( 'LBFactoryConf' );
46 $class = LBFactory
::getLBFactoryClass( $config );
47 if ( !isset( $config['readOnlyReason'] ) ) {
48 // TODO: replace the global wfConfiguredReadOnlyReason() with a service.
49 $config['readOnlyReason'] = wfConfiguredReadOnlyReason();
52 return new $class( $config );
55 'DBLoadBalancer' => function( MediaWikiServices
$services ) {
56 // just return the default LB from the DBLoadBalancerFactory service
57 return $services->getDBLoadBalancerFactory()->getMainLB();
60 'SiteStore' => function( MediaWikiServices
$services ) {
61 $rawSiteStore = new DBSiteStore( $services->getDBLoadBalancer() );
63 // TODO: replace wfGetCache with a CacheFactory service.
64 // TODO: replace wfIsHHVM with a capabilities service.
65 $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL
: CACHE_ANYTHING
);
67 return new CachingSiteStore( $rawSiteStore, $cache );
70 'SiteLookup' => function( MediaWikiServices
$services ) {
71 // Use the default SiteStore as the SiteLookup implementation for now
72 return $services->getSiteStore();
75 'ConfigFactory' => function( MediaWikiServices
$services ) {
76 // Use the bootstrap config to initialize the ConfigFactory.
77 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
78 $factory = new ConfigFactory();
80 foreach ( $registry as $name => $callback ) {
81 $factory->register( $name, $callback );
86 'MainConfig' => function( MediaWikiServices
$services ) {
87 // Use the 'main' config from the ConfigFactory service.
88 return $services->getConfigFactory()->makeConfig( 'main' );
91 'StatsdDataFactory' => function( MediaWikiServices
$services ) {
92 return new BufferingStatsdDataFactory(
93 rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
97 'EventRelayerGroup' => function( MediaWikiServices
$services ) {
98 return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
101 'SearchEngineFactory' => function( MediaWikiServices
$services ) {
102 return new SearchEngineFactory( $services->getSearchEngineConfig() );
105 'SearchEngineConfig' => function( MediaWikiServices
$services ) {
107 return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
110 'SkinFactory' => function( MediaWikiServices
$services ) {
111 $factory = new SkinFactory();
113 $names = $services->getMainConfig()->get( 'ValidSkinNames' );
115 foreach ( $names as $name => $skin ) {
116 $factory->register( $name, $skin, function () use ( $name, $skin ) {
117 $class = "Skin$skin";
118 return new $class( $name );
121 // Register a hidden "fallback" skin
122 $factory->register( 'fallback', 'Fallback', function () {
123 return new SkinFallback
;
125 // Register a hidden skin for api output
126 $factory->register( 'apioutput', 'ApiOutput', function () {
133 'WatchedItemStore' => function( MediaWikiServices
$services ) {
134 $store = new WatchedItemStore(
135 $services->getDBLoadBalancer(),
136 new HashBagOStuff( [ 'maxKeys' => 100 ] )
138 $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
142 'GenderCache' => function( MediaWikiServices
$services ) {
143 return new GenderCache();
146 ///////////////////////////////////////////////////////////////////////////
147 // NOTE: When adding a service here, don't forget to add a getter function
148 // in the MediaWikiServices class. The convenience getter should just call
149 // $this->getService( 'FooBarService' ).
150 ///////////////////////////////////////////////////////////////////////////