Inject SpecialPageFactory into Parser
authorKunal Mehta <legoktm@member.fsf.org>
Wed, 15 Aug 2018 01:11:59 +0000 (18:11 -0700)
committerJames D. Forrester <jforrester@wikimedia.org>
Fri, 17 Aug 2018 19:03:13 +0000 (12:03 -0700)
Change-Id: I6a6a94cbdafdc724ce02408cd9e744e7b3eda92b

includes/ServiceWiring.php
includes/parser/Parser.php
includes/parser/ParserFactory.php

index e710575..286dde1 100644 (file)
@@ -386,7 +386,8 @@ return [
                        $services->getMainConfig()->get( 'ParserConf' ),
                        $services->getMagicWordFactory(),
                        $services->getContentLanguage(),
-                       wfUrlProtocols()
+                       wfUrlProtocols(),
+                       $services->getSpecialPageFactory()
                );
        },
 
index 1fc2f92..6bee169 100644 (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() );
index 646f855..4238b27 100644 (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 );
        }
 }