Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / specialpage / SpecialPageFactory.php
index 3babafd..8ce480e 100644 (file)
@@ -47,7 +47,7 @@ class SpecialPageFactory {
        /**
         * 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',
@@ -90,6 +90,7 @@ class SpecialPageFactory {
                'Unblock' => 'SpecialUnblock',
                'BlockList' => 'SpecialBlockList',
                'ChangePassword' => 'SpecialChangePassword',
+               'BotPasswords' => 'SpecialBotPasswords',
                'PasswordReset' => 'SpecialPasswordReset',
                'DeletedContributions' => 'DeletedContributionsPage',
                'Preferences' => 'SpecialPreferences',
@@ -123,6 +124,7 @@ class SpecialPageFactory {
                'ListDuplicatedFiles' => 'ListDuplicatedFilesPage',
 
                // Data and tools
+               'ApiSandbox' => 'SpecialApiSandbox',
                'Statistics' => 'SpecialStatistics',
                'Allmessages' => 'SpecialAllMessages',
                'Version' => 'SpecialVersion',
@@ -176,7 +178,7 @@ class SpecialPageFactory {
                'RunJobs' => 'SpecialRunJobs',
                'Specialpages' => 'SpecialSpecialpages',
                'Userlogout' => 'SpecialUserlogout',
-       );
+       ];
 
        private static $list;
        private static $aliases;
@@ -257,7 +259,7 @@ class SpecialPageFactory {
 
                        // 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 ] );
 
                }
 
@@ -276,8 +278,8 @@ class SpecialPageFactory {
                        $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 ) {
@@ -337,7 +339,7 @@ class SpecialPageFactory {
                if ( isset( $aliases[$caseFoldedAlias] ) ) {
                        $name = $aliases[$caseFoldedAlias];
                } else {
-                       return array( null, null );
+                       return [ null, null ];
                }
 
                if ( !isset( $bits[1] ) ) { // bug 2087
@@ -346,7 +348,7 @@ class SpecialPageFactory {
                        $par = $bits[1];
                }
 
-               return array( $name, $par );
+               return [ $name, $par ];
        }
 
        /**
@@ -387,11 +389,11 @@ class SpecialPageFactory {
                                // @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 {
@@ -421,7 +423,7 @@ class SpecialPageFactory {
         * @return array ( string => Specialpage )
         */
        public static function getUsablePages( User $user = null ) {
-               $pages = array();
+               $pages = [];
                if ( $user === null ) {
                        global $wgUser;
                        $user = $wgUser;
@@ -447,7 +449,7 @@ class SpecialPageFactory {
         * @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() ) {
@@ -466,7 +468,7 @@ class SpecialPageFactory {
         * @return array ( string => Specialpage )
         */
        public static function getRestrictedPages( User $user = null ) {
-               $pages = array();
+               $pages = [];
                if ( $user === null ) {
                        global $wgUser;
                        $user = $wgUser;
@@ -580,31 +582,51 @@ class SpecialPageFactory {
         * @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;
        }