Add Parser to MediaWikiServices

So we can avoid using $wgParser everywhere.

Change-Id: Ie5fd2c523ceec8cc2656e749928f38909dc4bdf1
This commit is contained in:
Kunal Mehta 2016-08-16 13:47:43 -07:00
parent b02f949c50
commit 97620165ad
4 changed files with 18 additions and 1 deletions

View 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

View 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(),

View 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

View 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 ],