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() );
62 $rawSiteStore->setLanguageCodeMapping(
63 $services->getMainConfig()->get( 'DummyLanguageCodes' ) ?
: []
66 // TODO: replace wfGetCache with a CacheFactory service.
67 // TODO: replace wfIsHHVM with a capabilities service.
68 $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL
: CACHE_ANYTHING
);
70 return new CachingSiteStore( $rawSiteStore, $cache );
73 'SiteLookup' => function( MediaWikiServices
$services ) {
74 // Use the default SiteStore as the SiteLookup implementation for now
75 return $services->getSiteStore();
78 'ConfigFactory' => function( MediaWikiServices
$services ) {
79 // Use the bootstrap config to initialize the ConfigFactory.
80 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
81 $factory = new ConfigFactory();
83 foreach ( $registry as $name => $callback ) {
84 $factory->register( $name, $callback );
89 'MainConfig' => function( MediaWikiServices
$services ) {
90 // Use the 'main' config from the ConfigFactory service.
91 return $services->getConfigFactory()->makeConfig( 'main' );
94 'StatsdDataFactory' => function( MediaWikiServices
$services ) {
95 return new BufferingStatsdDataFactory(
96 rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
100 'EventRelayerGroup' => function( MediaWikiServices
$services ) {
101 return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
104 'SearchEngineFactory' => function( MediaWikiServices
$services ) {
105 return new SearchEngineFactory( $services->getSearchEngineConfig() );
108 'SearchEngineConfig' => function( MediaWikiServices
$services ) {
110 return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
113 'SkinFactory' => function( MediaWikiServices
$services ) {
114 $factory = new SkinFactory();
116 $names = $services->getMainConfig()->get( 'ValidSkinNames' );
118 foreach ( $names as $name => $skin ) {
119 $factory->register( $name, $skin, function () use ( $name, $skin ) {
120 $class = "Skin$skin";
121 return new $class( $name );
124 // Register a hidden "fallback" skin
125 $factory->register( 'fallback', 'Fallback', function () {
126 return new SkinFallback
;
128 // Register a hidden skin for api output
129 $factory->register( 'apioutput', 'ApiOutput', function () {
136 'WatchedItemStore' => function( MediaWikiServices
$services ) {
137 $store = new WatchedItemStore(
138 $services->getDBLoadBalancer(),
139 new HashBagOStuff( [ 'maxKeys' => 100 ] )
141 $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
145 'LinkCache' => function( MediaWikiServices
$services ) {
146 return new LinkCache(
147 $services->getTitleFormatter()
151 'GenderCache' => function( MediaWikiServices
$services ) {
152 return new GenderCache();
155 '_MediaWikiTitleCodec' => function( MediaWikiServices
$services ) {
158 return new MediaWikiTitleCodec(
160 $services->getGenderCache(),
161 $services->getMainConfig()->get( 'LocalInterwikis' )
165 'TitleFormatter' => function( MediaWikiServices
$services ) {
166 return $services->getService( '_MediaWikiTitleCodec' );
169 'TitleParser' => function( MediaWikiServices
$services ) {
170 return $services->getService( '_MediaWikiTitleCodec' );
173 ///////////////////////////////////////////////////////////////////////////
174 // NOTE: When adding a service here, don't forget to add a getter function
175 // in the MediaWikiServices class. The convenience getter should just call
176 // $this->getService( 'FooBarService' ).
177 ///////////////////////////////////////////////////////////////////////////