jenkins-bot has submitted this change and it was merged.
Change subject: Revert "Allow callback functions for creating SpecialPages."
......................................................................
Revert "Allow callback functions for creating SpecialPages."
This reverts commit 4f0b2f42419c283e8c94a5be6147d54ae7731a6b.
Change-Id: I4b4cec48406e11a26fa44245e598a6c45b429f22
---
M RELEASE-NOTES-1.24
M includes/DefaultSettings.php
M includes/PrefixSearch.php
M includes/api/ApiQuerySiteinfo.php
M includes/specialpage/SpecialPageFactory.php
D tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php
6 files changed, 27 insertions(+), 182 deletions(-)
Approvals:
Reedy: Looks good to me, approved
jenkins-bot: Verified
diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24
index 79b8a49..771a821 100644
--- a/RELEASE-NOTES-1.24
+++ b/RELEASE-NOTES-1.24
@@ -47,8 +47,6 @@
* $wgCompiledFiles has been removed.
* $wgSortSpecialPages was removed, the listing on Special:SpecialPages is
now always sorted.
-* $wgSpecialPages may now use callback functions as an alternative to plain
class names.
- This allows more control over constructor parameters.
* $wgHTCPMulticastAddress, $wgHTCPMulticastRouting and $wgHTCPPort were
removed.
* $wgRC2UDPAddress, $wgRC2UDPInterwikiPrefix, $wgRC2UDPOmitBots, $wgRC2UDPPort
and $wgRC2UDPPrefix have been removed.
@@ -442,8 +440,6 @@
meaning that JavaScript is no longer executed in these browser versions.
* Browser support for Opera 11 lowered from Grade A to Grade C.
* Removed IEFixes module which existed purely to provide support for MSIE
versions
-* Deprecated SpecialPageFactory::getList() in favor of
- SpecialPageFactory::getNames()
below 7 (conditionally loaded only for those browsers).
* Action::checkCanExecute() no longer has a return value.
* Removed cleanupForIRC(), loadFromCurRow(), newFromCurRow(), notifyRC2UDP()
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index a2136fb..6188dcf 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6189,10 +6189,8 @@
$wgValidSkinNames = array();
/**
- * Special page list. This is an associative array mapping the (canonical)
names of
- * special pages to either a class name to be instantiated, or a callback to
use for
- * creating the special page object. In both cases, the result must be an
instance of
- * SpecialPage.
+ * Special page list.
+ * See the top of SpecialPage.php for documentation.
*/
$wgSpecialPages = array();
diff --git a/includes/PrefixSearch.php b/includes/PrefixSearch.php
index 718750f..295183c 100644
--- a/includes/PrefixSearch.php
+++ b/includes/PrefixSearch.php
@@ -195,12 +195,12 @@
// Unlike SpecialPage itself, we want the canonical forms of
both
// canonical and alias title forms...
$keys = array();
- foreach ( SpecialPageFactory::getNames() as $page ) {
+ foreach ( SpecialPageFactory::getList() as $page => $class ) {
$keys[$wgContLang->caseFold( $page )] = $page;
}
foreach ( $wgContLang->getSpecialPageAliases() as $page =>
$aliases ) {
- if ( !in_array( $page, SpecialPageFactory::getNames() )
) {# bug 20885
+ if ( !array_key_exists( $page,
SpecialPageFactory::getList() ) ) {# bug 20885
continue;
}
diff --git a/includes/api/ApiQuerySiteinfo.php
b/includes/api/ApiQuerySiteinfo.php
index 311438f..fd0c429 100644
--- a/includes/api/ApiQuerySiteinfo.php
+++ b/includes/api/ApiQuerySiteinfo.php
@@ -344,7 +344,7 @@
global $wgContLang;
$data = array();
$aliases = $wgContLang->getSpecialPageAliases();
- foreach ( SpecialPageFactory::getNames() as $specialpage ) {
+ foreach ( SpecialPageFactory::getList() as $specialpage =>
$stuff ) {
if ( isset( $aliases[$specialpage] ) ) {
$arr = array( 'realname' => $specialpage,
'aliases' => $aliases[$specialpage] );
$this->getResult()->setIndexedTagName(
$arr['aliases'], 'alias' );
diff --git a/includes/specialpage/SpecialPageFactory.php
b/includes/specialpage/SpecialPageFactory.php
index e0737a0..0138cf9 100644
--- a/includes/specialpage/SpecialPageFactory.php
+++ b/includes/specialpage/SpecialPageFactory.php
@@ -176,43 +176,11 @@
private static $aliases;
/**
- * Reset the internal list of special pages. Useful when changing
$wgSpecialPages after
- * the internal list has already been initialized, e.g. during testing.
- */
- public static function resetList() {
- self::$list = null;
- self::$aliases = null;
- }
-
- /**
- * Returns a list of canonical special page names.
- * May be used to iterate over all registered special pages.
+ * Get the special page list
*
- * @return string[]
+ * @return array
*/
- public static function getNames() {
- return array_keys( get_object_vars( self::getListObject() ) );
- }
-
- /**
- * Get the special page list as an object, with each special page
represented by a member
- * field in the object.
- *
- * @deprecated since 1.24, use getNames() instead.
- * @return object
- */
- public static function getList() {
- wfDeprecated( __FUNCTION__, '1.24' );
- return self::getListObject();
- }
-
- /**
- * Get the special page list as an object, with each special page
represented by a member
- * field in the object.
- *
- * @return object
- */
- private static function getListObject() {
+ static function getList() {
global $wgSpecialPages;
global $wgDisableCounters, $wgDisableInternalSearch,
$wgEmailAuthentication;
global $wgEnableEmail, $wgEnableJavaScriptTest;
@@ -255,8 +223,6 @@
// This hook can be used to remove undesired built-in
special pages
wfRunHooks( 'SpecialPage_initList', array( &self::$list
) );
- self::$list = (object)self::$list;
-
wfProfileOut( __METHOD__ );
}
@@ -271,13 +237,12 @@
* contain at least one entry (English fallbacks will be added if
necessary).
* @return object
*/
- private static function getAliasListObject() {
+ static function getAliasList() {
if ( !is_object( self::$aliases ) ) {
global $wgContLang;
$aliases = $wgContLang->getSpecialPageAliases();
- // Objects are passed by reference by default, need to
create a copy
- $missingPages = clone self::getListObject();
+ $missingPages = self::getList();
self::$aliases = array();
// Check for $aliases being an array since
Language::getSpecialPageAliases can return null
@@ -314,8 +279,8 @@
$caseFoldedAlias = $wgContLang->caseFold( $bits[0] );
$caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
- if ( isset( self::getAliasListObject()->$caseFoldedAlias ) ) {
- $name = self::getAliasListObject()->$caseFoldedAlias;
+ if ( isset( self::getAliasList()->$caseFoldedAlias ) ) {
+ $name = self::getAliasList()->$caseFoldedAlias;
} else {
return array( null, null );
}
@@ -366,7 +331,8 @@
public static function exists( $name ) {
list( $title, /*...*/ ) = self::resolveAlias( $name );
- return property_exists( self::getListObject(), $title );
+ $specialPageList = self::getList();
+ return isset( $specialPageList[$title] );
}
/**
@@ -377,36 +343,22 @@
*/
public static function getPage( $name ) {
list( $realName, /*...*/ ) = self::resolveAlias( $name );
- if ( property_exists( self::getListObject(), $realName ) ) {
- $rec = self::getListObject()->$realName;
-
+ $specialPageList = self::getList();
+ if ( isset( $specialPageList[$realName] ) ) {
+ $rec = $specialPageList[$realName];
if ( is_string( $rec ) ) {
$className = $rec;
- $page = new $className;
- } elseif ( is_callable( $rec ) ) {
- // Use callback to instantiate the special page
- $page = call_user_func( $rec );
+
+ return new $className;
} elseif ( is_array( $rec ) ) {
$className = array_shift( $rec );
// @deprecated, officially since 1.18,
unofficially since forever
wfDeprecated( "Array syntax for
\$wgSpecialPages is deprecated ($className), " .
"define a subclass of SpecialPage
instead.", '1.18' );
- $page = MWFunction::newObj( $className, $rec );
- } elseif ( $rec instanceof SpecialPage ) {
- $page = $rec; //XXX: we should deep clone here
- } else {
- $page = null;
+ $specialPageList[$realName] =
MWFunction::newObj( $className, $rec );
}
- if ( $page instanceof SpecialPage ) {
- return $page;
- } else {
- // It's not a classname, nor a callback, nor a
legacy constructor array,
- // nor a special page object. Give up.
- wfLogWarning( "Cannot instantiate special page
$realName: bad spec!" );
- return null;
- }
-
+ return $specialPageList[$realName];
} else {
return null;
}
@@ -426,7 +378,7 @@
global $wgUser;
$user = $wgUser;
}
- foreach ( self::getListObject() as $name => $rec ) {
+ foreach ( self::getList() as $name => $rec ) {
$page = self::getPage( $name );
if ( $page ) { // not null
$page->setContext( RequestContext::getMain() );
@@ -448,7 +400,7 @@
*/
public static function getRegularPages() {
$pages = array();
- foreach ( self::getListObject() as $name => $rec ) {
+ foreach ( self::getList() as $name => $rec ) {
$page = self::getPage( $name );
if ( $page->isListed() && !$page->isRestricted() ) {
$pages[$name] = $page;
@@ -471,7 +423,7 @@
global $wgUser;
$user = $wgUser;
}
- foreach ( self::getListObject() as $name => $rec ) {
+ foreach ( self::getList() as $name => $rec ) {
$page = self::getPage( $name );
if (
$page->isListed()
@@ -580,7 +532,7 @@
* @param IContextSource $context
* @return string HTML fragment
*/
- public static function capturePath( Title $title, IContextSource
$context ) {
+ static function capturePath( Title $title, IContextSource $context ) {
global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang;
// Save current globals
@@ -617,7 +569,7 @@
* @param string|bool $subpage
* @return string
*/
- public static function getLocalNameFor( $name, $subpage = false ) {
+ static function getLocalNameFor( $name, $subpage = false ) {
global $wgContLang;
$aliases = $wgContLang->getSpecialPageAliases();
@@ -656,7 +608,7 @@
* @param string $alias
* @return Title|null Title or null if there is no such alias
*/
- public static function getTitleForAlias( $alias ) {
+ static function getTitleForAlias( $alias ) {
list( $name, $subpage ) = self::resolveAlias( $alias );
if ( $name != null ) {
return SpecialPage::getTitleFor( $name, $subpage );
diff --git a/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php
b/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php
deleted file mode 100644
index b1d4257..0000000
--- a/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-/**
- * Factory for handling the special page list and generating SpecialPage
objects.
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @covers SpecialPageFactory
- * @group SpecialPage
- */
-class SpecialPageFactoryTest extends MediaWikiTestCase {
-
- public function newSpecialAllPages() {
- return new SpecialAllPages();
- }
-
- public function specialPageProvider() {
- return array(
- 'class name' => array( 'SpecialAllPages', false ),
- 'closure' => array( function() {
- return new SpecialAllPages();
- }, false ),
- 'function' => array( array( $this, 'newSpecialAllPages'
), false ),
- );
- }
-
- /**
- * @dataProvider specialPageProvider
- */
- public function testGetPage( $spec, $shouldReuseInstance ) {
- $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array(
'testdummy' => $spec ) );
-
- SpecialPageFactory::resetList();
-
- $page = SpecialPageFactory::getPage( 'testdummy' );
- $this->assertInstanceOf( 'SpecialPage', $page );
-
- $page2 = SpecialPageFactory::getPage( 'testdummy' );
- $this->assertEquals( $shouldReuseInstance, $page2 === $page,
"Should re-use instance:" );
-
- SpecialPageFactory::resetList();
- }
-
- public function testGetNames() {
- $this->mergeMwGlobalArrayValue( 'wgSpecialPages', array(
'testdummy' => 'SpecialAllPages' ) );
-
- SpecialPageFactory::resetList();
- $names = SpecialPageFactory::getNames();
- $this->assertInternalType( 'array', $names );
- $this->assertContains( 'testdummy', $names );
- SpecialPageFactory::resetList();
- }
-
- public function testResolveAlias() {
- $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
-
- SpecialPageFactory::resetList();
-
- list( $name, $param ) = SpecialPageFactory::resolveAlias(
'Spezialseiten/Foo' );
- $this->assertEquals( 'Specialpages', $name );
- $this->assertEquals( 'Foo', $param );
-
- SpecialPageFactory::resetList();
- }
-
- public function testGetLocalNameFor() {
- $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
-
- SpecialPageFactory::resetList();
-
- $name = SpecialPageFactory::getLocalNameFor( 'Specialpages',
'Foo' );
- $this->assertEquals( 'Spezialseiten/Foo', $name );
-
- SpecialPageFactory::resetList();
- }
-
- public function testGetTitleForAlias() {
- $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
-
- SpecialPageFactory::resetList();
-
- $title = SpecialPageFactory::getTitleForAlias(
'Specialpages/Foo' );
- $this->assertEquals( 'Spezialseiten/Foo', $title->getText() );
- $this->assertEquals( NS_SPECIAL, $title->getNamespace() );
-
- SpecialPageFactory::resetList();
- }
-
-}
--
To view, visit https://gerrit.wikimedia.org/r/161326
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4b4cec48406e11a26fa44245e598a6c45b429f22
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.24wmf22
Gerrit-Owner: Reedy <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits