Merge "filebackend: Convert trigger_error to PSR log warning"
[lhc/web/wiklou.git] / includes / ServiceWiring.php
index d081629..83847d8 100644 (file)
  * For every service that MediaWiki core requires, an instantiator must be defined in
  * this file.
  *
+ * Note that, ideally, all information used to instantiate service objects should come
+ * from configuration. Information derived from the current request is acceptable, but
+ * only where there is no feasible alternative. It is preferred that such information
+ * (like the client IP, the acting user's identity, requested title, etc) be passed to
+ * the service object's methods as parameters. This makes the flow of information more
+ * obvious, and makes it easier to understand the behavior of services.
+ *
  * @note As of version 1.27, MediaWiki is only beginning to use dependency injection.
  * The services defined here do not yet fully represent all services used by core,
  * much of the code still relies on global state for this accessing services.
@@ -77,9 +84,7 @@ use Wikimedia\ObjectFactory;
 
 return [
        'ActorMigration' => function ( MediaWikiServices $services ) : ActorMigration {
-               return new ActorMigration(
-                       $services->getMainConfig()->get( 'ActorTableSchemaMigrationStage' )
-               );
+               return new ActorMigration( SCHEMA_COMPAT_NEW );
        },
 
        'BadFileLookup' => function ( MediaWikiServices $services ) : BadFileLookup {
@@ -109,14 +114,12 @@ return [
        },
 
        'BlockManager' => function ( MediaWikiServices $services ) : BlockManager {
-               $context = RequestContext::getMain();
                return new BlockManager(
                        new ServiceOptions(
                                BlockManager::$constructorOptions, $services->getMainConfig()
                        ),
-                       $context->getUser(),
-                       $context->getRequest(),
-                       $services->getPermissionManager()
+                       $services->getPermissionManager(),
+                       LoggerFactory::getInstance( 'BlockManager' )
                );
        },
 
@@ -204,10 +207,7 @@ return [
                );
                $class = MWLBFactory::getLBFactoryClass( $lbConf );
 
-               $instance = new $class( $lbConf );
-               MWLBFactory::setSchemaAliases( $instance, $mainConfig->get( 'DBtype' ) );
-
-               return $instance;
+               return new $class( $lbConf );
        },
 
        'EventRelayerGroup' => function ( MediaWikiServices $services ) : EventRelayerGroup {
@@ -271,6 +271,8 @@ return [
                if ( defined( 'MW_NO_SESSION' ) ) {
                        return $services->getLinkRendererFactory()->create();
                } else {
+                       // Normally information from the current request would not be passed in here;
+                       // this is an exception. (See also the class documentation.)
                        return $services->getLinkRendererFactory()->createForUser(
                                RequestContext::getMain()->getUser()
                        );
@@ -287,9 +289,9 @@ return [
 
        'LocalServerObjectCache' => function ( MediaWikiServices $services ) : BagOStuff {
                $config = $services->getMainConfig();
-               $cacheId = \ObjectCache::detectLocalServerCache();
+               $cacheId = ObjectCache::detectLocalServerCache();
 
-               return \ObjectCache::newFromParams( $config->get( 'ObjectCaches' )[$cacheId] );
+               return ObjectCache::newFromParams( $config->get( 'ObjectCaches' )[$cacheId] );
        },
 
        'LockManagerGroupFactory' => function ( MediaWikiServices $services ) : LockManagerGroupFactory {
@@ -318,7 +320,7 @@ return [
                                "Cache type \"$id\" is not present in \$wgObjectCaches." );
                }
 
-               return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] );
+               return ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] );
        },
 
        'MainWANObjectCache' => function ( MediaWikiServices $services ) : WANObjectCache {
@@ -338,7 +340,7 @@ return [
                }
                $params['store'] = $mainConfig->get( 'ObjectCaches' )[$objectCacheId];
 
-               return \ObjectCache::newWANCacheFromParams( $params );
+               return ObjectCache::newWANCacheFromParams( $params );
        },
 
        'MediaHandlerFactory' => function ( MediaWikiServices $services ) : MediaHandlerFactory {
@@ -362,6 +364,7 @@ return [
 
        'MessageFormatterFactory' =>
        function ( MediaWikiServices $services ) : IMessageFormatterFactory {
+               // @phan-suppress-next-line PhanAccessMethodInternal
                return new MessageFormatterFactory();
        },
 
@@ -493,8 +496,7 @@ return [
                        // 'class' and 'preprocessorClass'
                        $services->getMainConfig()->get( 'ParserConf' ),
                        // Make sure to have defaults in case someone overrode ParserConf with something silly
-                       [ 'class' => Parser::class,
-                               'preprocessorClass' => Parser::getDefaultPreprocessorClass() ],
+                       [ 'class' => Parser::class, 'preprocessorClass' => Preprocessor_Hash::class ],
                        // Plus a buch of actual config options
                        $services->getMainConfig()
                );
@@ -547,7 +549,8 @@ return [
                        $services->getContentLanguage(),
                        AuthManager::singleton(),
                        $services->getLinkRendererFactory()->create(),
-                       $services->getNamespaceInfo()
+                       $services->getNamespaceInfo(),
+                       $services->getPermissionManager()
                );
                $factory->setLogger( LoggerFactory::getInstance( 'preferences' ) );
 
@@ -636,7 +639,7 @@ return [
                        $services->getCommentStore(),
                        $services->getActorMigration(),
                        $config->get( 'MultiContentRevisionSchemaMigrationStage' ),
-                       LoggerFactory::getProvider(),
+                       LoggerFactory::getInstance( 'RevisionStore' ),
                        $config->get( 'ContentHandlerUseDB' )
                );
 
@@ -734,7 +737,8 @@ return [
                return new SpecialPageFactory(
                        new ServiceOptions(
                                SpecialPageFactory::$constructorOptions, $services->getMainConfig() ),
-                       $services->getContentLanguage()
+                       $services->getContentLanguage(),
+                       $services->getObjectFactory()
                );
        },
 
@@ -786,7 +790,8 @@ return [
                        $services->getDBLoadBalancer(),
                        $services->getCommentStore(),
                        $services->getActorMigration(),
-                       $services->getWatchedItemStore()
+                       $services->getWatchedItemStore(),
+                       $services->getPermissionManager()
                );
        },
 
@@ -830,6 +835,7 @@ return [
        },
 
        '_SqlBlobStore' => function ( MediaWikiServices $services ) : SqlBlobStore {
+               // @phan-suppress-next-line PhanAccessMethodInternal
                return $services->getBlobStoreFactory()->newSqlBlobStore();
        },