Inject SpecialPageFactory into Parser

Change-Id: I6a6a94cbdafdc724ce02408cd9e744e7b3eda92b
This commit is contained in:
Kunal Mehta 2018-08-14 18:11:59 -07:00 committed by James D. Forrester
parent e68fdb4065
commit 2852255186
3 changed files with 25 additions and 11 deletions

View file

@ -386,7 +386,8 @@ return [
$services->getMainConfig()->get( 'ParserConf' ),
$services->getMagicWordFactory(),
$services->getContentLanguage(),
wfUrlProtocols()
wfUrlProtocols(),
$services->getSpecialPageFactory()
);
},

View file

@ -22,6 +22,7 @@
*/
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\MediaWikiServices;
use MediaWiki\Special\SpecialPageFactory;
use Wikimedia\ScopedCallback;
/**
@ -269,16 +270,20 @@ class Parser {
/** @var ParserFactory */
private $factory;
/** @var SpecialPageFactory */
private $specialPageFactory;
/**
* @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()
* @param SpecialPageFactory|null $spFactory
*/
public function __construct(
array $conf = [], MagicWordFactory $magicWordFactory = null, Language $contLang = null,
ParserFactory $factory = null, $urlProtocols = null
ParserFactory $factory = null, $urlProtocols = null, SpecialPageFactory $spFactory = null
) {
$this->mConf = $conf;
$this->mUrlProtocols = $urlProtocols ?? wfUrlProtocols();
@ -301,12 +306,14 @@ class Parser {
}
wfDebug( __CLASS__ . ": using preprocessor: {$this->mPreprocessorClass}\n" );
$services = MediaWikiServices::getInstance();
$this->magicWordFactory = $magicWordFactory ??
MediaWikiServices::getInstance()->getMagicWordFactory();
$services->getMagicWordFactory();
$this->contLang = $contLang ?? MediaWikiServices::getInstance()->getContentLanguage();
$this->contLang = $contLang ?? $services->getContentLanguage();
$this->factory = $factory ?? MediaWikiServices::getInstance()->getParserFactory();
$this->factory = $factory ?? $services->getParserFactory();
$this->specialPageFactory = $spFactory ?? $services->getSpecialPageFactory();
}
/**
@ -3244,7 +3251,7 @@ class Parser {
&& $this->mOptions->getAllowSpecialInclusion()
&& $this->ot['html']
) {
$specialPage = SpecialPageFactory::getPage( $title->getDBkey() );
$specialPage = $this->specialPageFactory->getPage( $title->getDBkey() );
// Pass the template arguments as URL parameters.
// "uselang" will have no effect since the Language object
// is forced to the one defined in ParserOptions.
@ -3270,8 +3277,7 @@ class Parser {
$context->setUser( User::newFromName( '127.0.0.1', false ) );
}
$context->setLanguage( $this->mOptions->getUserLangObj() );
$ret = SpecialPageFactory::capturePath(
$title, $context, $this->getLinkRenderer() );
$ret = $this->specialPageFactory->capturePath( $title, $context, $this->getLinkRenderer() );
if ( $ret ) {
$text = $context->getOutput()->getHTML();
$this->mOutput->addOutputPageMetadata( $context->getOutput() );

View file

@ -1,5 +1,4 @@
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,6 +19,8 @@
* @ingroup Parser
*/
use MediaWiki\Special\SpecialPageFactory;
/**
* @since 1.32
*/
@ -36,20 +37,26 @@ class ParserFactory {
/** @var string */
private $urlProtocols;
/** @var SpecialPageFactory */
private $specialPageFactory;
/**
* @param array $conf See $wgParserConf documentation
* @param MagicWordFactory $magicWordFactory
* @param Language $contLang Content language
* @param string $urlProtocols As returned from wfUrlProtocols()
* @param SpecialPageFactory $spFactory
* @since 1.32
*/
public function __construct(
array $conf, MagicWordFactory $magicWordFactory, Language $contLang, $urlProtocols
array $conf, MagicWordFactory $magicWordFactory, Language $contLang, $urlProtocols,
SpecialPageFactory $spFactory
) {
$this->conf = $conf;
$this->magicWordFactory = $magicWordFactory;
$this->contLang = $contLang;
$this->urlProtocols = $urlProtocols;
$this->specialPageFactory = $spFactory;
}
/**
@ -58,6 +65,6 @@ class ParserFactory {
*/
public function create() : Parser {
return new Parser( $this->conf, $this->magicWordFactory, $this->contLang, $this,
$this->urlProtocols );
$this->urlProtocols, $this->specialPageFactory );
}
}