Start better utalizing OutputPage as the focal point for things related to the output...
[lhc/web/wiklou.git] / includes / SpecialPage.php
index 39b8ba2..bdccf2a 100644 (file)
@@ -73,6 +73,22 @@ class SpecialPage {
         * Query parameteres added by redirects
         */
        var $mAddedRedirectParams = array();
+       /**
+        * Current request
+        * @var WebRequest 
+        */
+       protected $mRequest;
+       /**
+        * Current output page
+        * @var OutputPage
+        */
+       protected $mOutput;
+       /**
+        * Full title including $par
+        * @var Title
+        */
+       protected $mFullTitle;
+               
        /**
         * List of special pages, followed by parameters.
         * If the only parameter is a string, that is the page name.
@@ -120,32 +136,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 +193,7 @@ class SpecialPage {
                'ComparePages'              => 'SpecialComparePages',
                'Export'                    => 'SpecialExport',
                'Import'                    => 'SpecialImport',
-               'Undelete'                  => 'UndeleteForm',
+               'Undelete'                  => 'SpecialUndelete',
                'Whatlinkshere'             => 'SpecialWhatlinkshere',
                'MergeHistory'              => 'SpecialMergeHistory',
 
@@ -341,9 +358,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]
                                : '-';
@@ -505,7 +523,7 @@ 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
@@ -538,6 +556,9 @@ class SpecialPage {
                        wfProfileOut( __METHOD__ );
                        return false;
                }
+               
+               # Page exists, set the context
+               $page->setContext( $wgRequest, $wgOut );
 
                # Check for redirect
                if ( !$including ) {
@@ -598,12 +619,13 @@ class SpecialPage {
         * @return String: HTML fragment
         */
        static function capturePath( &$title ) {
-               global $wgOut, $wgTitle;
+               global $wgOut, $wgTitle, $wgUser;
 
                $oldTitle = $wgTitle;
                $oldOut = $wgOut;
                $wgOut = new OutputPage;
                $wgOut->setTitle( $title );
+               $wgOut->setUser( $wgUser ); # for now, there may be a better idea in the future
 
                $ret = SpecialPage::executePath( $title, true );
                if ( $ret === true ) {
@@ -632,7 +654,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 +662,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 +821,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.
@@ -882,8 +916,7 @@ class SpecialPage {
                } else {
                        $msg = $summaryMessageKey;
                }
-               $out = wfMsgNoTrans( $msg );
-               if ( ! wfEmptyMsg( $msg, $out ) and  $out !== '' and ! $this->including() ) {
+               if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
                        $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
                }
 
@@ -951,6 +984,27 @@ class SpecialPage {
                        ? $params
                        : false;
        }
+       
+       /**
+        * Sets the context this SpecialPage is executed in
+        * 
+        * @param $request WebRequest
+        * @param $output OutputPage
+        */
+       protected function setContext( $request, $output ) {
+               $this->mRequest = $request;
+               $this->mOutput = $output;
+               $this->mFullTitle = $output->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->mFullTitle );
+       }
 }
 
 /**