Add SpecialPage::getLinkRenderer()
authorKunal Mehta <legoktm@member.fsf.org>
Wed, 22 Jun 2016 21:30:30 +0000 (23:30 +0200)
committerKunal Mehta <legoktm@member.fsf.org>
Wed, 22 Jun 2016 21:32:00 +0000 (23:32 +0200)
And SpecialPage::setLinkRenderer(), so the Parser can pass on its
LinkRenderer instance for when special pages are being included in a
page.

Change-Id: If9a9c648ab670b824ce534e7cf0d20d41e1bfd12

includes/parser/Parser.php
includes/specialpage/SpecialPage.php
includes/specialpage/SpecialPageFactory.php

index aca32ed..65dde21 100644 (file)
@@ -3147,7 +3147,7 @@ class Parser {
                                                $context->setUser( User::newFromName( '127.0.0.1', false ) );
                                        }
                                        $context->setLanguage( $this->mOptions->getUserLangObj() );
-                                       $ret = SpecialPageFactory::capturePath( $title, $context );
+                                       $ret = SpecialPageFactory::capturePath( $title, $context, $this->getLinkRenderer() );
                                        if ( $ret ) {
                                                $text = $context->getOutput()->getHTML();
                                                $this->mOutput->addOutputPageMetadata( $context->getOutput() );
index f478203..35ecc6e 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-use MediaWiki\MediaWikiServices;
-
 /**
  * Parent class for all special pages.
  *
@@ -24,6 +22,8 @@ use MediaWiki\MediaWikiServices;
  */
 
 use MediaWiki\Auth\AuthManager;
+use MediaWiki\Linker\LinkRenderer;
+use MediaWiki\MediaWikiServices;
 
 /**
  * Parent class for all special pages.
@@ -60,6 +60,11 @@ class SpecialPage {
         */
        protected $mContext;
 
+       /**
+        * @var LinkRenderer|null
+        */
+       private $linkRenderer;
+
        /**
         * Get a localised Title object for a specified special page name
         *
@@ -826,4 +831,24 @@ class SpecialPage {
                        wfTransactionalTimeLimit();
                }
        }
+
+       /**
+        * @since 1.28
+        * @return LinkRenderer
+        */
+       protected function getLinkRenderer() {
+               if ( $this->linkRenderer ) {
+                       return $this->linkRenderer;
+               } else {
+                       return MediaWikiServices::getInstance()->getLinkRenderer();
+               }
+       }
+
+       /**
+        * @since 1.28
+        * @param LinkRenderer $linkRenderer
+        */
+       public function setLinkRenderer( LinkRenderer $linkRenderer ) {
+               $this->linkRenderer = $linkRenderer;
+       }
 }
index 73efa4e..b69b28a 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup SpecialPage
  * @defgroup SpecialPage SpecialPage
  */
+use MediaWiki\Linker\LinkRenderer;
 
 /**
  * Factory for handling the special page list and generating SpecialPage objects.
@@ -523,10 +524,13 @@ class SpecialPageFactory {
         * @param Title $title
         * @param IContextSource $context
         * @param bool $including Bool output is being captured for use in {{special:whatever}}
+        * @param LinkRenderer|null $linkRenderer (since 1.28)
         *
         * @return bool
         */
-       public static function executePath( Title &$title, IContextSource &$context, $including = false ) {
+       public static function executePath( Title &$title, IContextSource &$context, $including = false,
+               LinkRenderer $linkRenderer = null
+       ) {
                // @todo FIXME: Redirects broken due to this call
                $bits = explode( '/', $title->getDBkey(), 2 );
                $name = $bits[0];
@@ -586,6 +590,9 @@ class SpecialPageFactory {
                }
 
                $page->including( $including );
+               if ( $linkRenderer ) {
+                       $page->setLinkRenderer( $linkRenderer );
+               }
 
                // Execute special page
                $page->run( $par );
@@ -605,9 +612,12 @@ class SpecialPageFactory {
         *
         * @param Title $title
         * @param IContextSource $context
+        * @param LinkRenderer|null $linkRenderer (since 1.28)
         * @return string HTML fragment
         */
-       public static function capturePath( Title $title, IContextSource $context ) {
+       public static function capturePath(
+               Title $title, IContextSource $context, LinkRenderer $linkRenderer = null
+       ) {
                global $wgTitle, $wgOut, $wgRequest, $wgUser, $wgLang;
                $main = RequestContext::getMain();
 
@@ -640,7 +650,7 @@ class SpecialPageFactory {
                $main->setLanguage( $context->getLanguage() );
 
                // The useful part
-               $ret = self::executePath( $title, $context, true );
+               $ret = self::executePath( $title, $context, true, $linkRenderer );
 
                // Restore old globals and context
                $wgTitle = $glob['title'];