Follow-up r85278, r85240:
[lhc/web/wiklou.git] / includes / SpecialPage.php
index 64cd0d8..64a9697 100644 (file)
@@ -73,6 +73,12 @@ class SpecialPage {
         * Query parameteres added by redirects
         */
        var $mAddedRedirectParams = array();
+       /**
+        * Current request context
+        * @var RequestContext
+        */
+       protected $mContext;
+               
        /**
         * List of special pages, followed by parameters.
         * If the only parameter is a string, that is the page name.
@@ -120,32 +126,33 @@ class SpecialPage {
                'CreateAccount'             => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
 
                # Users and rights
-               'Blockip'                   => 'IPBlockForm',
-               'Ipblocklist'               => 'IPUnblockForm',
-               'Unblock'                   => array( 'SpecialRedirectToSpecial', 'Unblock', 'Ipblocklist', false, array( 'uselang', 'ip', 'id' ), array( 'action' => 'unblock' ) ),
+               'Block'                     => 'SpecialBlock',
+               'Unblock'                   => 'SpecialUnblock',
+               'BlockList'                 => 'SpecialBlockList',
                'Resetpass'                 => 'SpecialResetpass',
                'DeletedContributions'      => 'DeletedContributionsPage',
                'Preferences'               => 'SpecialPreferences',
                'Contributions'             => 'SpecialContributions',
                'Listgrouprights'           => 'SpecialListGroupRights',
-               'Listusers'                 => array( 'SpecialPage', 'Listusers' ),
+               'Listusers'                 => 'SpecialListusers',
                'Listadmins'                => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
                'Listbots'                  => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
                'Activeusers'               => 'SpecialActiveUsers',
                'Userrights'                => 'UserrightsPage',
                'DisableAccount'            => 'SpecialDisableAccount',
+               'EditWatchlist'             => 'SpecialEditWatchlist',
 
                # Recent changes and logs
-               'Newimages'                 => array( 'IncludableSpecialPage', 'Newimages' ),
+               'Newimages'                 => 'SpecialNewFiles',
                'Log'                       => 'SpecialLog',
-               'Watchlist'                 => array( 'SpecialPage', 'Watchlist' ),
+               'Watchlist'                 => 'SpecialWatchlist',
                'Newpages'                  => 'SpecialNewpages',
                'Recentchanges'             => 'SpecialRecentchanges',
                'Recentchangeslinked'       => 'SpecialRecentchangeslinked',
                'Tags'                      => 'SpecialTags',
 
                # Media reports and uploads
-               'Listfiles'                 => array( 'SpecialPage', 'Listfiles' ),
+               'Listfiles'                 => 'SpecialListFiles',
                'Filepath'                  => 'SpecialFilepath',
                'MIMEsearch'                => 'MIMEsearchPage',
                'FileDuplicateSearch'       => 'FileDuplicateSearchPage',
@@ -176,7 +183,7 @@ class SpecialPage {
                'ComparePages'              => 'SpecialComparePages',
                'Export'                    => 'SpecialExport',
                'Import'                    => 'SpecialImport',
-               'Undelete'                  => 'UndeleteForm',
+               'Undelete'                  => 'SpecialUndelete',
                'Whatlinkshere'             => 'SpecialWhatlinkshere',
                'MergeHistory'              => 'SpecialMergeHistory',
 
@@ -341,9 +348,10 @@ class SpecialPage {
                if( isset($specialPageGroupsCache[$page->mName]) ) {
                        return $specialPageGroupsCache[$page->mName];
                }
-               $group = wfMsg('specialpages-specialpagegroup-'.strtolower($page->mName));
-               if( $group == ''
-                || wfEmptyMsg('specialpages-specialpagegroup-'.strtolower($page->mName), $group ) ) {
+               $msg = wfMessage('specialpages-specialpagegroup-'.strtolower($page->mName));
+               if ( !$msg->isBlank() ) {
+                       $group = $msg->text();
+               } else {
                        $group = isset($wgSpecialPageGroups[$page->mName])
                                ? $wgSpecialPageGroups[$page->mName]
                                : '-';
@@ -407,7 +415,7 @@ class SpecialPage {
                                self::$mList[$name] = new $className;
                        } elseif ( is_array( $rec ) ) {
                                $className = array_shift( $rec );
-                               self::$mList[$name] = wfCreateObject( $className, $rec );
+                               self::$mList[$name] = MWFunction::newObj( $className, $rec );
                        }
                        return self::$mList[$name];
                } else {
@@ -505,16 +513,17 @@ class SpecialPage {
 
        /**
         * Execute a special page path.
-        * The path     may contain parameters, e.g. Special:Name/Params
+        * The path may contain parameters, e.g. Special:Name/Params
         * Extracts the special page name and call the execute method, passing the parameters
         *
         * Returns a title object if the page is redirected, false if there was no such special
         * page, and true if it was successful.
         *
-        * @param $title          a title object
-        * @param $including      output is being captured for use in {{special:whatever}}
+        * @param $title          Title object
+        * @param $context        RequestContext
+        * @param $including      Bool output is being captured for use in {{special:whatever}}
         */
-       static function executePath( &$title, $including = false ) {
+       static function executePath( &$title, RequestContext $context, $including = false ) {
                global $wgOut, $wgTitle, $wgRequest;
                wfProfileIn( __METHOD__ );
 
@@ -529,15 +538,16 @@ class SpecialPage {
                $page = SpecialPage::getPageByAlias( $name );
                # Nonexistent?
                if ( !$page ) {
-                       if ( !$including ) {
-                               $wgOut->setArticleRelated( false );
-                               $wgOut->setRobotPolicy( 'noindex,nofollow' );
-                               $wgOut->setStatusCode( 404 );
-                               $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
-                       }
+                       $wgOut->setArticleRelated( false );
+                       $wgOut->setRobotPolicy( 'noindex,nofollow' );
+                       $wgOut->setStatusCode( 404 );
+                       $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
                        wfProfileOut( __METHOD__ );
                        return false;
                }
+               
+               # Page exists, set the context
+               $page->setContext( $context );
 
                # Check for redirect
                if ( !$including ) {
@@ -598,14 +608,24 @@ class SpecialPage {
         * @return String: HTML fragment
         */
        static function capturePath( &$title ) {
-               global $wgOut, $wgTitle;
+               global $wgOut, $wgTitle, $wgUser;
+
+               // preload the skin - Sometimes the SpecialPage loads it at a bad point in time making a includable special page override the skin title
+               // This hack is ok for now. The plan is for
+               // - Skin to stop storing it's own title
+               // - includable special pages to stop using $wgTitle and $wgOut
+               // - and OutputPage to store it's own skin object instead of askin $wgUser
+               // Once just about any of those are implemented preloading will not be necessarily
+               $wgOut->getSkin();
 
                $oldTitle = $wgTitle;
                $oldOut = $wgOut;
-               $wgOut = new OutputPage;
-               $wgOut->setTitle( $title );
+               
+               $context = new RequestContext;
+               $context->setTitle( $title );
+               $wgOut = $context->getOutput();
 
-               $ret = SpecialPage::executePath( $title, true );
+               $ret = SpecialPage::executePath( $title, $context, true );
                if ( $ret === true ) {
                        $ret = $wgOut->getHTML();
                }
@@ -632,7 +652,7 @@ class SpecialPage {
                        $found = false;
                        foreach ( $aliases as $n => $values ) {
                                if ( strcasecmp( $name, $n ) === 0 ) {
-                                       wfWarn( "Found alias defined for $n when searching for" .
+                                       wfWarn( "Found alias defined for $n when searching for " .
                                                "special page aliases for $name. Case mismatch?" );
                                        $name = $values[0];
                                        $found = true;
@@ -640,7 +660,7 @@ class SpecialPage {
                                }
                        }
                        if ( !$found ) {
-                               wfWarn( "Did not find alias for special page '$name'. " . 
+                               wfWarn( "Did not find alias for special page '$name'. " .
                                        "Perhaps no aliases are defined for it?" );
                        }
                }
@@ -799,6 +819,18 @@ class SpecialPage {
                return $this->mLocalName;
        }
 
+       /**
+        * Is this page expensive (for some definition of expensive)?
+        * Expensive pages are disabled or cached in miser mode.  Originally used
+        * (and still overridden) by QueryPage and subclasses, moved here so that
+        * Special:SpecialPages can safely call it for all special pages.
+        *
+        * @return Boolean
+        */
+       public function isExpensive() {
+               return false;
+       }
+
        /**
         * Can be overridden by subclasses with more complicated permissions
         * schemes.
@@ -828,18 +860,17 @@ class SpecialPage {
         * Output an error message telling the user what access level they have to have
         */
        function displayRestrictionError() {
-               global $wgOut;
-               $wgOut->permissionRequired( $this->mRestriction );
+               $this->getOutput()->permissionRequired( $this->mRestriction );
        }
 
        /**
         * Sets headers - this should be called from the execute() method of all derived classes!
         */
        function setHeaders() {
-               global $wgOut;
-               $wgOut->setArticleRelated( false );
-               $wgOut->setRobotPolicy( "noindex,nofollow" );
-               $wgOut->setPageTitle( $this->getDescription() );
+               $out = $this->getOutput();
+               $out->setArticleRelated( false );
+               $out->setRobotPolicy( "noindex,nofollow" );
+               $out->setPageTitle( $this->getDescription() );
        }
 
        /**
@@ -849,11 +880,9 @@ class SpecialPage {
         * This may be overridden by subclasses.
         */
        function execute( $par ) {
-               global $wgUser;
-
                $this->setHeaders();
 
-               if ( $this->userCanExecute( $wgUser ) ) {
+               if ( $this->userCanExecute( $this->getUser() ) ) {
                        $func = $this->mFunction;
                        // only load file if the function does not exist
                        if(!is_callable($func) and $this->mFile) {
@@ -875,16 +904,15 @@ class SpecialPage {
         * @param $summaryMessageKey String: message key of the summary
         */
        function outputHeader( $summaryMessageKey = '' ) {
-               global $wgOut, $wgContLang;
+               global $wgContLang;
 
                if( $summaryMessageKey == '' ) {
                        $msg = $wgContLang->lc( $this->name() ) . '-summary';
                } else {
                        $msg = $summaryMessageKey;
                }
-               $out = wfMsgNoTrans( $msg );
-               if ( ! wfEmptyMsg( $msg, $out ) and  $out !== '' and ! $this->including() ) {
-                       $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
+               if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
+                       $this->getOutput()->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
                }
 
        }
@@ -951,6 +979,91 @@ class SpecialPage {
                        ? $params
                        : false;
        }
+       
+       /**
+        * Sets the context this SpecialPage is executed in
+        * 
+        * @param $context RequestContext
+        * @since 1.18
+        */
+       protected function setContext( $context ) {
+               $this->mContext = $context;
+       }
+
+       /**
+        * Gets the context this SpecialPage is executed in
+        * 
+        * @return RequestContext
+        * @since 1.18
+        */
+       public function getContext() {
+               if ( $this->mContext instanceof RequestContext ) {
+                       return $this->mContext;
+               } else {
+                       wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
+                       return RequestContext::getMain();
+               }
+       }
+
+       /**
+        * Get the WebRequest being used for this instance
+        *
+        * @return WebRequest
+        * @since 1.18
+        */
+       public function getRequest() {
+               return $this->getContext()->getRequest();
+       }
+
+       /**
+        * Get the OutputPage being used for this instance
+        *
+        * @return OutputPage
+        * @since 1.18
+        */
+       public function getOutput() {
+               return $this->getContext()->getOutput();
+       }
+
+       /**
+        * Shortcut to get the skin being used for this instance
+        *
+        * @return User
+        * @since 1.18
+        */
+       public function getUser() {
+               return $this->getContext()->getUser();
+       }
+
+       /**
+        * Shortcut to get the skin being used for this instance
+        *
+        * @return Skin
+        * @since 1.18
+        */
+       public function getSkin() {
+               return $this->getContext()->getSkin();
+       }
+
+       /**
+        * Return the full title, including $par
+        *
+        * @return Title
+        * @since 1.18
+        */
+       public function getFullTitle() {
+               return $this->getContext()->getTitle();
+       }
+
+       /**
+        * Wrapper around wfMessage that sets the current context. Currently this
+        * is only the title.
+        * 
+        * @see wfMessage
+        */
+       public function msg( /* $args */ ) {
+               return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->getFullTitle() );
+       }
 }
 
 /**
@@ -1082,7 +1195,7 @@ class SpecialMyuploads extends UnlistedSpecialPage {
 }
 
 /**
- * Redirect to Special:Listfiles?user=$wgUser
+ * Redirect from Special:PermanentLink/### to index.php?oldid=###
  */
 class SpecialPermanentLink extends UnlistedSpecialPage {
        function __construct() {