/**
* List of special page names to the subclass of SpecialPage which handles them.
*/
- private static $coreList = array(
+ private static $coreList = [
// Maintenance Reports
'BrokenRedirects' => 'BrokenRedirectsPage',
'Deadendpages' => 'DeadendPagesPage',
'ListDuplicatedFiles' => 'ListDuplicatedFilesPage',
// Data and tools
+ 'ApiSandbox' => 'SpecialApiSandbox',
'Statistics' => 'SpecialStatistics',
'Allmessages' => 'SpecialAllMessages',
'Version' => 'SpecialVersion',
'RunJobs' => 'SpecialRunJobs',
'Specialpages' => 'SpecialSpecialpages',
'Userlogout' => 'SpecialUserlogout',
- );
+ ];
private static $list;
private static $aliases;
// This hook can be used to disable unwanted core special pages
// or conditionally register special pages.
- Hooks::run( 'SpecialPage_initList', array( &self::$list ) );
+ Hooks::run( 'SpecialPage_initList', [ &self::$list ] );
}
$aliases = $wgContLang->getSpecialPageAliases();
$pageList = self::getPageList();
- self::$aliases = array();
- $keepAlias = array();
+ self::$aliases = [];
+ $keepAlias = [];
// Force every canonical name to be an alias for itself.
foreach ( $pageList as $name => $stuff ) {
if ( isset( $aliases[$caseFoldedAlias] ) ) {
$name = $aliases[$caseFoldedAlias];
} else {
- return array( null, null );
+ return [ null, null ];
}
if ( !isset( $bits[1] ) ) { // bug 2087
$par = $bits[1];
}
- return array( $name, $par );
+ return [ $name, $par ];
}
/**
// @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 = ObjectFactory::getObjectFromSpec( array(
+ $page = ObjectFactory::getObjectFromSpec( [
'class' => $className,
'args' => $rec,
'closure_expansion' => false,
- ) );
+ ] );
} elseif ( $rec instanceof SpecialPage ) {
$page = $rec; // XXX: we should deep clone here
} else {
* @return array ( string => Specialpage )
*/
public static function getUsablePages( User $user = null ) {
- $pages = array();
+ $pages = [];
if ( $user === null ) {
global $wgUser;
$user = $wgUser;
* @return array ( string => Specialpage )
*/
public static function getRegularPages() {
- $pages = array();
+ $pages = [];
foreach ( self::getPageList() as $name => $rec ) {
$page = self::getPage( $name );
if ( $page->isListed() && !$page->isRestricted() ) {
* @return array ( string => Specialpage )
*/
public static function getRestrictedPages( User $user = null ) {
- $pages = array();
+ $pages = [];
if ( $user === null ) {
global $wgUser;
$user = $wgUser;
* @return string HTML fragment
*/
public static function capturePath( Title $title, IContextSource $context ) {
- global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang;
-
- // Save current globals
- $oldTitle = $wgTitle;
- $oldOut = $wgOut;
- $oldRequest = $wgRequest;
- $oldUser = $wgUser;
- $oldLang = $wgLang;
-
- // Set the globals to the current context
+ global $wgTitle, $wgOut, $wgRequest, $wgUser, $wgLang;
+ $main = RequestContext::getMain();
+
+ // Save current globals and main context
+ $glob = [
+ 'title' => $wgTitle,
+ 'output' => $wgOut,
+ 'request' => $wgRequest,
+ 'user' => $wgUser,
+ 'language' => $wgLang,
+ ];
+ $ctx = [
+ 'title' => $main->getTitle(),
+ 'output' => $main->getOutput(),
+ 'request' => $main->getRequest(),
+ 'user' => $main->getUser(),
+ 'language' => $main->getLanguage(),
+ ];
+
+ // Override
$wgTitle = $title;
$wgOut = $context->getOutput();
$wgRequest = $context->getRequest();
$wgUser = $context->getUser();
$wgLang = $context->getLanguage();
+ $main->setTitle( $title );
+ $main->setOutput( $context->getOutput() );
+ $main->setRequest( $context->getRequest() );
+ $main->setUser( $context->getUser() );
+ $main->setLanguage( $context->getLanguage() );
// The useful part
$ret = self::executePath( $title, $context, true );
- // And restore the old globals
- $wgTitle = $oldTitle;
- $wgOut = $oldOut;
- $wgRequest = $oldRequest;
- $wgUser = $oldUser;
- $wgLang = $oldLang;
+ // Restore old globals and context
+ $wgTitle = $glob['title'];
+ $wgOut = $glob['output'];
+ $wgRequest = $glob['request'];
+ $wgUser = $glob['user'];
+ $wgLang = $glob['language'];
+ $main->setTitle( $ctx['title'] );
+ $main->setOutput( $ctx['output'] );
+ $main->setRequest( $ctx['request'] );
+ $main->setUser( $ctx['user'] );
+ $main->setLanguage( $ctx['language'] );
return $ret;
}