Merge "Localisation updates from https://translatewiki.net."
[lhc/web/wiklou.git] / includes / ServiceWiring.php
1 <?php
2 /**
3 * Default wiring for MediaWiki services.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 *
22 * This file is loaded by MediaWiki\MediaWikiServices::getInstance() during the
23 * bootstrapping of the dependency injection framework.
24 *
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
28 * this file.
29 *
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.
33 *
34 * @since 1.27
35 *
36 * @see docs/injection.txt for an overview of using dependency injection in the
37 * MediaWiki code base.
38 */
39
40 use MediaWiki\Interwiki\ClassicInterwikiLookup;
41 use MediaWiki\MediaWikiServices;
42
43 return [
44 'DBLoadBalancerFactory' => function( MediaWikiServices $services ) {
45 $config = $services->getMainConfig()->get( 'LBFactoryConf' );
46
47 $class = LBFactory::getLBFactoryClass( $config );
48 if ( !isset( $config['readOnlyReason'] ) ) {
49 // TODO: replace the global wfConfiguredReadOnlyReason() with a service.
50 $config['readOnlyReason'] = wfConfiguredReadOnlyReason();
51 }
52
53 return new $class( $config );
54 },
55
56 'DBLoadBalancer' => function( MediaWikiServices $services ) {
57 // just return the default LB from the DBLoadBalancerFactory service
58 return $services->getDBLoadBalancerFactory()->getMainLB();
59 },
60
61 'SiteStore' => function( MediaWikiServices $services ) {
62 $rawSiteStore = new DBSiteStore( $services->getDBLoadBalancer() );
63
64 // TODO: replace wfGetCache with a CacheFactory service.
65 // TODO: replace wfIsHHVM with a capabilities service.
66 $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING );
67
68 return new CachingSiteStore( $rawSiteStore, $cache );
69 },
70
71 'SiteLookup' => function( MediaWikiServices $services ) {
72 // Use the default SiteStore as the SiteLookup implementation for now
73 return $services->getSiteStore();
74 },
75
76 'ConfigFactory' => function( MediaWikiServices $services ) {
77 // Use the bootstrap config to initialize the ConfigFactory.
78 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
79 $factory = new ConfigFactory();
80
81 foreach ( $registry as $name => $callback ) {
82 $factory->register( $name, $callback );
83 }
84 return $factory;
85 },
86
87 'MainConfig' => function( MediaWikiServices $services ) {
88 // Use the 'main' config from the ConfigFactory service.
89 return $services->getConfigFactory()->makeConfig( 'main' );
90 },
91
92 'InterwikiLookup' => function( MediaWikiServices $services ) {
93 global $wgContLang; // TODO: manage $wgContLang as a service
94 $config = $services->getMainConfig();
95 return new ClassicInterwikiLookup(
96 $wgContLang,
97 ObjectCache::getMainWANInstance(),
98 $config->get( 'InterwikiExpiry' ),
99 $config->get( 'InterwikiCache' ),
100 $config->get( 'InterwikiScopes' ),
101 $config->get( 'InterwikiFallbackSite' )
102 );
103 },
104
105 'StatsdDataFactory' => function( MediaWikiServices $services ) {
106 return new BufferingStatsdDataFactory(
107 rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
108 );
109 },
110
111 'EventRelayerGroup' => function( MediaWikiServices $services ) {
112 return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
113 },
114
115 'SearchEngineFactory' => function( MediaWikiServices $services ) {
116 return new SearchEngineFactory( $services->getSearchEngineConfig() );
117 },
118
119 'SearchEngineConfig' => function( MediaWikiServices $services ) {
120 global $wgContLang;
121 return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
122 },
123
124 'SkinFactory' => function( MediaWikiServices $services ) {
125 $factory = new SkinFactory();
126
127 $names = $services->getMainConfig()->get( 'ValidSkinNames' );
128
129 foreach ( $names as $name => $skin ) {
130 $factory->register( $name, $skin, function () use ( $name, $skin ) {
131 $class = "Skin$skin";
132 return new $class( $name );
133 } );
134 }
135 // Register a hidden "fallback" skin
136 $factory->register( 'fallback', 'Fallback', function () {
137 return new SkinFallback;
138 } );
139 // Register a hidden skin for api output
140 $factory->register( 'apioutput', 'ApiOutput', function () {
141 return new SkinApi;
142 } );
143
144 return $factory;
145 },
146
147 'WatchedItemStore' => function( MediaWikiServices $services ) {
148 $store = new WatchedItemStore(
149 $services->getDBLoadBalancer(),
150 new HashBagOStuff( [ 'maxKeys' => 100 ] )
151 );
152 $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
153 return $store;
154 },
155
156 'LinkCache' => function( MediaWikiServices $services ) {
157 return new LinkCache(
158 $services->getTitleFormatter()
159 );
160 },
161
162 'GenderCache' => function( MediaWikiServices $services ) {
163 return new GenderCache();
164 },
165
166 '_MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
167 global $wgContLang;
168
169 return new MediaWikiTitleCodec(
170 $wgContLang,
171 $services->getGenderCache(),
172 $services->getMainConfig()->get( 'LocalInterwikis' )
173 );
174 },
175
176 'TitleFormatter' => function( MediaWikiServices $services ) {
177 return $services->getService( '_MediaWikiTitleCodec' );
178 },
179
180 'TitleParser' => function( MediaWikiServices $services ) {
181 return $services->getService( '_MediaWikiTitleCodec' );
182 },
183
184 ///////////////////////////////////////////////////////////////////////////
185 // NOTE: When adding a service here, don't forget to add a getter function
186 // in the MediaWikiServices class. The convenience getter should just call
187 // $this->getService( 'FooBarService' ).
188 ///////////////////////////////////////////////////////////////////////////
189
190 ];