From 80590a15dc3daac70ca9cdfb684dc6a70b5eeabd Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Sun, 5 Aug 2018 15:50:01 +0300 Subject: [PATCH] Update Parser to use NamespaceInfo Change-Id: I668a51487786e4ab05a153ca3995388e79c13b42 --- includes/ServiceWiring.php | 3 ++- includes/parser/Parser.php | 19 ++++++++++++------- includes/parser/ParserFactory.php | 16 +++++++++++++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 750c964830..3543ff8b83 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -373,7 +373,8 @@ return [ wfUrlProtocols(), $services->getSpecialPageFactory(), $services->getMainConfig(), - $services->getLinkRendererFactory() + $services->getLinkRendererFactory(), + $services->getNamespaceInfo() ); }, diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 47e5b409ff..9ff731d801 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -280,6 +280,9 @@ class Parser { /** @var LinkRendererFactory */ private $linkRendererFactory; + /** @var NamespaceInfo */ + private $nsInfo; + /** * @param array $parserConf See $wgParserConf documentation * @param MagicWordFactory|null $magicWordFactory @@ -289,12 +292,14 @@ class Parser { * @param SpecialPageFactory|null $spFactory * @param Config|null $siteConfig * @param LinkRendererFactory|null $linkRendererFactory + * @param NamespaceInfo|null $nsInfo */ public function __construct( array $parserConf = [], MagicWordFactory $magicWordFactory = null, Language $contLang = null, ParserFactory $factory = null, $urlProtocols = null, SpecialPageFactory $spFactory = null, Config $siteConfig = null, - LinkRendererFactory $linkRendererFactory = null + LinkRendererFactory $linkRendererFactory = null, + NamespaceInfo $nsInfo = null ) { $this->mConf = $parserConf; $this->mUrlProtocols = $urlProtocols ?? wfUrlProtocols(); @@ -325,10 +330,10 @@ class Parser { $this->factory = $factory ?? $services->getParserFactory(); $this->specialPageFactory = $spFactory ?? $services->getSpecialPageFactory(); - $this->siteConfig = $siteConfig ?? MediaWikiServices::getInstance()->getMainConfig(); - + $this->siteConfig = $siteConfig ?? $services->getMainConfig(); $this->linkRendererFactory = - $linkRendererFactory ?? MediaWikiServices::getInstance()->getLinkRendererFactory(); + $linkRendererFactory ?? $services->getLinkRendererFactory(); + $this->nsInfo = $nsInfo ?? $services->getNamespaceInfo(); } /** @@ -2529,7 +2534,7 @@ class Parser { */ public function areSubpagesAllowed() { # Some namespaces don't allow subpages - return MWNamespace::hasSubpages( $this->mTitle->getNamespace() ); + return $this->nsInfo->hasSubpages( $this->mTitle->getNamespace() ); } /** @@ -2600,7 +2605,7 @@ class Parser { $this->siteConfig->get( 'MiserMode' ) && !$this->mOptions->getInterfaceMessage() && // @TODO: disallow this word on all namespaces - MWNamespace::isContent( $this->mTitle->getNamespace() ) + $this->nsInfo->isContent( $this->mTitle->getNamespace() ) ) { return $this->mRevisionId ? '-' : ''; }; @@ -3339,7 +3344,7 @@ class Parser { ); } } - } elseif ( MWNamespace::isNonincludable( $title->getNamespace() ) ) { + } elseif ( $this->nsInfo->isNonincludable( $title->getNamespace() ) ) { $found = false; # access denied wfDebug( __METHOD__ . ": template inclusion denied for " . $title->getPrefixedDBkey() . "\n" ); diff --git a/includes/parser/ParserFactory.php b/includes/parser/ParserFactory.php index 05c0622d96..cddacf43c5 100644 --- a/includes/parser/ParserFactory.php +++ b/includes/parser/ParserFactory.php @@ -19,7 +19,7 @@ * @ingroup Parser */ use MediaWiki\Linker\LinkRendererFactory; - +use MediaWiki\MediaWikiServices; use MediaWiki\Special\SpecialPageFactory; /** @@ -47,6 +47,9 @@ class ParserFactory { /** @var LinkRendererFactory */ private $linkRendererFactory; + /** @var NamespaceInfo */ + private $nsInfo; + /** * @param array $parserConf See $wgParserConf documentation * @param MagicWordFactory $magicWordFactory @@ -55,12 +58,18 @@ class ParserFactory { * @param SpecialPageFactory $spFactory * @param Config $siteConfig * @param LinkRendererFactory $linkRendererFactory + * @param NamespaceInfo|null $nsInfo * @since 1.32 */ public function __construct( array $parserConf, MagicWordFactory $magicWordFactory, Language $contLang, $urlProtocols, - SpecialPageFactory $spFactory, Config $siteConfig, LinkRendererFactory $linkRendererFactory + SpecialPageFactory $spFactory, Config $siteConfig, + LinkRendererFactory $linkRendererFactory, NamespaceInfo $nsInfo = null ) { + if ( !$nsInfo ) { + wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' ); + $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo(); + } $this->parserConf = $parserConf; $this->magicWordFactory = $magicWordFactory; $this->contLang = $contLang; @@ -68,6 +77,7 @@ class ParserFactory { $this->specialPageFactory = $spFactory; $this->siteConfig = $siteConfig; $this->linkRendererFactory = $linkRendererFactory; + $this->nsInfo = $nsInfo; } /** @@ -77,6 +87,6 @@ class ParserFactory { public function create() : Parser { return new Parser( $this->parserConf, $this->magicWordFactory, $this->contLang, $this, $this->urlProtocols, $this->specialPageFactory, $this->siteConfig, - $this->linkRendererFactory ); + $this->linkRendererFactory, $this->nsInfo ); } } -- 2.20.1