If the special page object was already created for the request, there's
no need to create the object again. Save the created result (object, null)
in a global static array and return the value if the realName was already
created.
Bug: T123995
Change-Id: I70bf0e93e45f4b0597deaef717f5eb87c66f0a71
private static $list;
private static $aliases;
private static $list;
private static $aliases;
+ private static $pageObjectCache = [];
/**
* Reset the internal list of special pages. Useful when changing $wgSpecialPages after
/**
* Reset the internal list of special pages. Useful when changing $wgSpecialPages after
public static function resetList() {
self::$list = null;
self::$aliases = null;
public static function resetList() {
self::$list = null;
self::$aliases = null;
+ self::$pageObjectCache = [];
public static function getPage( $name ) {
list( $realName, /*...*/ ) = self::resolveAlias( $name );
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] ) ) {
$specialPageList = self::getPageList();
if ( isset( $specialPageList[$realName] ) ) {
+ self::$pageObjectCache[$realName] = $page;
if ( $page instanceof SpecialPage ) {
return $page;
} else {
if ( $page instanceof SpecialPage ) {
return $page;
} else {
$specialPageTestHelper = new SpecialPageTestHelper();
return [
$specialPageTestHelper = new SpecialPageTestHelper();
return [
- 'class name' => [ 'SpecialAllPages', false ],
+ 'class name' => [ 'SpecialAllPages' ],
'closure' => [ function () {
return new SpecialAllPages();
'closure' => [ function () {
return new SpecialAllPages();
- }, false ],
- 'function' => [ [ $this, 'newSpecialAllPages' ], false ],
- 'callback string' => [ 'SpecialPageTestHelper::newSpecialAllPages', false ],
+ } ],
+ 'function' => [ [ $this, 'newSpecialAllPages' ] ],
+ 'callback string' => [ 'SpecialPageTestHelper::newSpecialAllPages' ],
'callback with object' => [
'callback with object' => [
- [ $specialPageTestHelper, 'newSpecialAllPages' ],
- false
+ [ $specialPageTestHelper, 'newSpecialAllPages' ]
- [ 'SpecialPageTestHelper', 'newSpecialAllPages' ],
- false
+ [ 'SpecialPageTestHelper', 'newSpecialAllPages' ]
* @covers SpecialPageFactory::getPage
* @dataProvider specialPageProvider
*/
* @covers SpecialPageFactory::getPage
* @dataProvider specialPageProvider
*/
- public function testGetPage( $spec, $shouldReuseInstance ) {
+ public function testGetPage( $spec ) {
$this->mergeMwGlobalArrayValue( 'wgSpecialPages', [ 'testdummy' => $spec ] );
SpecialPageFactory::resetList();
$this->mergeMwGlobalArrayValue( 'wgSpecialPages', [ 'testdummy' => $spec ] );
SpecialPageFactory::resetList();
$this->assertInstanceOf( 'SpecialPage', $page );
$page2 = SpecialPageFactory::getPage( 'testdummy' );
$this->assertInstanceOf( 'SpecialPage', $page );
$page2 = SpecialPageFactory::getPage( 'testdummy' );
- $this->assertEquals( $shouldReuseInstance, $page2 === $page, "Should re-use instance:" );
+ $this->assertEquals( true, $page2 === $page, "Should re-use instance:" );