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 'LinkCache' => function( MediaWikiServices
$services ) {
158 return new LinkCache(
159 $services->getTitleFormatter()
163 'LinkRendererFactory' => function( MediaWikiServices
$services ) {
164 return new LinkRendererFactory(
165 $services->getTitleFormatter()
169 'LinkRenderer' => function( MediaWikiServices
$services ) {
172 if ( defined( 'MW_NO_SESSION' ) ) {
173 return $services->getLinkRendererFactory()->create();
175 return $services->getLinkRendererFactory()->createForUser( $wgUser );
179 'GenderCache' => function( MediaWikiServices
$services ) {
180 return new GenderCache();
183 '_MediaWikiTitleCodec' => function( MediaWikiServices
$services ) {
186 return new MediaWikiTitleCodec(
188 $services->getGenderCache(),
189 $services->getMainConfig()->get( 'LocalInterwikis' )
193 'TitleFormatter' => function( MediaWikiServices
$services ) {
194 return $services->getService( '_MediaWikiTitleCodec' );
197 'TitleParser' => function( MediaWikiServices
$services ) {
198 return $services->getService( '_MediaWikiTitleCodec' );
201 ///////////////////////////////////////////////////////////////////////////
202 // NOTE: When adding a service here, don't forget to add a getter function
203 // in the MediaWikiServices class. The convenience getter should just call
204 // $this->getService( 'FooBarService' ).
205 ///////////////////////////////////////////////////////////////////////////