Add Parser to MediaWikiServices
authorKunal Mehta <legoktm@member.fsf.org>
Tue, 16 Aug 2016 20:47:43 +0000 (13:47 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Sun, 16 Oct 2016 19:04:13 +0000 (12:04 -0700)
So we can avoid using $wgParser everywhere.

Change-Id: Ie5fd2c523ceec8cc2656e749928f38909dc4bdf1

includes/MediaWikiServices.php
includes/ServiceWiring.php
includes/Setup.php
tests/phpunit/includes/MediaWikiServicesTest.php

index 7f94ced..2171a5d 100644 (file)
@@ -21,6 +21,7 @@ use MediaWiki\Services\NoSuchServiceException;
 use MWException;
 use MimeAnalyzer;
 use ObjectCache;
+use Parser;
 use ProxyLookup;
 use SearchEngine;
 use SearchEngineConfig;
@@ -556,6 +557,14 @@ class MediaWikiServices extends ServiceContainer {
                return $this->getService( 'ProxyLookup' );
        }
 
+       /**
+        * @since 1.28
+        * @return Parser
+        */
+       public function getParser() {
+               return $this->getService( 'Parser' );
+       }
+
        /**
         * @since 1.28
         * @return GenderCache
index 49183e5..a427f5c 100644 (file)
@@ -207,6 +207,11 @@ return [
                );
        },
 
+       'Parser' => function( MediaWikiServices $services ) {
+               $conf = $services->getMainConfig()->get( 'ParserConf' );
+               return ObjectFactory::constructClassInstance( $conf['class'], [ $conf ] );
+       },
+
        'LinkCache' => function( MediaWikiServices $services ) {
                return new LinkCache(
                        $services->getTitleFormatter(),
index 7cda14c..357c76d 100644 (file)
@@ -818,7 +818,9 @@ $wgOut = RequestContext::getMain()->getOutput(); // BackCompat
 /**
  * @var Parser $wgParser
  */
-$wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
+$wgParser = new StubObject( 'wgParser', function () {
+       return MediaWikiServices::getInstance()->getParser();
+} );
 
 /**
  * @var Title $wgTitle
index 0ff903f..c9c50c0 100644 (file)
@@ -314,6 +314,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase {
                        'WatchedItemQueryService' => [ 'WatchedItemQueryService', WatchedItemQueryService::class ],
                        'CryptRand' => [ 'CryptRand', CryptRand::class ],
                        'MediaHandlerFactory' => [ 'MediaHandlerFactory', MediaHandlerFactory::class ],
+                       'Parser' => [ 'Parser', Parser::class ],
                        'GenderCache' => [ 'GenderCache', GenderCache::class ],
                        'LinkCache' => [ 'LinkCache', LinkCache::class ],
                        'LinkRenderer' => [ 'LinkRenderer', LinkRenderer::class ],