Map dummy language codes in sites
[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\MediaWikiServices;
41
42 return [
43 'DBLoadBalancerFactory' => function( MediaWikiServices $services ) {
44 $config = $services->getMainConfig()->get( 'LBFactoryConf' );
45
46 $class = LBFactory::getLBFactoryClass( $config );
47 if ( !isset( $config['readOnlyReason'] ) ) {
48 // TODO: replace the global wfConfiguredReadOnlyReason() with a service.
49 $config['readOnlyReason'] = wfConfiguredReadOnlyReason();
50 }
51
52 return new $class( $config );
53 },
54
55 'DBLoadBalancer' => function( MediaWikiServices $services ) {
56 // just return the default LB from the DBLoadBalancerFactory service
57 return $services->getDBLoadBalancerFactory()->getMainLB();
58 },
59
60 'SiteStore' => function( MediaWikiServices $services ) {
61 $rawSiteStore = new DBSiteStore( $services->getDBLoadBalancer() );
62 $rawSiteStore->setLanguageCodeMapping(
63 $services->getMainConfig()->get( 'DummyLanguageCodes' ) ?: []
64 );
65
66 // TODO: replace wfGetCache with a CacheFactory service.
67 // TODO: replace wfIsHHVM with a capabilities service.
68 $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING );
69
70 return new CachingSiteStore( $rawSiteStore, $cache );
71 },
72
73 'SiteLookup' => function( MediaWikiServices $services ) {
74 // Use the default SiteStore as the SiteLookup implementation for now
75 return $services->getSiteStore();
76 },
77
78 'ConfigFactory' => function( MediaWikiServices $services ) {
79 // Use the bootstrap config to initialize the ConfigFactory.
80 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
81 $factory = new ConfigFactory();
82
83 foreach ( $registry as $name => $callback ) {
84 $factory->register( $name, $callback );
85 }
86 return $factory;
87 },
88
89 'MainConfig' => function( MediaWikiServices $services ) {
90 // Use the 'main' config from the ConfigFactory service.
91 return $services->getConfigFactory()->makeConfig( 'main' );
92 },
93
94 'StatsdDataFactory' => function( MediaWikiServices $services ) {
95 return new BufferingStatsdDataFactory(
96 rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
97 );
98 },
99
100 'EventRelayerGroup' => function( MediaWikiServices $services ) {
101 return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
102 },
103
104 'SearchEngineFactory' => function( MediaWikiServices $services ) {
105 return new SearchEngineFactory( $services->getSearchEngineConfig() );
106 },
107
108 'SearchEngineConfig' => function( MediaWikiServices $services ) {
109 global $wgContLang;
110 return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
111 },
112
113 'SkinFactory' => function( MediaWikiServices $services ) {
114 $factory = new SkinFactory();
115
116 $names = $services->getMainConfig()->get( 'ValidSkinNames' );
117
118 foreach ( $names as $name => $skin ) {
119 $factory->register( $name, $skin, function () use ( $name, $skin ) {
120 $class = "Skin$skin";
121 return new $class( $name );
122 } );
123 }
124 // Register a hidden "fallback" skin
125 $factory->register( 'fallback', 'Fallback', function () {
126 return new SkinFallback;
127 } );
128 // Register a hidden skin for api output
129 $factory->register( 'apioutput', 'ApiOutput', function () {
130 return new SkinApi;
131 } );
132
133 return $factory;
134 },
135
136 'WatchedItemStore' => function( MediaWikiServices $services ) {
137 $store = new WatchedItemStore(
138 $services->getDBLoadBalancer(),
139 new HashBagOStuff( [ 'maxKeys' => 100 ] )
140 );
141 $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
142 return $store;
143 },
144
145 'LinkCache' => function( MediaWikiServices $services ) {
146 return new LinkCache(
147 $services->getTitleFormatter()
148 );
149 },
150
151 'GenderCache' => function( MediaWikiServices $services ) {
152 return new GenderCache();
153 },
154
155 '_MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
156 global $wgContLang;
157
158 return new MediaWikiTitleCodec(
159 $wgContLang,
160 $services->getGenderCache(),
161 $services->getMainConfig()->get( 'LocalInterwikis' )
162 );
163 },
164
165 'TitleFormatter' => function( MediaWikiServices $services ) {
166 return $services->getService( '_MediaWikiTitleCodec' );
167 },
168
169 'TitleParser' => function( MediaWikiServices $services ) {
170 return $services->getService( '_MediaWikiTitleCodec' );
171 },
172
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 ///////////////////////////////////////////////////////////////////////////
178
179 ];