Merge "Add Parser to MediaWikiServices"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 28 Oct 2016 17:53:30 +0000 (17:53 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 28 Oct 2016 17:53:30 +0000 (17:53 +0000)
1  2 
includes/MediaWikiServices.php
includes/ServiceWiring.php
tests/phpunit/includes/MediaWikiServicesTest.php

@@@ -3,7 -3,6 +3,7 @@@ namespace MediaWiki
  
  use Config;
  use ConfigFactory;
 +use CryptHKDF;
  use CryptRand;
  use EventRelayerGroup;
  use GenderCache;
@@@ -22,6 -21,7 +22,7 @@@ use MediaWiki\Services\NoSuchServiceExc
  use MWException;
  use MimeAnalyzer;
  use ObjectCache;
+ use Parser;
  use ProxyLookup;
  use SearchEngine;
  use SearchEngineConfig;
@@@ -183,7 -183,7 +184,7 @@@ class MediaWikiServices extends Service
  
                $oldInstance = self::$instance;
  
 -              self::$instance = self::newInstance( $bootstrapConfig );
 +              self::$instance = self::newInstance( $bootstrapConfig, 'load' );
                self::$instance->importWiring( $oldInstance, [ 'BootstrapConfig' ] );
  
                if ( $quick === 'quick' ) {
                return $this->getService( 'CryptRand' );
        }
  
 +      /**
 +       * @since 1.28
 +       * @return CryptHKDF
 +       */
 +      public function getCryptHKDF() {
 +              return $this->getService( 'CryptHKDF' );
 +      }
 +
        /**
         * @since 1.28
         * @return MediaHandlerFactory
                return $this->getService( 'ProxyLookup' );
        }
  
+       /**
+        * @since 1.28
+        * @return Parser
+        */
+       public function getParser() {
+               return $this->getService( 'Parser' );
+       }
        /**
         * @since 1.28
         * @return GenderCache
@@@ -184,29 -184,6 +184,29 @@@ return 
                );
        },
  
 +      'CryptHKDF' => function( MediaWikiServices $services ) {
 +              $config = $services->getMainConfig();
 +
 +              $secret = $config->get( 'HKDFSecret' ) ?: $config->get( 'SecretKey' );
 +              if ( !$secret ) {
 +                      throw new RuntimeException( "Cannot use MWCryptHKDF without a secret." );
 +              }
 +
 +              // In HKDF, the context can be known to the attacker, but this will
 +              // keep simultaneous runs from producing the same output.
 +              $context = [ microtime(), getmypid(), gethostname() ];
 +
 +              // Setup salt cache. Use APC, or fallback to the main cache if it isn't setup
 +              $cache = $services->getLocalServerObjectCache();
 +              if ( $cache instanceof EmptyBagOStuff ) {
 +                      $cache = ObjectCache::getLocalClusterInstance();
 +              }
 +
 +              return new CryptHKDF( $secret, $config->get( 'HKDFAlgorithm' ),
 +                      $cache, $context, $services->getCryptRand()
 +              );
 +      },
 +
        'MediaHandlerFactory' => function( MediaWikiServices $services ) {
                return new MediaHandlerFactory(
                        $services->getMainConfig()->get( 'MediaHandlers' )
                );
        },
  
+       'Parser' => function( MediaWikiServices $services ) {
+               $conf = $services->getMainConfig()->get( 'ParserConf' );
+               return ObjectFactory::constructClassInstance( $conf['class'], [ $conf ] );
+       },
        'LinkCache' => function( MediaWikiServices $services ) {
                return new LinkCache(
                        $services->getTitleFormatter(),
@@@ -313,8 -313,8 +313,9 @@@ class MediaWikiServicesTest extends Med
                        'WatchedItemStore' => [ 'WatchedItemStore', WatchedItemStore::class ],
                        'WatchedItemQueryService' => [ 'WatchedItemQueryService', WatchedItemQueryService::class ],
                        'CryptRand' => [ 'CryptRand', CryptRand::class ],
 +                      'CryptHKDF' => [ 'CryptHKDF', CryptHKDF::class ],
                        'MediaHandlerFactory' => [ 'MediaHandlerFactory', MediaHandlerFactory::class ],
+                       'Parser' => [ 'Parser', Parser::class ],
                        'GenderCache' => [ 'GenderCache', GenderCache::class ],
                        'LinkCache' => [ 'LinkCache', LinkCache::class ],
                        'LinkRenderer' => [ 'LinkRenderer', LinkRenderer::class ],