From 28522551862160da1e6e2a31545f4bdcc30c908a Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Tue, 14 Aug 2018 18:11:59 -0700 Subject: [PATCH] Inject SpecialPageFactory into Parser Change-Id: I6a6a94cbdafdc724ce02408cd9e744e7b3eda92b --- includes/ServiceWiring.php | 3 ++- includes/parser/Parser.php | 20 +++++++++++++------- includes/parser/ParserFactory.php | 13 ++++++++++--- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index e710575beb..286dde197d 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -386,7 +386,8 @@ return [ $services->getMainConfig()->get( 'ParserConf' ), $services->getMagicWordFactory(), $services->getContentLanguage(), - wfUrlProtocols() + wfUrlProtocols(), + $services->getSpecialPageFactory() ); }, diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 1fc2f9272b..6bee1692c4 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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() ); diff --git a/includes/parser/ParserFactory.php b/includes/parser/ParserFactory.php index 646f8552cd..4238b2750a 100644 --- a/includes/parser/ParserFactory.php +++ b/includes/parser/ParserFactory.php @@ -1,5 +1,4 @@ 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 ); } } -- 2.20.1