Merge "Re add @access protected on Title::__construct"
[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
63 // TODO: replace wfGetCache with a CacheFactory service.
64 // TODO: replace wfIsHHVM with a capabilities service.
65 $cache = wfGetCache( wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING );
66
67 return new CachingSiteStore( $rawSiteStore, $cache );
68 },
69
70 'SiteLookup' => function( MediaWikiServices $services ) {
71 // Use the default SiteStore as the SiteLookup implementation for now
72 return $services->getSiteStore();
73 },
74
75 'ConfigFactory' => function( MediaWikiServices $services ) {
76 // Use the bootstrap config to initialize the ConfigFactory.
77 $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
78 $factory = new ConfigFactory();
79
80 foreach ( $registry as $name => $callback ) {
81 $factory->register( $name, $callback );
82 }
83 return $factory;
84 },
85
86 'MainConfig' => function( MediaWikiServices $services ) {
87 // Use the 'main' config from the ConfigFactory service.
88 return $services->getConfigFactory()->makeConfig( 'main' );
89 },
90
91 'StatsdDataFactory' => function( MediaWikiServices $services ) {
92 return new BufferingStatsdDataFactory(
93 rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
94 );
95 },
96
97 'EventRelayerGroup' => function( MediaWikiServices $services ) {
98 return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
99 },
100
101 'SearchEngineFactory' => function( MediaWikiServices $services ) {
102 return new SearchEngineFactory( $services->getSearchEngineConfig() );
103 },
104
105 'SearchEngineConfig' => function( MediaWikiServices $services ) {
106 global $wgContLang;
107 return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
108 },
109
110 'SkinFactory' => function( MediaWikiServices $services ) {
111 $factory = new SkinFactory();
112
113 $names = $services->getMainConfig()->get( 'ValidSkinNames' );
114
115 foreach ( $names as $name => $skin ) {
116 $factory->register( $name, $skin, function () use ( $name, $skin ) {
117 $class = "Skin$skin";
118 return new $class( $name );
119 } );
120 }
121 // Register a hidden "fallback" skin
122 $factory->register( 'fallback', 'Fallback', function () {
123 return new SkinFallback;
124 } );
125 // Register a hidden skin for api output
126 $factory->register( 'apioutput', 'ApiOutput', function () {
127 return new SkinApi;
128 } );
129
130 return $factory;
131 },
132
133 'WatchedItemStore' => function( MediaWikiServices $services ) {
134 $store = new WatchedItemStore(
135 $services->getDBLoadBalancer(),
136 new HashBagOStuff( [ 'maxKeys' => 100 ] )
137 );
138 $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
139 return $store;
140 },
141
142 'GenderCache' => function( MediaWikiServices $services ) {
143 return new GenderCache();
144 },
145
146 '_MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
147 global $wgContLang;
148
149 return new MediaWikiTitleCodec(
150 $wgContLang,
151 $services->getGenderCache(),
152 $services->getMainConfig()->get( 'LocalInterwikis' )
153 );
154 },
155
156 'TitleFormatter' => function( MediaWikiServices $services ) {
157 return $services->getService( '_MediaWikiTitleCodec' );
158 },
159
160 'TitleParser' => function( MediaWikiServices $services ) {
161 return $services->getService( '_MediaWikiTitleCodec' );
162 },
163
164 ///////////////////////////////////////////////////////////////////////////
165 // NOTE: When adding a service here, don't forget to add a getter function
166 // in the MediaWikiServices class. The convenience getter should just call
167 // $this->getService( 'FooBarService' ).
168 ///////////////////////////////////////////////////////////////////////////
169
170 ];