MediaWiki  master
ServiceWiring.php
Go to the documentation of this file.
1 <?php
87 
88 return [
89  'ActorMigration' => function ( MediaWikiServices $services ) : ActorMigration {
90  return new ActorMigration( SCHEMA_COMPAT_NEW );
91  },
92 
93  'BadFileLookup' => function ( MediaWikiServices $services ) : BadFileLookup {
94  return new BadFileLookup(
95  function () {
96  return wfMessage( 'bad_image_list' )->inContentLanguage()->plain();
97  },
98  $services->getLocalServerObjectCache(),
99  $services->getRepoGroup(),
100  $services->getTitleParser()
101  );
102  },
103 
104  'BlobStore' => function ( MediaWikiServices $services ) : BlobStore {
105  return $services->getService( '_SqlBlobStore' );
106  },
107 
108  'BlobStoreFactory' => function ( MediaWikiServices $services ) : BlobStoreFactory {
109  return new BlobStoreFactory(
110  $services->getDBLoadBalancerFactory(),
111  $services->getExternalStoreAccess(),
112  $services->getMainWANObjectCache(),
113  new ServiceOptions( BlobStoreFactory::CONSTRUCTOR_OPTIONS,
114  $services->getMainConfig() )
115  );
116  },
117 
118  'BlockErrorFormatter' => function () : BlockErrorFormatter {
119  return new BlockErrorFormatter();
120  },
121 
122  'BlockManager' => function ( MediaWikiServices $services ) : BlockManager {
123  return new BlockManager(
124  new ServiceOptions(
125  BlockManager::CONSTRUCTOR_OPTIONS, $services->getMainConfig()
126  ),
127  $services->getPermissionManager(),
128  LoggerFactory::getInstance( 'BlockManager' )
129  );
130  },
131 
132  'BlockRestrictionStore' => function ( MediaWikiServices $services ) : BlockRestrictionStore {
133  return new BlockRestrictionStore(
134  $services->getDBLoadBalancer()
135  );
136  },
137 
138  'CommentStore' => function ( MediaWikiServices $services ) : CommentStore {
139  return new CommentStore(
140  $services->getContentLanguage(),
142  );
143  },
144 
145  'ConfigFactory' => function ( MediaWikiServices $services ) : ConfigFactory {
146  // Use the bootstrap config to initialize the ConfigFactory.
147  $registry = $services->getBootstrapConfig()->get( 'ConfigRegistry' );
148  $factory = new ConfigFactory();
149 
150  foreach ( $registry as $name => $callback ) {
151  $factory->register( $name, $callback );
152  }
153  return $factory;
154  },
155 
156  'ConfigRepository' => function ( MediaWikiServices $services ) : ConfigRepository {
157  return new ConfigRepository( $services->getConfigFactory() );
158  },
159 
160  'ConfiguredReadOnlyMode' => function ( MediaWikiServices $services ) : ConfiguredReadOnlyMode {
161  $config = $services->getMainConfig();
162  return new ConfiguredReadOnlyMode(
163  $config->get( 'ReadOnly' ),
164  $config->get( 'ReadOnlyFile' )
165  );
166  },
167 
168  'ContentLanguage' => function ( MediaWikiServices $services ) : Language {
169  return Language::factory( $services->getMainConfig()->get( 'LanguageCode' ) );
170  },
171 
172  'CryptHKDF' => function ( MediaWikiServices $services ) : CryptHKDF {
173  $config = $services->getMainConfig();
174 
175  $secret = $config->get( 'HKDFSecret' ) ?: $config->get( 'SecretKey' );
176  if ( !$secret ) {
177  throw new RuntimeException( "Cannot use MWCryptHKDF without a secret." );
178  }
179 
180  // In HKDF, the context can be known to the attacker, but this will
181  // keep simultaneous runs from producing the same output.
182  $context = [ microtime(), getmypid(), gethostname() ];
183 
184  // Setup salt cache. Use APC, or fallback to the main cache if it isn't setup
185  $cache = $services->getLocalServerObjectCache();
186  if ( $cache instanceof EmptyBagOStuff ) {
188  }
189 
190  return new CryptHKDF( $secret, $config->get( 'HKDFAlgorithm' ), $cache, $context );
191  },
192 
193  'DateFormatterFactory' => function () : DateFormatterFactory {
194  return new DateFormatterFactory;
195  },
196 
197  'DBLoadBalancer' => function ( MediaWikiServices $services ) : Wikimedia\Rdbms\ILoadBalancer {
198  // just return the default LB from the DBLoadBalancerFactory service
199  return $services->getDBLoadBalancerFactory()->getMainLB();
200  },
201 
202  'DBLoadBalancerFactory' =>
203  function ( MediaWikiServices $services ) : Wikimedia\Rdbms\LBFactory {
204  $mainConfig = $services->getMainConfig();
205 
207  $mainConfig->get( 'LBFactoryConf' ),
208  new ServiceOptions( MWLBFactory::APPLY_DEFAULT_CONFIG_OPTIONS, $mainConfig ),
209  $services->getConfiguredReadOnlyMode(),
210  $services->getLocalServerObjectCache(),
211  $services->getMainObjectStash(),
212  $services->getMainWANObjectCache()
213  );
214  $class = MWLBFactory::getLBFactoryClass( $lbConf );
215 
216  return new $class( $lbConf );
217  },
218 
219  'EventRelayerGroup' => function ( MediaWikiServices $services ) : EventRelayerGroup {
220  return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
221  },
222 
223  'ExternalStoreAccess' => function ( MediaWikiServices $services ) : ExternalStoreAccess {
224  return new ExternalStoreAccess(
225  $services->getExternalStoreFactory(),
226  LoggerFactory::getInstance( 'ExternalStore' )
227  );
228  },
229 
230  'ExternalStoreFactory' => function ( MediaWikiServices $services ) : ExternalStoreFactory {
231  $config = $services->getMainConfig();
232  $writeStores = $config->get( 'DefaultExternalStore' );
233 
234  return new ExternalStoreFactory(
235  $config->get( 'ExternalStores' ),
236  ( $writeStores !== false ) ? (array)$writeStores : [],
237  $services->getDBLoadBalancer()->getLocalDomainID(),
238  LoggerFactory::getInstance( 'ExternalStore' )
239  );
240  },
241 
242  'GenderCache' => function ( MediaWikiServices $services ) : GenderCache {
243  $nsInfo = $services->getNamespaceInfo();
244  // Database layer may be disabled, so processing without database connection
245  $dbLoadBalancer = $services->isServiceDisabled( 'DBLoadBalancer' )
246  ? null
247  : $services->getDBLoadBalancer();
248  return new GenderCache( $nsInfo, $dbLoadBalancer );
249  },
250 
251  'HttpRequestFactory' =>
252  function ( MediaWikiServices $services ) : HttpRequestFactory {
253  return new HttpRequestFactory();
254  },
255 
256  'InterwikiLookup' => function ( MediaWikiServices $services ) : InterwikiLookup {
257  $config = $services->getMainConfig();
258  return new ClassicInterwikiLookup(
259  $services->getContentLanguage(),
260  $services->getMainWANObjectCache(),
261  $config->get( 'InterwikiExpiry' ),
262  $config->get( 'InterwikiCache' ),
263  $config->get( 'InterwikiScopes' ),
264  $config->get( 'InterwikiFallbackSite' )
265  );
266  },
267 
268  'LanguageFallback' => function ( MediaWikiServices $services ) : LanguageFallback {
269  return new LanguageFallback(
270  $services->getMainConfig()->get( 'LanguageCode' ),
271  $services->getLocalisationCache(),
272  $services->getLanguageNameUtils()
273  );
274  },
275 
276  'LanguageNameUtils' => function ( MediaWikiServices $services ) : LanguageNameUtils {
277  return new LanguageNameUtils( new ServiceOptions(
278  LanguageNameUtils::CONSTRUCTOR_OPTIONS,
279  $services->getMainConfig()
280  ) );
281  },
282 
283  'LinkCache' => function ( MediaWikiServices $services ) : LinkCache {
284  return new LinkCache(
285  $services->getTitleFormatter(),
286  $services->getMainWANObjectCache(),
287  $services->getNamespaceInfo()
288  );
289  },
290 
291  'LinkRenderer' => function ( MediaWikiServices $services ) : LinkRenderer {
292  if ( defined( 'MW_NO_SESSION' ) ) {
293  return $services->getLinkRendererFactory()->create();
294  } else {
295  // Normally information from the current request would not be passed in here;
296  // this is an exception. (See also the class documentation.)
297  return $services->getLinkRendererFactory()->createForUser(
299  );
300  }
301  },
302 
303  'LinkRendererFactory' => function ( MediaWikiServices $services ) : LinkRendererFactory {
304  return new LinkRendererFactory(
305  $services->getTitleFormatter(),
306  $services->getLinkCache(),
307  $services->getNamespaceInfo()
308  );
309  },
310 
311  'LocalisationCache' => function ( MediaWikiServices $services ) : LocalisationCache {
312  $conf = $services->getMainConfig()->get( 'LocalisationCacheConf' );
313 
314  $logger = LoggerFactory::getInstance( 'localisation' );
315 
317  $conf, $services->getMainConfig()->get( 'CacheDirectory' ) );
318  $logger->debug( 'LocalisationCache: using store ' . get_class( $store ) );
319 
320  return new $conf['class'](
321  new ServiceOptions(
322  LocalisationCache::CONSTRUCTOR_OPTIONS,
323  // Two of the options are stored in $wgLocalisationCacheConf
324  $conf,
325  // In case someone set that config variable and didn't reset all keys, set defaults.
326  [
327  'forceRecache' => false,
328  'manualRecache' => false,
329  ],
330  // Some other options come from config itself
331  $services->getMainConfig()
332  ),
333  $store,
334  $logger,
335  [ function () use ( $services ) {
336  $services->getResourceLoader()->getMessageBlobStore()->clear();
337  } ],
338  $services->getLanguageNameUtils()
339  );
340  },
341 
342  'LocalServerObjectCache' => function ( MediaWikiServices $services ) : BagOStuff {
343  $config = $services->getMainConfig();
345 
346  return ObjectCache::newFromParams( $config->get( 'ObjectCaches' )[$cacheId] );
347  },
348 
349  'LockManagerGroupFactory' => function ( MediaWikiServices $services ) : LockManagerGroupFactory {
350  return new LockManagerGroupFactory(
352  $services->getMainConfig()->get( 'LockManagers' ),
353  $services->getDBLoadBalancerFactory()
354  );
355  },
356 
357  'MagicWordFactory' => function ( MediaWikiServices $services ) : MagicWordFactory {
358  return new MagicWordFactory( $services->getContentLanguage() );
359  },
360 
361  'MainConfig' => function ( MediaWikiServices $services ) : Config {
362  // Use the 'main' config from the ConfigFactory service.
363  return $services->getConfigFactory()->makeConfig( 'main' );
364  },
365 
366  'MainObjectStash' => function ( MediaWikiServices $services ) : BagOStuff {
367  $mainConfig = $services->getMainConfig();
368 
369  $id = $mainConfig->get( 'MainStash' );
370  if ( !isset( $mainConfig->get( 'ObjectCaches' )[$id] ) ) {
371  throw new UnexpectedValueException(
372  "Cache type \"$id\" is not present in \$wgObjectCaches." );
373  }
374 
375  $params = $mainConfig->get( 'ObjectCaches' )[$id];
376  $logger = $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ?? 'objectcache' );
377 
378  $store = ObjectCache::newFromParams( $params );
379  $logger->debug( 'MainObjectStash using store {class}', [
380  'class' => get_class( $store )
381  ] );
382 
383  return $store;
384  },
385 
386  'MainWANObjectCache' => function ( MediaWikiServices $services ) : WANObjectCache {
387  $mainConfig = $services->getMainConfig();
388 
389  $id = $mainConfig->get( 'MainWANCache' );
390  if ( !isset( $mainConfig->get( 'WANObjectCaches' )[$id] ) ) {
391  throw new UnexpectedValueException(
392  "WAN cache type \"$id\" is not present in \$wgWANObjectCaches." );
393  }
394 
395  $params = $mainConfig->get( 'WANObjectCaches' )[$id];
396 
397  $logger = LoggerFactory::getInstance( $params['loggroup'] ?? 'objectcache' );
398 
399  $objectCacheId = $params['cacheId'];
400  if ( !isset( $mainConfig->get( 'ObjectCaches' )[$objectCacheId] ) ) {
401  throw new UnexpectedValueException(
402  "Cache type \"$objectCacheId\" is not present in \$wgObjectCaches." );
403  }
404  $storeParams = $mainConfig->get( 'ObjectCaches' )[$objectCacheId];
405  $store = ObjectCache::newFromParams( $storeParams );
406  $logger->debug( 'MainWANObjectCache using store {class}', [
407  'class' => get_class( $store )
408  ] );
409 
410  $params['logger'] = $logger;
411  $params['cache'] = $store;
412  $params['secret'] = $params['secret'] ?? $mainConfig->get( 'SecretKey' );
413  if ( !$mainConfig->get( 'CommandLineMode' ) ) {
414  // Send the statsd data post-send on HTTP requests; avoid in CLI mode (T181385)
415  $params['stats'] = $services->getStatsdDataFactory();
416  // Let pre-emptive refreshes happen post-send on HTTP requests
417  $params['asyncHandler'] = [ DeferredUpdates::class, 'addCallableUpdate' ];
418  }
419 
420  $class = $params['class'];
421  // @phan-suppress-next-line PhanParamTooMany Not inferring the right type
422  $instance = new $class( $params );
423 
424  '@phan-var WANObjectCache $instance';
425  return $instance;
426  },
427 
428  'MediaHandlerFactory' => function ( MediaWikiServices $services ) : MediaHandlerFactory {
429  return new MediaHandlerFactory(
430  $services->getMainConfig()->get( 'MediaHandlers' )
431  );
432  },
433 
434  'MessageCache' => function ( MediaWikiServices $services ) : MessageCache {
435  $mainConfig = $services->getMainConfig();
436  $clusterCache = ObjectCache::getInstance( $mainConfig->get( 'MessageCacheType' ) );
437  $srvCache = $mainConfig->get( 'UseLocalMessageCache' )
438  ? $services->getLocalServerObjectCache()
439  : new EmptyBagOStuff();
440 
441  $logger = LoggerFactory::getInstance( 'MessageCache' );
442  $logger->debug( 'MessageCache using store {class}', [
443  'class' => get_class( $clusterCache )
444  ] );
445 
446  return new MessageCache(
447  $services->getMainWANObjectCache(),
448  $clusterCache,
449  $srvCache,
450  $services->getContentLanguage(),
451  $logger,
452  [ 'useDB' => $mainConfig->get( 'UseDatabaseMessages' ) ]
453  );
454  },
455 
456  'MessageFormatterFactory' =>
457  function ( MediaWikiServices $services ) : IMessageFormatterFactory {
458  // @phan-suppress-next-line PhanAccessMethodInternal
459  return new MessageFormatterFactory();
460  },
461 
462  'MimeAnalyzer' => function ( MediaWikiServices $services ) : MimeAnalyzer {
463  $logger = LoggerFactory::getInstance( 'Mime' );
464  $mainConfig = $services->getMainConfig();
465  $params = [
466  'typeFile' => $mainConfig->get( 'MimeTypeFile' ),
467  'infoFile' => $mainConfig->get( 'MimeInfoFile' ),
468  'xmlTypes' => $mainConfig->get( 'XMLMimeTypes' ),
469  'guessCallback' =>
470  function ( $mimeAnalyzer, &$head, &$tail, $file, &$mime ) use ( $logger ) {
471  // Also test DjVu
472  $deja = new DjVuImage( $file );
473  if ( $deja->isValid() ) {
474  $logger->info( "Detected $file as image/vnd.djvu\n" );
475  $mime = 'image/vnd.djvu';
476 
477  return;
478  }
479  // Some strings by reference for performance - assuming well-behaved hooks
480  Hooks::run(
481  'MimeMagicGuessFromContent',
482  [ $mimeAnalyzer, &$head, &$tail, $file, &$mime ]
483  );
484  },
485  'extCallback' => function ( $mimeAnalyzer, $ext, &$mime ) {
486  // Media handling extensions can improve the MIME detected
487  Hooks::run( 'MimeMagicImproveFromExtension', [ $mimeAnalyzer, $ext, &$mime ] );
488  },
489  'initCallback' => function ( $mimeAnalyzer ) {
490  // Allow media handling extensions adding MIME-types and MIME-info
491  Hooks::run( 'MimeMagicInit', [ $mimeAnalyzer ] );
492  },
493  'logger' => $logger
494  ];
495 
496  if ( $params['infoFile'] === 'includes/mime.info' ) {
497  $params['infoFile'] = __DIR__ . "/libs/mime/mime.info";
498  }
499 
500  if ( $params['typeFile'] === 'includes/mime.types' ) {
501  $params['typeFile'] = __DIR__ . "/libs/mime/mime.types";
502  }
503 
504  $detectorCmd = $mainConfig->get( 'MimeDetectorCommand' );
505  if ( $detectorCmd ) {
506  $factory = $services->getShellCommandFactory();
507  $params['detectCallback'] = function ( $file ) use ( $detectorCmd, $factory ) {
508  $result = $factory->create()
509  // $wgMimeDetectorCommand can contain commands with parameters
510  ->unsafeParams( $detectorCmd )
511  ->params( $file )
512  ->execute();
513  return $result->getStdout();
514  };
515  }
516 
517  return new MimeAnalyzer( $params );
518  },
519 
520  'MovePageFactory' => function ( MediaWikiServices $services ) : MovePageFactory {
521  return new MovePageFactory(
522  new ServiceOptions( MovePageFactory::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
523  $services->getDBLoadBalancer(),
524  $services->getNamespaceInfo(),
525  $services->getWatchedItemStore(),
526  $services->getPermissionManager(),
527  $services->getRepoGroup()
528  );
529  },
530 
531  'NamespaceInfo' => function ( MediaWikiServices $services ) : NamespaceInfo {
533  $services->getMainConfig() ) );
534  },
535 
536  'NameTableStoreFactory' => function ( MediaWikiServices $services ) : NameTableStoreFactory {
537  return new NameTableStoreFactory(
538  $services->getDBLoadBalancerFactory(),
539  $services->getMainWANObjectCache(),
540  LoggerFactory::getInstance( 'NameTableSqlStore' )
541  );
542  },
543 
544  'ObjectFactory' => function ( MediaWikiServices $services ) : ObjectFactory {
545  return new ObjectFactory( $services );
546  },
547 
548  'OldRevisionImporter' => function ( MediaWikiServices $services ) : OldRevisionImporter {
550  true,
551  LoggerFactory::getInstance( 'OldRevisionImporter' ),
552  $services->getDBLoadBalancer()
553  );
554  },
555 
556  'PageEditStash' => function ( MediaWikiServices $services ) : PageEditStash {
557  $config = $services->getMainConfig();
558 
559  return new PageEditStash(
561  $services->getDBLoadBalancer(),
562  LoggerFactory::getInstance( 'StashEdit' ),
563  $services->getStatsdDataFactory(),
564  defined( 'MEDIAWIKI_JOB_RUNNER' ) || $config->get( 'CommandLineMode' )
565  ? PageEditStash::INITIATOR_JOB_OR_CLI
566  : PageEditStash::INITIATOR_USER
567  );
568  },
569 
570  'Parser' => function ( MediaWikiServices $services ) : Parser {
571  return $services->getParserFactory()->create();
572  },
573 
574  'ParserCache' => function ( MediaWikiServices $services ) : ParserCache {
575  $config = $services->getMainConfig();
576  $cache = ObjectCache::getInstance( $config->get( 'ParserCacheType' ) );
577  wfDebugLog( 'caches', 'parser: ' . get_class( $cache ) );
578 
579  return new ParserCache(
580  $cache,
581  $config->get( 'CacheEpoch' )
582  );
583  },
584 
585  'ParserFactory' => function ( MediaWikiServices $services ) : ParserFactory {
586  $options = new ServiceOptions( Parser::CONSTRUCTOR_OPTIONS,
587  // 'class' and 'preprocessorClass'
588  $services->getMainConfig()->get( 'ParserConf' ),
589  // Make sure to have defaults in case someone overrode ParserConf with something silly
590  [ 'class' => Parser::class, 'preprocessorClass' => Preprocessor_Hash::class ],
591  // Plus a buch of actual config options
592  $services->getMainConfig()
593  );
594 
595  return new ParserFactory(
596  $options,
597  $services->getMagicWordFactory(),
598  $services->getContentLanguage(),
599  wfUrlProtocols(),
600  $services->getSpecialPageFactory(),
601  $services->getLinkRendererFactory(),
602  $services->getNamespaceInfo(),
603  LoggerFactory::getInstance( 'Parser' )
604  );
605  },
606 
607  'PasswordFactory' => function ( MediaWikiServices $services ) : PasswordFactory {
608  $config = $services->getMainConfig();
609  return new PasswordFactory(
610  $config->get( 'PasswordConfig' ),
611  $config->get( 'PasswordDefault' )
612  );
613  },
614 
615  'PasswordReset' => function ( MediaWikiServices $services ) : PasswordReset {
616  $options = new ServiceOptions( PasswordReset::CONSTRUCTOR_OPTIONS, $services->getMainConfig() );
617  return new PasswordReset(
618  $options,
619  AuthManager::singleton(),
620  $services->getPermissionManager(),
621  $services->getDBLoadBalancer(),
622  LoggerFactory::getInstance( 'authentication' )
623  );
624  },
625 
626  'PerDbNameStatsdDataFactory' =>
627  function ( MediaWikiServices $services ) : StatsdDataFactoryInterface {
628  $config = $services->getMainConfig();
629  $wiki = $config->get( 'DBname' );
631  $services->getStatsdDataFactory(),
632  $wiki
633  );
634  },
635 
636  'PermissionManager' => function ( MediaWikiServices $services ) : PermissionManager {
637  return new PermissionManager(
638  new ServiceOptions(
639  PermissionManager::CONSTRUCTOR_OPTIONS, $services->getMainConfig()
640  ),
641  $services->getSpecialPageFactory(),
642  $services->getRevisionLookup(),
643  $services->getNamespaceInfo(),
644  $services->getBlockErrorFormatter()
645  );
646  },
647 
648  'PreferencesFactory' => function ( MediaWikiServices $services ) : PreferencesFactory {
649  $factory = new DefaultPreferencesFactory(
650  new ServiceOptions(
651  DefaultPreferencesFactory::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
652  $services->getContentLanguage(),
653  AuthManager::singleton(),
654  $services->getLinkRendererFactory()->create(),
655  $services->getNamespaceInfo(),
656  $services->getPermissionManager()
657  );
658  $factory->setLogger( LoggerFactory::getInstance( 'preferences' ) );
659 
660  return $factory;
661  },
662 
663  'ProxyLookup' => function ( MediaWikiServices $services ) : ProxyLookup {
664  $mainConfig = $services->getMainConfig();
665  return new ProxyLookup(
666  $mainConfig->get( 'CdnServers' ),
667  $mainConfig->get( 'CdnServersNoPurge' )
668  );
669  },
670 
671  'ReadOnlyMode' => function ( MediaWikiServices $services ) : ReadOnlyMode {
672  return new ReadOnlyMode(
673  $services->getConfiguredReadOnlyMode(),
674  $services->getDBLoadBalancer()
675  );
676  },
677 
678  'RepoGroup' => function ( MediaWikiServices $services ) : RepoGroup {
679  $config = $services->getMainConfig();
680  return new RepoGroup(
681  $config->get( 'LocalFileRepo' ),
682  $config->get( 'ForeignFileRepos' ),
683  $services->getMainWANObjectCache()
684  );
685  },
686 
687  'ResourceLoader' => function ( MediaWikiServices $services ) : ResourceLoader {
688  // @todo This should not take a Config object, but it's not so easy to remove because it
689  // exposes it in a getter, which is actually used.
690  global $IP;
691  $config = $services->getMainConfig();
692 
693  $rl = new ResourceLoader(
694  $config,
695  LoggerFactory::getInstance( 'resourceloader' )
696  );
697 
698  $rl->addSource( $config->get( 'ResourceLoaderSources' ) );
699 
700  // Core modules, then extension/skin modules
701  $rl->register( include "$IP/resources/Resources.php" );
702  $rl->register( $config->get( 'ResourceModules' ) );
703  Hooks::run( 'ResourceLoaderRegisterModules', [ &$rl ] );
704 
705  if ( $config->get( 'EnableJavaScriptTest' ) === true ) {
706  $rl->registerTestModules();
707  }
708 
709  return $rl;
710  },
711 
712  'RevisionFactory' => function ( MediaWikiServices $services ) : RevisionFactory {
713  return $services->getRevisionStore();
714  },
715 
716  'RevisionLookup' => function ( MediaWikiServices $services ) : RevisionLookup {
717  return $services->getRevisionStore();
718  },
719 
720  'RevisionRenderer' => function ( MediaWikiServices $services ) : RevisionRenderer {
721  $renderer = new RevisionRenderer(
722  $services->getDBLoadBalancer(),
723  $services->getSlotRoleRegistry()
724  );
725 
726  $renderer->setLogger( LoggerFactory::getInstance( 'SaveParse' ) );
727  return $renderer;
728  },
729 
730  'RevisionStore' => function ( MediaWikiServices $services ) : RevisionStore {
731  return $services->getRevisionStoreFactory()->getRevisionStore();
732  },
733 
734  'RevisionStoreFactory' => function ( MediaWikiServices $services ) : RevisionStoreFactory {
735  $config = $services->getMainConfig();
736  $store = new RevisionStoreFactory(
737  $services->getDBLoadBalancerFactory(),
738  $services->getBlobStoreFactory(),
739  $services->getNameTableStoreFactory(),
740  $services->getSlotRoleRegistry(),
741  $services->getMainWANObjectCache(),
742  $services->getCommentStore(),
743  $services->getActorMigration(),
744  $config->get( 'MultiContentRevisionSchemaMigrationStage' ),
745  LoggerFactory::getInstance( 'RevisionStore' ),
746  $config->get( 'ContentHandlerUseDB' )
747  );
748 
749  return $store;
750  },
751 
752  'SearchEngineConfig' => function ( MediaWikiServices $services ) : SearchEngineConfig {
753  // @todo This should not take a Config object, but it's not so easy to remove because it
754  // exposes it in a getter, which is actually used.
755  return new SearchEngineConfig( $services->getMainConfig(),
756  $services->getContentLanguage() );
757  },
758 
759  'SearchEngineFactory' => function ( MediaWikiServices $services ) : SearchEngineFactory {
760  return new SearchEngineFactory( $services->getSearchEngineConfig() );
761  },
762 
763  'ShellCommandFactory' => function ( MediaWikiServices $services ) : CommandFactory {
764  $config = $services->getMainConfig();
765 
766  $limits = [
767  'time' => $config->get( 'MaxShellTime' ),
768  'walltime' => $config->get( 'MaxShellWallClockTime' ),
769  'memory' => $config->get( 'MaxShellMemory' ),
770  'filesize' => $config->get( 'MaxShellFileSize' ),
771  ];
772  $cgroup = $config->get( 'ShellCgroup' );
773  $restrictionMethod = $config->get( 'ShellRestrictionMethod' );
774 
775  $factory = new CommandFactory( $limits, $cgroup, $restrictionMethod );
776  $factory->setLogger( LoggerFactory::getInstance( 'exec' ) );
777  $factory->logStderr();
778 
779  return $factory;
780  },
781 
782  'SiteLookup' => function ( MediaWikiServices $services ) : SiteLookup {
783  // Use SiteStore as the SiteLookup as well. This was originally separated
784  // to allow for a cacheable read-only interface (using FileBasedSiteLookup),
785  // but this was never used. SiteStore has caching (see below).
786  return $services->getSiteStore();
787  },
788 
789  'SiteStore' => function ( MediaWikiServices $services ) : SiteStore {
790  $rawSiteStore = new DBSiteStore( $services->getDBLoadBalancer() );
791 
792  $cache = $services->getLocalServerObjectCache();
793  if ( $cache instanceof EmptyBagOStuff ) {
795  }
796 
797  return new CachingSiteStore( $rawSiteStore, $cache );
798  },
799 
800  'SkinFactory' => function ( MediaWikiServices $services ) : SkinFactory {
801  $factory = new SkinFactory();
802 
803  $names = $services->getMainConfig()->get( 'ValidSkinNames' );
804 
805  foreach ( $names as $name => $skin ) {
806  $factory->register( $name, $skin, function () use ( $name, $skin ) {
807  $class = "Skin$skin";
808  return new $class( $name );
809  } );
810  }
811  // Register a hidden "fallback" skin
812  $factory->register( 'fallback', 'Fallback', function () {
813  return new SkinFallback;
814  } );
815  // Register a hidden skin for api output
816  $factory->register( 'apioutput', 'ApiOutput', function () {
817  return new SkinApi;
818  } );
819 
820  return $factory;
821  },
822 
823  'SlotRoleRegistry' => function ( MediaWikiServices $services ) : SlotRoleRegistry {
824  $config = $services->getMainConfig();
825 
826  $registry = new SlotRoleRegistry(
827  $services->getNameTableStoreFactory()->getSlotRoles()
828  );
829 
830  $registry->defineRole( 'main', function () use ( $config ) {
831  return new MainSlotRoleHandler(
832  $config->get( 'NamespaceContentModels' )
833  );
834  } );
835 
836  return $registry;
837  },
838 
839  'SpecialPageFactory' => function ( MediaWikiServices $services ) : SpecialPageFactory {
840  return new SpecialPageFactory(
841  new ServiceOptions(
842  SpecialPageFactory::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
843  $services->getContentLanguage(),
844  $services->getObjectFactory()
845  );
846  },
847 
848  'StatsdDataFactory' => function ( MediaWikiServices $services ) : IBufferingStatsdDataFactory {
849  return new BufferingStatsdDataFactory(
850  rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ), '.' )
851  );
852  },
853 
854  'TempFSFileFactory' => function ( MediaWikiServices $services ) : TempFSFileFactory {
855  return new TempFSFileFactory( $services->getMainConfig()->get( 'TmpDirectory' ) );
856  },
857 
858  'TitleFormatter' => function ( MediaWikiServices $services ) : TitleFormatter {
859  return $services->getService( '_MediaWikiTitleCodec' );
860  },
861 
862  'TitleParser' => function ( MediaWikiServices $services ) : TitleParser {
863  return $services->getService( '_MediaWikiTitleCodec' );
864  },
865 
866  'UploadRevisionImporter' => function ( MediaWikiServices $services ) : UploadRevisionImporter {
868  $services->getMainConfig()->get( 'EnableUploads' ),
869  LoggerFactory::getInstance( 'UploadRevisionImporter' )
870  );
871  },
872 
873  'VirtualRESTServiceClient' =>
874  function ( MediaWikiServices $services ) : VirtualRESTServiceClient {
875  $config = $services->getMainConfig()->get( 'VirtualRestConfig' );
876 
877  $vrsClient = new VirtualRESTServiceClient( new MultiHttpClient( [] ) );
878  foreach ( $config['paths'] as $prefix => $serviceConfig ) {
879  $class = $serviceConfig['class'];
880  // Merge in the global defaults
881  $constructArg = $serviceConfig['options'] ?? [];
882  $constructArg += $config['global'];
883  // Make the VRS service available at the mount point
884  $vrsClient->mount( $prefix, [ 'class' => $class, 'config' => $constructArg ] );
885  }
886 
887  return $vrsClient;
888  },
889 
890  'WatchedItemQueryService' =>
891  function ( MediaWikiServices $services ) : WatchedItemQueryService {
892  return new WatchedItemQueryService(
893  $services->getDBLoadBalancer(),
894  $services->getCommentStore(),
895  $services->getActorMigration(),
896  $services->getWatchedItemStore(),
897  $services->getPermissionManager()
898  );
899  },
900 
901  'WatchedItemStore' => function ( MediaWikiServices $services ) : WatchedItemStore {
902  $store = new WatchedItemStore(
903  $services->getDBLoadBalancerFactory(),
905  $services->getMainObjectStash(),
906  new HashBagOStuff( [ 'maxKeys' => 100 ] ),
907  $services->getReadOnlyMode(),
908  $services->getMainConfig()->get( 'UpdateRowsPerQuery' ),
909  $services->getNamespaceInfo(),
910  $services->getRevisionLookup()
911  );
912  $store->setStatsdDataFactory( $services->getStatsdDataFactory() );
913 
914  if ( $services->getMainConfig()->get( 'ReadOnlyWatchedItemStore' ) ) {
915  $store = new NoWriteWatchedItemStore( $store );
916  }
917 
918  return $store;
919  },
920 
921  'WikiRevisionOldRevisionImporterNoUpdates' =>
922  function ( MediaWikiServices $services ) : ImportableOldRevisionImporter {
924  false,
925  LoggerFactory::getInstance( 'OldRevisionImporter' ),
926  $services->getDBLoadBalancer()
927  );
928  },
929 
930  '_MediaWikiTitleCodec' => function ( MediaWikiServices $services ) : MediaWikiTitleCodec {
931  return new MediaWikiTitleCodec(
932  $services->getContentLanguage(),
933  $services->getGenderCache(),
934  $services->getMainConfig()->get( 'LocalInterwikis' ),
935  $services->getInterwikiLookup(),
936  $services->getNamespaceInfo()
937  );
938  },
939 
940  '_SqlBlobStore' => function ( MediaWikiServices $services ) : SqlBlobStore {
941  // @phan-suppress-next-line PhanAccessMethodInternal
942  return $services->getBlobStoreFactory()->newSqlBlobStore();
943  },
944 
946  // NOTE: When adding a service here, don't forget to add a getter function
947  // in the MediaWikiServices class. The convenience getter should just call
948  // $this->getService( 'FooBarService' ).
950 
951 ];
Service for storing and loading Content objects.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
A factory for application metric data.
wfUrlProtocols( $includeProtocolRelative=true)
Returns a regular expression of url protocols.
A simple factory providing a message formatter for a given language code.
$context
Definition: load.php:45
SkinTemplate class for API output.
Definition: SkinApi.php:31
$IP
Definition: WebStart.php:41
The RevisionRenderer service provides access to rendered output for revisions.
Class for managing stashed edits used by the page updater classes.
Service for instantiating BlobStores.
A registry service for SlotRoleHandlers, used to define which slot roles are available on which page...
setLogger(LoggerInterface $saveParseLogger)
static getInstance( $id)
Get a cached instance of the specified type of cache object.
Definition: ObjectCache.php:78
static getLocalClusterInstance()
Get the main cluster-local cache object.
A read-only mode service which does not depend on LoadBalancer.
defineRole( $role, callable $instantiator)
Defines a slot role.
Factory service for RevisionStore instances.
InterwikiLookup implementing the "classic" interwiki storage (hardcoded up to MW 1.26).
const CONSTRUCTOR_OPTIONS
Storage layer class for WatchedItems.
This is the default implementation of PreferencesFactory.
A service class for fetching the wiki&#39;s current read-only mode.
A class for passing options to services.
The MediaWiki-specific implementation of IMessageFormatterFactory.
Support for detecting/validating DjVu image files and getting some basic file metadata (resolution et...
Definition: DjVuImage.php:38
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Class that generates HTML links for pages.
Factory for handling the special page list and generating SpecialPage objects.
static getMain()
Get the RequestContext object associated with the main request.
Interface for configuration instances.
Definition: Config.php:28
Service for looking up page revisions.
$cache
Definition: mcc.php:33
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:212
Service for looking up page revisions.
Service interface for looking up Interwiki records.
static applyDefaultConfig(array $lbConf, ServiceOptions $options, ConfiguredReadOnlyMode $readOnlyMode, BagOStuff $srvCache, BagOStuff $mainStash, WANObjectCache $wanCache)
Definition: MWLBFactory.php:72
getUser()
const CONSTRUCTOR_OPTIONS
SkinTemplate class for the fallback skin.
A service class for getting formatted information about a block.
Service for constructing revision objects.
static getCurrentWikiDbDomain()
Definition: WikiMap.php:293
setStatsdDataFactory(StatsdDataFactoryInterface $stats)
A service class for checking blocks.
A SlotRoleHandler for the main slot.
static getStoreFromConf(array $conf, $fallbackCacheDir)
Return a suitable LCStore as specified by the given configuration.
Factory creating MWHttpRequest objects.
static newFromParams( $params)
Create a new cache object from parameters.
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
Factory facilitating dependency injection for Command.
if(!is_readable( $file)) $ext
Definition: router.php:48
const SCHEMA_COMPAT_NEW
Definition: Defines.php:271
static singleton( $domain=false)
Factory to create LinkRender objects.
A PreferencesFactory is a MediaWiki service that provides the definitions of preferences for a given ...
Object which holds currently registered configuration options.
Service for loading and storing data blobs.
Definition: BlobStore.php:35
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
const MIGRATION_NEW
Definition: Defines.php:298
Class to handle multiple HTTP requests.
static detectLocalServerCache()
Detects which local server cache library is present and returns a configuration for it...
Proxy to prefix metric keys sent to a StatsdDataFactoryInterface.
MediaWikiServices is the service locator for the application scope of MediaWiki.
A service that provides utilities to do with language names and codes.
return true
Definition: router.php:92
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()-...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200