Add PasswordFactory to MediaWikiServices
[lhc/web/wiklou.git] / includes / ServiceWiring.php
index ace64ab..853b06d 100644 (file)
@@ -38,6 +38,7 @@
  */
 
 use MediaWiki\Auth\AuthManager;
+use MediaWiki\Config\ConfigRepository;
 use MediaWiki\Interwiki\ClassicInterwikiLookup;
 use MediaWiki\Linker\LinkRendererFactory;
 use MediaWiki\Logger\LoggerFactory;
@@ -104,16 +105,19 @@ return [
                return $factory;
        },
 
+       'ConfigRepository' => function ( MediaWikiServices $services ) {
+               return new ConfigRepository( $services->getConfigFactory() );
+       },
+
        'MainConfig' => function ( MediaWikiServices $services ) {
                // Use the 'main' config from the ConfigFactory service.
                return $services->getConfigFactory()->makeConfig( 'main' );
        },
 
        'InterwikiLookup' => function ( MediaWikiServices $services ) {
-               global $wgContLang; // TODO: manage $wgContLang as a service
                $config = $services->getMainConfig();
                return new ClassicInterwikiLookup(
-                       $wgContLang,
+                       $services->getContentLanguage(),
                        $services->getMainWANObjectCache(),
                        $config->get( 'InterwikiExpiry' ),
                        $config->get( 'InterwikiCache' ),
@@ -128,6 +132,14 @@ return [
                );
        },
 
+       'PerDbNameStatsdDataFactory' => function ( MediaWikiServices $services ) {
+               $config = $services->getMainConfig();
+               $wiki = $config->get( 'DBname' );
+               return new BufferingStatsdDataFactory(
+                       rtrim( $services->getMainConfig()->get( 'StatsdMetricPrefix' ) ) . '.' . $wiki
+               );
+       },
+
        'EventRelayerGroup' => function ( MediaWikiServices $services ) {
                return new EventRelayerGroup( $services->getMainConfig()->get( 'EventRelayerConfig' ) );
        },
@@ -137,8 +149,8 @@ return [
        },
 
        'SearchEngineConfig' => function ( MediaWikiServices $services ) {
-               global $wgContLang;
-               return new SearchEngineConfig( $services->getMainConfig(), $wgContLang );
+               return new SearchEngineConfig( $services->getMainConfig(),
+                       $services->getContentLanguage() );
        },
 
        'SkinFactory' => function ( MediaWikiServices $services ) {
@@ -188,29 +200,8 @@ return [
                );
        },
 
-       'CryptRand' => function ( MediaWikiServices $services ) {
-               $secretKey = $services->getMainConfig()->get( 'SecretKey' );
-               return new CryptRand(
-                       [
-                               // To try vary the system information of the state a bit more
-                               // by including the system's hostname into the state
-                               'wfHostname',
-                               // It's mostly worthless but throw the wiki's id into the data
-                               // for a little more variance
-                               'wfWikiID',
-                               // If we have a secret key set then throw it into the state as well
-                               function () use ( $secretKey ) {
-                                       return $secretKey ?: '';
-                               }
-                       ],
-                       // The config file is likely the most often edited file we know should
-                       // be around so include its stat info into the state.
-                       // The constant with its location will almost always be defined, as
-                       // WebStart.php defines MW_CONFIG_FILE to $IP/LocalSettings.php unless
-                       // being configured with MW_CONFIG_CALLBACK (e.g. the installer).
-                       defined( 'MW_CONFIG_FILE' ) ? [ MW_CONFIG_FILE ] : [],
-                       LoggerFactory::getInstance( 'CryptRand' )
-               );
+       'CryptRand' => function () {
+               return new CryptRand();
        },
 
        'CryptHKDF' => function ( MediaWikiServices $services ) {
@@ -231,9 +222,7 @@ return [
                        $cache = ObjectCache::getLocalClusterInstance();
                }
 
-               return new CryptHKDF( $secret, $config->get( 'HKDFAlgorithm' ),
-                       $cache, $context, $services->getCryptRand()
-               );
+               return new CryptHKDF( $secret, $config->get( 'HKDFAlgorithm' ), $cache, $context );
        },
 
        'MediaHandlerFactory' => function ( MediaWikiServices $services ) {
@@ -311,7 +300,8 @@ return [
 
        'Parser' => function ( MediaWikiServices $services ) {
                $conf = $services->getMainConfig()->get( 'ParserConf' );
-               return ObjectFactory::constructClassInstance( $conf['class'], [ $conf ] );
+               return ObjectFactory::constructClassInstance( $conf['class'],
+                       [ $conf, $services->getMagicWordFactory() ] );
        },
 
        'ParserCache' => function ( MediaWikiServices $services ) {
@@ -354,10 +344,8 @@ return [
        },
 
        '_MediaWikiTitleCodec' => function ( MediaWikiServices $services ) {
-               global $wgContLang;
-
                return new MediaWikiTitleCodec(
-                       $wgContLang,
+                       $services->getContentLanguage(),
                        $services->getGenderCache(),
                        $services->getMainConfig()->get( 'LocalInterwikis' )
                );
@@ -494,6 +482,9 @@ return [
                        $blobStore,
                        $services->getMainWANObjectCache(),
                        $services->getCommentStore(),
+                       $services->getContentModelStore(),
+                       $services->getSlotRoleStore(),
+                       $services->getMainConfig()->get( 'MultiContentRevisionSchemaMigrationStage' ),
                        $services->getActorMigration()
                );
 
@@ -514,12 +505,11 @@ return [
        },
 
        'BlobStoreFactory' => function ( MediaWikiServices $services ) {
-               global $wgContLang;
                return new BlobStoreFactory(
                        $services->getDBLoadBalancer(),
                        $services->getMainWANObjectCache(),
                        $services->getMainConfig(),
-                       $wgContLang
+                       $services->getContentLanguage()
                );
        },
 
@@ -560,12 +550,30 @@ return [
                );
        },
 
+       'ChangeTagDefStore' => function ( MediaWikiServices $services ) {
+               return new NameTableStore(
+                       $services->getDBLoadBalancer(),
+                       $services->getMainWANObjectCache(),
+                       LoggerFactory::getInstance( 'NameTableSqlStore' ),
+                       'change_tag_def',
+                       'ctd_id',
+                       'ctd_name',
+                       null,
+                       false,
+                       function ( $insertFields ) {
+                               $insertFields['ctd_user_defined'] = 0;
+                               $insertFields['ctd_count'] = 0;
+                               return $insertFields;
+                       }
+               );
+       },
+
        'PreferencesFactory' => function ( MediaWikiServices $services ) {
-               global $wgContLang;
                $authManager = AuthManager::singleton();
                $linkRenderer = $services->getLinkRendererFactory()->create();
                $config = $services->getMainConfig();
-               $factory = new DefaultPreferencesFactory( $config, $wgContLang, $authManager, $linkRenderer );
+               $factory = new DefaultPreferencesFactory( $config, $services->getContentLanguage(),
+                       $authManager, $linkRenderer );
                $factory->setLogger( LoggerFactory::getInstance( 'preferences' ) );
 
                return $factory;
@@ -576,9 +584,8 @@ return [
        },
 
        'CommentStore' => function ( MediaWikiServices $services ) {
-               global $wgContLang;
                return new CommentStore(
-                       $wgContLang,
+                       $services->getContentLanguage(),
                        $services->getMainConfig()->get( 'CommentTableSchemaMigrationStage' )
                );
        },
@@ -589,6 +596,22 @@ return [
                );
        },
 
+       'MagicWordFactory' => function ( MediaWikiServices $services ) {
+               return new MagicWordFactory( $services->getContentLanguage() );
+       },
+
+       'ContentLanguage' => function ( MediaWikiServices $services ) {
+               return Language::factory( $services->getMainConfig()->get( 'LanguageCode' ) );
+       },
+
+       'PasswordFactory' => function ( MediaWikiServices $services ) {
+               $config = $services->getMainConfig();
+               return new PasswordFactory(
+                       $config->get( 'PasswordConfig' ),
+                       $config->get( 'PasswordDefault' )
+               );
+       },
+
        ///////////////////////////////////////////////////////////////////////////
        // NOTE: When adding a service here, don't forget to add a getter function
        // in the MediaWikiServices class. The convenience getter should just call