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\Interwiki\ClassicInterwikiLookup
;
41 use MediaWiki\Linker\LinkRendererFactory
;
42 use MediaWiki\MediaWikiServices
;
45 'DBLoadBalancerFactory' => function( MediaWikiServices
$services ) {
46 $config = $services->getMainConfig()->get( 'LBFactoryConf' );
48 $class = LBFactory
::getLBFactoryClass( $config );
49 if ( !isset( $config['readOnlyReason'] ) ) {
50 // TODO: replace the global wfConfiguredReadOnlyReason() with a service.
51 $config['readOnlyReason'] = wfConfiguredReadOnlyReason();
54 return new $class( $config );
57 'DBLoadBalancer' => function( MediaWikiServices
$services ) {
58 // just return the default LB from the DBLoadBalancerFactory service
59 return $services->getDBLoadBalancerFactory()->getMainLB();
62 'SiteStore' => function( MediaWikiServices
$services ) {
63 $rawSiteStore = new DBSiteStore( $services->getDBLoadBalancer() );
65 // TODO: replace wfGetCache with a CacheFactory service.
66 // TODO: replace wfIsHHVM with a capabilities service.
67 $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL
: CACHE_ANYTHING
);
69 return new CachingSiteStore( $rawSiteStore, $cache );
72 'SiteLookup' => function( MediaWikiServices
$services ) {
73 // Use the default SiteStore as the SiteLookup implementation for now
74 return $services->getSiteStore();
77 'ConfigFactory' => function( MediaWikiServices
$services ) {
78 // Use the bootstrap config to initialize the ConfigFactory.
79 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
80 $factory = new ConfigFactory();
82 foreach ( $registry as $name => $callback ) {
83 $factory->register( $name, $callback );
88 'MainConfig' => function( MediaWikiServices
$services ) {
89 // Use the 'main' config from the ConfigFactory service.
90 return $services->getConfigFactory()->makeConfig( 'main' );
93 'InterwikiLookup' => function( MediaWikiServices
$services ) {
94 global $wgContLang; // TODO: manage $wgContLang as a service
95 $config = $services->getMainConfig();
96 return new ClassicInterwikiLookup(
98 ObjectCache
::getMainWANInstance(),
99 $config->get( 'InterwikiExpiry' ),
100 $config->get( 'InterwikiCache' ),
101 $config->get( 'InterwikiScopes' ),
102 $config->get( 'InterwikiFallbackSite' )
106 'StatsdDataFactory' => function( MediaWikiServices
$services ) {
107 return new BufferingStatsdDataFactory(
108 rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
112 'EventRelayerGroup' => function( MediaWikiServices
$services ) {
113 return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
116 'SearchEngineFactory' => function( MediaWikiServices
$services ) {
117 return new SearchEngineFactory( $services->getSearchEngineConfig() );
120 'SearchEngineConfig' => function( MediaWikiServices
$services ) {
122 return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
125 'SkinFactory' => function( MediaWikiServices
$services ) {
126 $factory = new SkinFactory();
128 $names = $services->getMainConfig()->get( 'ValidSkinNames' );
130 foreach ( $names as $name => $skin ) {
131 $factory->register( $name, $skin, function () use ( $name, $skin ) {
132 $class = "Skin$skin";
133 return new $class( $name );
136 // Register a hidden "fallback" skin
137 $factory->register( 'fallback', 'Fallback', function () {
138 return new SkinFallback
;
140 // Register a hidden skin for api output
141 $factory->register( 'apioutput', 'ApiOutput', function () {
148 'WatchedItemStore' => function( MediaWikiServices
$services ) {
149 $store = new WatchedItemStore(
150 $services->getDBLoadBalancer(),
151 new HashBagOStuff( [ 'maxKeys' => 100 ] )
153 $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
157 'WatchedItemQueryService' => function( MediaWikiServices
$services ) {
158 return new WatchedItemQueryService( $services->getDBLoadBalancer() );
161 'LinkCache' => function( MediaWikiServices
$services ) {
162 return new LinkCache(
163 $services->getTitleFormatter()
167 'LinkRendererFactory' => function( MediaWikiServices
$services ) {
168 return new LinkRendererFactory(
169 $services->getTitleFormatter()
173 'LinkRenderer' => function( MediaWikiServices
$services ) {
176 if ( defined( 'MW_NO_SESSION' ) ) {
177 return $services->getLinkRendererFactory()->create();
179 return $services->getLinkRendererFactory()->createForUser( $wgUser );
183 'GenderCache' => function( MediaWikiServices
$services ) {
184 return new GenderCache();
187 '_MediaWikiTitleCodec' => function( MediaWikiServices
$services ) {
190 return new MediaWikiTitleCodec(
192 $services->getGenderCache(),
193 $services->getMainConfig()->get( 'LocalInterwikis' )
197 'TitleFormatter' => function( MediaWikiServices
$services ) {
198 return $services->getService( '_MediaWikiTitleCodec' );
201 'TitleParser' => function( MediaWikiServices
$services ) {
202 return $services->getService( '_MediaWikiTitleCodec' );
205 ///////////////////////////////////////////////////////////////////////////
206 // NOTE: When adding a service here, don't forget to add a getter function
207 // in the MediaWikiServices class. The convenience getter should just call
208 // $this->getService( 'FooBarService' ).
209 ///////////////////////////////////////////////////////////////////////////