use MediaWiki\Storage\RevisionStore;
use MediaWiki\Storage\RevisionStoreFactory;
use MediaWiki\Storage\SqlBlobStore;
-use Wikimedia\ObjectFactory;
return [
'ActorMigration' => function ( MediaWikiServices $services ) : ActorMigration {
},
'Parser' => function ( MediaWikiServices $services ) : Parser {
- $conf = $services->getMainConfig()->get( 'ParserConf' );
- return ObjectFactory::constructClassInstance( $conf['class'],
- [ $conf, $services->getMagicWordFactory() ] );
+ return $services->getParserFactory()->create();
},
'ParserCache' => function ( MediaWikiServices $services ) : ParserCache {
/** @var Language */
private $contLang;
+ /** @var ParserFactory */
+ private $factory;
+
/**
* @param array $conf See $wgParserConf documentation
* @param MagicWordFactory|null $magicWordFactory
* @param Language|null $contLang Content language
+ * @param ParserFactory|null $factory
* @param string|null $urlProtocols As returned from wfUrlProtocols()
*/
public function __construct(
array $conf = [], MagicWordFactory $magicWordFactory = null, Language $contLang = null,
- $urlProtocols = null
+ ParserFactory $factory = null, $urlProtocols = null
) {
$this->mConf = $conf;
$this->mUrlProtocols = $urlProtocols ?? wfUrlProtocols();
MediaWikiServices::getInstance()->getMagicWordFactory();
$this->contLang = $contLang ?? MediaWikiServices::getInstance()->getContentLanguage();
+
+ $this->factory = $factory ?? MediaWikiServices::getInstance()->getParserFactory();
}
/**
* @return Parser A parser object that is not parsing anything
*/
public function getFreshParser() {
- global $wgParserConf;
if ( $this->mInParse ) {
- return new $wgParserConf['class']( $wgParserConf );
+ return $this->factory->create();
} else {
return $this;
}
* @since 1.32
*/
public function create() : Parser {
- return new Parser( $this->conf, $this->magicWordFactory, $this->contLang,
+ return new Parser( $this->conf, $this->magicWordFactory, $this->contLang, $this,
$this->urlProtocols );
}
}
<?php
+
+use MediaWiki\MediaWikiServices;
+
/**
* Parse some wikitext.
*
}
protected function initParser() {
- global $wgParserConf;
- $parserClass = $wgParserConf['class'];
- $this->parser = new $parserClass();
+ $this->parser = MediaWikiServices::getInstance()->getParserFactory()->create();
}
/**
<?php
-use Wikimedia\ObjectFactory;
+use MediaWiki\MediaWikiServices;
use Wikimedia\TestingAccessWrapper;
/**
}
public function testRawHtmlInMsg() {
- global $wgParserConf;
$this->setMwGlobals( 'wgRawHtml', true );
// We have to reset the core hook registration.
// to register the html hook
MessageCache::destroyInstance();
$this->setMwGlobals( 'wgParser',
- ObjectFactory::constructClassInstance( $wgParserConf['class'], [ $wgParserConf ] )
- );
+ MediaWikiServices::getInstance()->getParserFactory()->create() );
$msg = new RawMessage( '<html><script>alert("xss")</script></html>' );
$txt = '<span class="error"><html> tags cannot be' .
public function testConstructorArgNum() {
$factoryConstructor = new ReflectionMethod( 'ParserFactory', '__construct' );
$instanceConstructor = new ReflectionMethod( 'Parser', '__construct' );
- $this->assertSame( $instanceConstructor->getNumberOfParameters(),
+ // Subtract one for the ParserFactory itself
+ $this->assertSame( $instanceConstructor->getNumberOfParameters() - 1,
$factoryConstructor->getNumberOfParameters(),
'Parser and ParserFactory constructors have an inconsistent number of parameters. ' .
'Did you add a parameter to one and not the other?' );
<?php
+use MediaWiki\MediaWikiServices;
+
/**
* @group Database
* @group Parser
* @dataProvider provideValidNames
*/
public function testTagHooks( $tag ) {
- global $wgParserConf;
- $parser = new Parser( $wgParserConf );
+ $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
$parser->setHook( $tag, [ $this, 'tagCallback' ] );
$parserOutput = $parser->parse(
* @expectedException MWException
*/
public function testBadTagHooks( $tag ) {
- global $wgParserConf;
- $parser = new Parser( $wgParserConf );
+ $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
$parser->setHook( $tag, [ $this, 'tagCallback' ] );
$parser->parse(
* @dataProvider provideValidNames
*/
public function testFunctionTagHooks( $tag ) {
- global $wgParserConf;
- $parser = new Parser( $wgParserConf );
+ $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
$parser->setFunctionTagHook( $tag, [ $this, 'functionTagCallback' ], 0 );
$parserOutput = $parser->parse(
* @expectedException MWException
*/
public function testBadFunctionTagHooks( $tag ) {
- global $wgParserConf;
- $parser = new Parser( $wgParserConf );
+ $parser = MediaWikiServices::getInstance()->getParserFactory()->create();
$parser->setFunctionTagHook(
$tag,
use MediaWiki\Auth\AuthManager;
use MediaWiki\MediaWikiServices;
use MediaWiki\Preferences\DefaultPreferencesFactory;
-use Wikimedia\ObjectFactory;
use Wikimedia\TestingAccessWrapper;
/**
public function setUp() {
parent::setUp();
- global $wgParserConf;
$this->context = new RequestContext();
$this->context->setTitle( Title::newFromText( self::class ) );
- $this->setMwGlobals( 'wgParser',
- ObjectFactory::constructClassInstance( $wgParserConf['class'], [ $wgParserConf ] )
- );
- $this->config = MediaWikiServices::getInstance()->getMainConfig();
+
+ $services = MediaWikiServices::getInstance();
+
+ $this->setMwGlobals( 'wgParser', $services->getParserFactory()->create() );
+ $this->config = $services->getMainConfig();
}
/**