Merge "Revert "Don't construct SpecialPages twice""
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 10 Nov 2016 06:00:17 +0000 (06:00 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 10 Nov 2016 06:00:17 +0000 (06:00 +0000)
1  2 
includes/specialpage/SpecialPageFactory.php
tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php

@@@ -21,7 -21,6 +21,7 @@@
   * @ingroup SpecialPage
   * @defgroup SpecialPage SpecialPage
   */
 +use MediaWiki\Linker\LinkRenderer;
  
  /**
   * Factory for handling the special page list and generating SpecialPage objects.
@@@ -82,17 -81,11 +82,17 @@@ class SpecialPageFactory 
                'PagesWithProp' => 'SpecialPagesWithProp',
                'TrackingCategories' => 'SpecialTrackingCategories',
  
 -              // Login/create account
 -              'Userlogin' => 'LoginForm',
 +              // Authentication
 +              'Userlogin' => 'SpecialUserLogin',
 +              'Userlogout' => 'SpecialUserLogout',
                'CreateAccount' => 'SpecialCreateAccount',
 +              'LinkAccounts' => 'SpecialLinkAccounts',
 +              'UnlinkAccounts' => 'SpecialUnlinkAccounts',
 +              'ChangeCredentials' => 'SpecialChangeCredentials',
 +              'RemoveCredentials' => 'SpecialRemoveCredentials',
  
                // Users and rights
 +              'Activeusers' => 'SpecialActiveUsers',
                'Block' => 'SpecialBlock',
                'Unblock' => 'SpecialUnblock',
                'BlockList' => 'SpecialBlockList',
                'Revisiondelete' => 'SpecialRevisionDelete',
                'RunJobs' => 'SpecialRunJobs',
                'Specialpages' => 'SpecialSpecialpages',
 -              'Userlogout' => 'SpecialUserlogout',
        ];
  
        private static $list;
        private static $aliases;
-       private static $pageObjectCache = [];
  
        /**
         * Reset the internal list of special pages. Useful when changing $wgSpecialPages after
        public static function resetList() {
                self::$list = null;
                self::$aliases = null;
-               self::$pageObjectCache = [];
        }
  
        /**
                                self::$list['ChangeContentModel'] = 'SpecialChangeContentModel';
                        }
  
 -                      self::$list['Activeusers'] = 'SpecialActiveUsers';
 -
                        // Add extension special pages
                        self::$list = array_merge( self::$list, $wgSpecialPages );
  
        public static function getPage( $name ) {
                list( $realName, /*...*/ ) = self::resolveAlias( $name );
  
-               if ( isset( self::$pageObjectCache[$realName] ) ) {
-                       return self::$pageObjectCache[$realName];
-               }
                $specialPageList = self::getPageList();
  
                if ( isset( $specialPageList[$realName] ) ) {
                                $page = null;
                        }
  
-                       self::$pageObjectCache[$realName] = $page;
                        if ( $page instanceof SpecialPage ) {
                                return $page;
                        } else {
         * @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];
                        $trxProfiler = Profiler::instance()->getTransactionProfiler();
                        if ( $context->getRequest()->wasPosted() && !$page->doesWrites() ) {
                                $trxProfiler->setExpectations( $trxLimits['POST-nonwrite'], __METHOD__ );
 +                              $context->getRequest()->markAsSafeRequest();
                        }
                }
  
                }
  
                $page->including( $including );
 +              if ( $linkRenderer ) {
 +                      $page->setLinkRenderer( $linkRenderer );
 +              }
  
                // Execute special page
                $page->run( $par );
         *
         * @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();
  
                $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'];
                }
  
                if ( $subpage !== false && !is_null( $subpage ) ) {
 +                      // Make sure it's in dbkey form
 +                      $subpage = str_replace( ' ', '_', $subpage );
                        $name = "$name/$subpage";
                }
  
@@@ -1,6 -1,4 +1,6 @@@
  <?php
 +use Wikimedia\ScopedCallback;
 +
  /**
   * Factory for handling the special page list and generating SpecialPage objects.
   *
@@@ -57,17 -55,19 +57,19 @@@ class SpecialPageFactoryTest extends Me
                $specialPageTestHelper = new SpecialPageTestHelper();
  
                return [
-                       'class name' => [ 'SpecialAllPages' ],
+                       'class name' => [ 'SpecialAllPages', false ],
                        'closure' => [ function () {
                                return new SpecialAllPages();
-                       } ],
-                       'function' => [ [ $this, 'newSpecialAllPages' ] ],
-                       'callback string' => [ 'SpecialPageTestHelper::newSpecialAllPages' ],
+                       }, false ],
+                       'function' => [ [ $this, 'newSpecialAllPages' ], false ],
+                       'callback string' => [ 'SpecialPageTestHelper::newSpecialAllPages', false ],
                        'callback with object' => [
-                               [ $specialPageTestHelper, 'newSpecialAllPages' ]
+                               [ $specialPageTestHelper, 'newSpecialAllPages' ],
+                               false
                        ],
                        'callback array' => [
-                               [ 'SpecialPageTestHelper', 'newSpecialAllPages' ]
+                               [ 'SpecialPageTestHelper', 'newSpecialAllPages' ],
+                               false
                        ]
                ];
        }
@@@ -76,7 -76,7 +78,7 @@@
         * @covers SpecialPageFactory::getPage
         * @dataProvider specialPageProvider
         */
-       public function testGetPage( $spec ) {
+       public function testGetPage( $spec, $shouldReuseInstance ) {
                $this->mergeMwGlobalArrayValue( 'wgSpecialPages', [ 'testdummy' => $spec ] );
                SpecialPageFactory::resetList();
  
@@@ -84,7 -84,7 +86,7 @@@
                $this->assertInstanceOf( 'SpecialPage', $page );
  
                $page2 = SpecialPageFactory::getPage( 'testdummy' );
-               $this->assertEquals( true, $page2 === $page, "Should re-use instance:" );
+               $this->assertEquals( $shouldReuseInstance, $page2 === $page, "Should re-use instance:" );
        }
  
        /**