From 21f7ab7e228614e1feb3c645b70b6fb7bb07afc6 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Wed, 8 Aug 2018 17:57:31 +0300 Subject: [PATCH] Inject LinkRendererFactory into Parser Change-Id: Idaf5a0f897dc3bd2aa9bf03be280281836bfc645 --- includes/ServiceWiring.php | 3 ++- includes/parser/Parser.php | 15 ++++++++++++--- includes/parser/ParserFactory.php | 11 +++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index cccb5e733f..70a4cd424f 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -368,7 +368,8 @@ return [ $services->getContentLanguage(), wfUrlProtocols(), $services->getSpecialPageFactory(), - $services->getMainConfig() + $services->getMainConfig(), + $services->getLinkRendererFactory() ); }, diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 0ced8a14e8..47e5b409ff 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -21,6 +21,7 @@ * @ingroup Parser */ use MediaWiki\Linker\LinkRenderer; +use MediaWiki\Linker\LinkRendererFactory; use MediaWiki\MediaWikiServices; use MediaWiki\Special\SpecialPageFactory; use Wikimedia\ScopedCallback; @@ -276,6 +277,9 @@ class Parser { /** @var Config */ private $siteConfig; + /** @var LinkRendererFactory */ + private $linkRendererFactory; + /** * @param array $parserConf See $wgParserConf documentation * @param MagicWordFactory|null $magicWordFactory @@ -284,11 +288,13 @@ class Parser { * @param string|null $urlProtocols As returned from wfUrlProtocols() * @param SpecialPageFactory|null $spFactory * @param Config|null $siteConfig + * @param LinkRendererFactory|null $linkRendererFactory */ public function __construct( array $parserConf = [], MagicWordFactory $magicWordFactory = null, Language $contLang = null, ParserFactory $factory = null, $urlProtocols = null, - SpecialPageFactory $spFactory = null, Config $siteConfig = null + SpecialPageFactory $spFactory = null, Config $siteConfig = null, + LinkRendererFactory $linkRendererFactory = null ) { $this->mConf = $parserConf; $this->mUrlProtocols = $urlProtocols ?? wfUrlProtocols(); @@ -320,6 +326,9 @@ class Parser { $this->factory = $factory ?? $services->getParserFactory(); $this->specialPageFactory = $spFactory ?? $services->getSpecialPageFactory(); $this->siteConfig = $siteConfig ?? MediaWikiServices::getInstance()->getMainConfig(); + + $this->linkRendererFactory = + $linkRendererFactory ?? MediaWikiServices::getInstance()->getLinkRendererFactory(); } /** @@ -973,9 +982,9 @@ class Parser { * @return LinkRenderer */ public function getLinkRenderer() { + // XXX We make the LinkRenderer with current options and then cache it forever if ( !$this->mLinkRenderer ) { - $this->mLinkRenderer = MediaWikiServices::getInstance() - ->getLinkRendererFactory()->create(); + $this->mLinkRenderer = $this->linkRendererFactory->create(); $this->mLinkRenderer->setStubThreshold( $this->getOptions()->getStubThreshold() ); diff --git a/includes/parser/ParserFactory.php b/includes/parser/ParserFactory.php index eb05aced0d..05c0622d96 100644 --- a/includes/parser/ParserFactory.php +++ b/includes/parser/ParserFactory.php @@ -18,6 +18,7 @@ * @file * @ingroup Parser */ +use MediaWiki\Linker\LinkRendererFactory; use MediaWiki\Special\SpecialPageFactory; @@ -43,6 +44,9 @@ class ParserFactory { /** @var Config */ private $siteConfig; + /** @var LinkRendererFactory */ + private $linkRendererFactory; + /** * @param array $parserConf See $wgParserConf documentation * @param MagicWordFactory $magicWordFactory @@ -50,11 +54,12 @@ class ParserFactory { * @param string $urlProtocols As returned from wfUrlProtocols() * @param SpecialPageFactory $spFactory * @param Config $siteConfig + * @param LinkRendererFactory $linkRendererFactory * @since 1.32 */ public function __construct( array $parserConf, MagicWordFactory $magicWordFactory, Language $contLang, $urlProtocols, - SpecialPageFactory $spFactory, Config $siteConfig + SpecialPageFactory $spFactory, Config $siteConfig, LinkRendererFactory $linkRendererFactory ) { $this->parserConf = $parserConf; $this->magicWordFactory = $magicWordFactory; @@ -62,6 +67,7 @@ class ParserFactory { $this->urlProtocols = $urlProtocols; $this->specialPageFactory = $spFactory; $this->siteConfig = $siteConfig; + $this->linkRendererFactory = $linkRendererFactory; } /** @@ -70,6 +76,7 @@ class ParserFactory { */ public function create() : Parser { return new Parser( $this->parserConf, $this->magicWordFactory, $this->contLang, $this, - $this->urlProtocols, $this->specialPageFactory, $this->siteConfig ); + $this->urlProtocols, $this->specialPageFactory, $this->siteConfig, + $this->linkRendererFactory ); } } -- 2.20.1