MediaWiki  master
ServiceWiring.php
Go to the documentation of this file.
1 <?php
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 
65  // TODO: replace wfGetCache with a CacheFactory service.
66  // TODO: replace wfIsHHVM with a capabilities service.
68 
69  return new CachingSiteStore( $rawSiteStore, $cache );
70  },
71 
72  'SiteLookup' => function( MediaWikiServices $services ) {
73  // Use the default SiteStore as the SiteLookup implementation for now
74  return $services->getSiteStore();
75  },
76 
77  'ConfigFactory' => function( MediaWikiServices $services ) {
78  // Use the bootstrap config to initialize the ConfigFactory.
79  $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
80  $factory = new ConfigFactory();
81 
82  foreach ( $registry as $name => $callback ) {
83  $factory->register( $name, $callback );
84  }
85  return $factory;
86  },
87 
88  'MainConfig' => function( MediaWikiServices $services ) {
89  // Use the 'main' config from the ConfigFactory service.
90  return $services->getConfigFactory()->makeConfig( 'main' );
91  },
92 
93  'InterwikiLookup' => function( MediaWikiServices $services ) {
94  global $wgContLang; // TODO: manage $wgContLang as a service
95  $config = $services->getMainConfig();
96  return new ClassicInterwikiLookup(
97  $wgContLang,
99  $config->get( 'InterwikiExpiry' ),
100  $config->get( 'InterwikiCache' ),
101  $config->get( 'InterwikiScopes' ),
102  $config->get( 'InterwikiFallbackSite' )
103  );
104  },
105 
106  'StatsdDataFactory' => function( MediaWikiServices $services ) {
107  return new BufferingStatsdDataFactory(
108  rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
109  );
110  },
111 
112  'EventRelayerGroup' => function( MediaWikiServices $services ) {
113  return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
114  },
115 
116  'SearchEngineFactory' => function( MediaWikiServices $services ) {
117  return new SearchEngineFactory( $services->getSearchEngineConfig() );
118  },
119 
120  'SearchEngineConfig' => function( MediaWikiServices $services ) {
122  return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
123  },
124 
125  'SkinFactory' => function( MediaWikiServices $services ) {
126  $factory = new SkinFactory();
127 
128  $names = $services->getMainConfig()->get( 'ValidSkinNames' );
129 
130  foreach ( $names as $name => $skin ) {
131  $factory->register( $name, $skin, function () use ( $name, $skin ) {
132  $class = "Skin$skin";
133  return new $class( $name );
134  } );
135  }
136  // Register a hidden "fallback" skin
137  $factory->register( 'fallback', 'Fallback', function () {
138  return new SkinFallback;
139  } );
140  // Register a hidden skin for api output
141  $factory->register( 'apioutput', 'ApiOutput', function () {
142  return new SkinApi;
143  } );
144 
145  return $factory;
146  },
147 
148  'WatchedItemStore' => function( MediaWikiServices $services ) {
149  $store = new WatchedItemStore(
150  $services->getDBLoadBalancer(),
151  new HashBagOStuff( [ 'maxKeys' => 100 ] )
152  );
153  $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
154  return $store;
155  },
156 
157  'WatchedItemQueryService' => function( MediaWikiServices $services ) {
158  return new WatchedItemQueryService( $services->getDBLoadBalancer() );
159  },
160 
161  'LinkCache' => function( MediaWikiServices $services ) {
162  return new LinkCache(
163  $services->getTitleFormatter()
164  );
165  },
166 
167  'LinkRendererFactory' => function( MediaWikiServices $services ) {
168  return new LinkRendererFactory(
169  $services->getTitleFormatter(),
170  $services->getLinkCache()
171  );
172  },
173 
174  'LinkRenderer' => function( MediaWikiServices $services ) {
175  global $wgUser;
176 
177  if ( defined( 'MW_NO_SESSION' ) ) {
178  return $services->getLinkRendererFactory()->create();
179  } else {
180  return $services->getLinkRendererFactory()->createForUser( $wgUser );
181  }
182  },
183 
184  'GenderCache' => function( MediaWikiServices $services ) {
185  return new GenderCache();
186  },
187 
188  '_MediaWikiTitleCodec' => function( MediaWikiServices $services ) {
190 
191  return new MediaWikiTitleCodec(
192  $wgContLang,
193  $services->getGenderCache(),
194  $services->getMainConfig()->get( 'LocalInterwikis' )
195  );
196  },
197 
198  'TitleFormatter' => function( MediaWikiServices $services ) {
199  return $services->getService( '_MediaWikiTitleCodec' );
200  },
201 
202  'TitleParser' => function( MediaWikiServices $services ) {
203  return $services->getService( '_MediaWikiTitleCodec' );
204  },
205 
207  // NOTE: When adding a service here, don't forget to add a getter function
208  // in the MediaWikiServices class. The convenience getter should just call
209  // $this->getService( 'FooBarService' ).
211 
212 ];
A factory for application metric data.
A codec for MediaWiki page titles.
static getMainWANInstance()
Get the main WAN cache object.
Factory class to create Skin objects.
Definition: SkinFactory.php:31
wfIsHHVM()
Check if we are running under HHVM.
const CACHE_ACCEL
Definition: Defines.php:105
Factory class to create Config objects.
SkinTemplate class for API output.
Definition: SkinApi.php:33
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
Configuration handling class for SearchEngine.
InterwikiLookup implementing the "classic" interwiki storage (hardcoded up to MW 1.26).
Storage layer class for WatchedItems.
Factory class for spawning EventRelayer objects using configuration.
$factory
wfConfiguredReadOnlyReason()
Get the value of $wgReadOnly or the contents of $wgReadOnlyFile.
wfGetCache($cacheType)
Get a specific cache object.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1816
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place or wrap services the preferred way to define a new service is the $wgServiceWiringFiles array $services
Definition: hooks.txt:2044
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
SkinTemplate class for the fallback skin.
setStatsdDataFactory(StatsdDataFactoryInterface $stats)
Sets a StatsdDataFactory instance on the object.
Simple store for keeping values in an associative array for the current process.
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
Definition: LBFactory.php:100
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Factory class for SearchEngine.
Caches user genders when needed to use correct namespace aliases.
Definition: GenderCache.php:31
Cache for article titles (prefixed DB keys) and ids linked from one source.
Definition: LinkCache.php:31
const CACHE_ANYTHING
Definition: Defines.php:101
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
Factory to create LinkRender objects.
MediaWikiServices is the service locator for the application scope of MediaWiki.
$wgUser
Definition: Setup.php:801
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310