Merge "Flag internal page retrieve/save cycles with EDIT_INTERNAL"
[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\Linker\LinkRendererFactory;
42 use MediaWiki\MediaWikiServices;
43
44 return [
45 'DBLoadBalancerFactory' => function( MediaWikiServices $services ) {
46 $config = $services->getMainConfig()->get( 'LBFactoryConf' );
47
48 $class = LBFactory::getLBFactoryClass( $config );
49 if ( !isset( $config['readOnlyReason'] ) ) {
50 // TODO: replace the global wfConfiguredReadOnlyReason() with a service.
51 $config['readOnlyReason'] = wfConfiguredReadOnlyReason();
52 }
53
54 return new $class( $config );
55 },
56
57 'DBLoadBalancer' => function( MediaWikiServices $services ) {
58 // just return the default LB from the DBLoadBalancerFactory service
59 return $services->getDBLoadBalancerFactory()->getMainLB();
60 },
61
62 'SiteStore' => function( MediaWikiServices $services ) {
63 $rawSiteStore = new DBSiteStore( $services->getDBLoadBalancer() );
64 $rawSiteStore->setLanguageCodeMapping(
65 $services->getMainConfig()->get( 'DummyLanguageCodes' ) ?: []
66 );
67
68 // TODO: replace wfGetCache with a CacheFactory service.
69 // TODO: replace wfIsHHVM with a capabilities service.
70 $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING );
71
72 return new CachingSiteStore( $rawSiteStore, $cache );
73 },
74
75 'SiteLookup' => function( MediaWikiServices $services ) {
76 // Use the default SiteStore as the SiteLookup implementation for now
77 return $services->getSiteStore();
78 },
79
80 'ConfigFactory' => function( MediaWikiServices $services ) {
81 // Use the bootstrap config to initialize the ConfigFactory.
82 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
83 $factory = new ConfigFactory();
84
85 foreach ( $registry as $name => $callback ) {
86 $factory->register( $name, $callback );
87 }
88 return $factory;
89 },
90
91 'MainConfig' => function( MediaWikiServices $services ) {
92 // Use the 'main' config from the ConfigFactory service.
93 return $services->getConfigFactory()->makeConfig( 'main' );
94 },
95
96 'InterwikiLookup' => function( MediaWikiServices $services ) {
97 global $wgContLang; // TODO: manage $wgContLang as a service
98 $config = $services->getMainConfig();
99 return new ClassicInterwikiLookup(
100 $wgContLang,
101 ObjectCache::getMainWANInstance(),
102 $config->get( 'InterwikiExpiry' ),
103 $config->get( 'InterwikiCache' ),
104 $config->get( 'InterwikiScopes' ),
105 $config->get( 'InterwikiFallbackSite' )
106 );
107 },
108
109 'StatsdDataFactory' => function( MediaWikiServices $services ) {
110 return new BufferingStatsdDataFactory(
111 rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
112 );
113 },
114
115 'EventRelayerGroup' => function( MediaWikiServices $services ) {
116 return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
117 },
118
119 'SearchEngineFactory' => function( MediaWikiServices $services ) {
120 return new SearchEngineFactory( $services->getSearchEngineConfig() );
121 },
122
123 'SearchEngineConfig' => function( MediaWikiServices $services ) {
124 global $wgContLang;
125 return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
126 },
127
128 'SkinFactory' => function( MediaWikiServices $services ) {
129 $factory = new SkinFactory();
130
131 $names = $services->getMainConfig()->get( 'ValidSkinNames' );
132
133 foreach ( $names as $name => $skin ) {
134 $factory->register( $name, $skin, function () use ( $name, $skin ) {
135 $class = "Skin$skin";
136 return new $class( $name );
137 } );
138 }
139 // Register a hidden "fallback" skin
140 $factory->register( 'fallback', 'Fallback', function () {
141 return new SkinFallback;
142 } );
143 // Register a hidden skin for api output
144 $factory->register( 'apioutput', 'ApiOutput', function () {
145 return new SkinApi;
146 } );
147
148 return $factory;
149 },
150
151 'WatchedItemStore' => function( MediaWikiServices $services ) {
152 $store = new WatchedItemStore(
153 $services->getDBLoadBalancer(),
154 new HashBagOStuff( [ 'maxKeys' => 100 ] )
155 );
156 $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
157 return $store;
158 },
159
160 'LinkCache' => function( MediaWikiServices $services ) {
161 return new LinkCache(
162 $services->getTitleFormatter()
163 );
164 },
165
166 'LinkRendererFactory' => function( MediaWikiServices $services ) {
167 return new LinkRendererFactory(
168 $services->getTitleFormatter()
169 );
170 },
171
172 'LinkRenderer' => function( MediaWikiServices $services ) {
173 global $wgUser;
174
175 if ( defined( 'MW_NO_SESSION' ) ) {
176 return $services->getLinkRendererFactory()->create();
177 } else {
178 return $services->getLinkRendererFactory()->createForUser( $wgUser );
179 }
180 },
181
182 'GenderCache' => function( MediaWikiServices $services ) {
183 return new GenderCache();
184 },
185
186 '_MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
187 global $wgContLang;
188
189 return new MediaWikiTitleCodec(
190 $wgContLang,
191 $services->getGenderCache(),
192 $services->getMainConfig()->get( 'LocalInterwikis' )
193 );
194 },
195
196 'TitleFormatter' => function( MediaWikiServices $services ) {
197 return $services->getService( '_MediaWikiTitleCodec' );
198 },
199
200 'TitleParser' => function( MediaWikiServices $services ) {
201 return $services->getService( '_MediaWikiTitleCodec' );
202 },
203
204 ///////////////////////////////////////////////////////////////////////////
205 // NOTE: When adding a service here, don't forget to add a getter function
206 // in the MediaWikiServices class. The convenience getter should just call
207 // $this->getService( 'FooBarService' ).
208 ///////////////////////////////////////////////////////////////////////////
209
210 ];