$out is needed here
[lhc/web/wiklou.git] / includes / SpecialPage.php
index 8643875..246f80a 100644 (file)
  * SpecialPage::$mList. To remove a core static special page at runtime, use
  * a SpecialPage_initList hook.
  *
- * @package MediaWiki
- * @subpackage SpecialPage
- */
-
-/**
- * @access private
+ * @addtogroup SpecialPage
  */
 
 /**
  * Parent special page class, also static functions for handling the special
- * page list
- * @package MediaWiki
+ * page list.
+ * @addtogroup SpecialPage
  */
 class SpecialPage
 {
@@ -73,7 +68,15 @@ class SpecialPage
         * Query parameters that can be passed through redirects
         */
        var $mAllowedRedirectParams = array();
-
+       /**
+        * List of special pages, followed by parameters.
+        * If the only parameter is a string, that is the page name.
+        * Otherwise, it is an array. The format is one of:
+        ** array( 'SpecialPage', name, right )
+        ** array( 'IncludableSpecialPage', name, right, listed? )
+        ** array( 'UnlistedSpecialPage', name, right )
+        ** array( 'SpecialRedirectToSpecial', name, page to redirect to, special page param, ... )
+        */
        static public $mList = array(
                'DoubleRedirects'           => array( 'SpecialPage', 'DoubleRedirects' ),
                'BrokenRedirects'           => array( 'SpecialPage', 'BrokenRedirects' ),
@@ -81,6 +84,7 @@ class SpecialPage
 
                'Userlogin'                 => array( 'SpecialPage', 'Userlogin' ),
                'Userlogout'                => array( 'UnlistedSpecialPage', 'Userlogout' ),
+               'CreateAccount'             => array( 'SpecialRedirectToSpecial', 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ),
                'Preferences'               => array( 'SpecialPage', 'Preferences' ),
                'Watchlist'                 => array( 'SpecialPage', 'Watchlist' ),
 
@@ -89,31 +93,37 @@ class SpecialPage
                'Imagelist'                 => array( 'SpecialPage', 'Imagelist' ),
                'Newimages'                 => array( 'IncludableSpecialPage', 'Newimages' ),
                'Listusers'                 => array( 'SpecialPage', 'Listusers' ),
+               'Listgrouprights'           => 'SpecialListGroupRights',
                'Statistics'                => array( 'SpecialPage', 'Statistics' ),
-               'Randompage'                => array( 'SpecialPage', 'Randompage' ),
+               'Randompage'                => 'Randompage',
                'Lonelypages'               => array( 'SpecialPage', 'Lonelypages' ),
                'Uncategorizedpages'        => array( 'SpecialPage', 'Uncategorizedpages' ),
                'Uncategorizedcategories'   => array( 'SpecialPage', 'Uncategorizedcategories' ),
                'Uncategorizedimages'       => array( 'SpecialPage', 'Uncategorizedimages' ),
+               'Uncategorizedtemplates'    => array( 'SpecialPage', 'Uncategorizedtemplates' ),
                'Unusedcategories'          => array( 'SpecialPage', 'Unusedcategories' ),
                'Unusedimages'              => array( 'SpecialPage', 'Unusedimages' ),
                'Wantedpages'               => array( 'IncludableSpecialPage', 'Wantedpages' ),
                'Wantedcategories'          => array( 'SpecialPage', 'Wantedcategories' ),
                'Mostlinked'                => array( 'SpecialPage', 'Mostlinked' ),
                'Mostlinkedcategories'      => array( 'SpecialPage', 'Mostlinkedcategories' ),
+               'Mostlinkedtemplates'       => array( 'SpecialPage', 'Mostlinkedtemplates' ),
                'Mostcategories'            => array( 'SpecialPage', 'Mostcategories' ),
                'Mostimages'                => array( 'SpecialPage', 'Mostimages' ),
                'Mostrevisions'             => array( 'SpecialPage', 'Mostrevisions' ),
+               'Fewestrevisions'           => array( 'SpecialPage', 'Fewestrevisions' ),
                'Shortpages'                => array( 'SpecialPage', 'Shortpages' ),
                'Longpages'                 => array( 'SpecialPage', 'Longpages' ),
                'Newpages'                  => array( 'IncludableSpecialPage', 'Newpages' ),
                'Ancientpages'              => array( 'SpecialPage', 'Ancientpages' ),
                'Deadendpages'              => array( 'SpecialPage', 'Deadendpages' ),
+               'Protectedpages'            => array( 'SpecialPage', 'Protectedpages' ),
+               'Protectedtitles'           => array( 'SpecialPage', 'Protectedtitles' ),
                'Allpages'                  => array( 'IncludableSpecialPage', 'Allpages' ),
                'Prefixindex'               => array( 'IncludableSpecialPage', 'Prefixindex' ) ,
                'Ipblocklist'               => array( 'SpecialPage', 'Ipblocklist' ),
                'Specialpages'              => array( 'UnlistedSpecialPage', 'Specialpages' ),
-               'Contributions'             => array( 'UnlistedSpecialPage', 'Contributions' ),
+               'Contributions'             => array( 'SpecialPage', 'Contributions' ),
                'Emailuser'                 => array( 'UnlistedSpecialPage', 'Emailuser' ),
                'Whatlinkshere'             => array( 'UnlistedSpecialPage', 'Whatlinkshere' ),
                'Recentchangeslinked'       => array( 'UnlistedSpecialPage', 'Recentchangeslinked' ),
@@ -128,25 +138,121 @@ class SpecialPage
                'Log'                       => array( 'SpecialPage', 'Log' ),
                'Blockip'                   => array( 'SpecialPage', 'Blockip', 'block' ),
                'Undelete'                  => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
-               'Import'                    => array( 'SpecialPage', "Import", 'import' ),
+               'Import'                    => array( 'SpecialPage', 'Import', 'import' ),
                'Lockdb'                    => array( 'SpecialPage', 'Lockdb', 'siteadmin' ),
                'Unlockdb'                  => array( 'SpecialPage', 'Unlockdb', 'siteadmin' ),
-               'Userrights'                => array( 'SpecialPage', 'Userrights', 'userrights' ),
+               'Userrights'                => 'UserrightsPage',
                'MIMEsearch'                => array( 'SpecialPage', 'MIMEsearch' ),
+               'FileDuplicateSearch'       => array( 'SpecialPage', 'FileDuplicateSearch' ),
                'Unwatchedpages'            => array( 'SpecialPage', 'Unwatchedpages', 'unwatchedpages' ),
                'Listredirects'             => array( 'SpecialPage', 'Listredirects' ),
-               'Revisiondelete'            => array( 'SpecialPage', 'Revisiondelete', 'deleterevision' ),
+               'Revisiondelete'            => array( 'UnlistedSpecialPage', 'Revisiondelete', 'deleterevision' ),
                'Unusedtemplates'           => array( 'SpecialPage', 'Unusedtemplates' ),
-               'Randomredirect'            => array( 'SpecialPage', 'Randomredirect' ),
+               'Randomredirect'            => 'SpecialRandomredirect',
+               'Withoutinterwiki'          => array( 'SpecialPage', 'Withoutinterwiki' ),
+               'Filepath'                  => array( 'SpecialPage', 'Filepath' ),
 
                'Mypage'                    => array( 'SpecialMypage' ),
                'Mytalk'                    => array( 'SpecialMytalk' ),
                'Mycontributions'           => array( 'SpecialMycontributions' ),
                'Listadmins'                => array( 'SpecialRedirectToSpecial', 'Listadmins', 'Listusers', 'sysop' ),
-       );
+               'MergeHistory'              => array( 'SpecialPage', 'MergeHistory', 'mergehistory' ),
+               'Listbots'                  => array( 'SpecialRedirectToSpecial', 'Listbots', 'Listusers', 'bot' ),
+               );
 
        static public $mAliases;
        static public $mListInitialised = false;
+       /**
+        * List of special pages, followed by what subtitle they should go under
+        * at Special:SpecialPages
+        */
+       static public $mGroupsList = array(
+               'DoubleRedirects'           => 'maintenance',
+               'BrokenRedirects'           => 'maintenance',
+               'Lonelypages'               => 'maintenance',
+               'Uncategorizedpages'        => 'maintenance',
+               'Uncategorizedcategories'   => 'maintenance',
+               'Uncategorizedimages'       => 'maintenance',
+               'Uncategorizedtemplates'    => 'maintenance',
+               'Unusedcategories'          => 'maintenance',
+               'Unusedimages'              => 'maintenance',
+               'Protectedpages'            => 'maintenance',
+               'Protectedtitles'           => 'maintenance',
+               'Unusedtemplates'           => 'maintenance',
+               'Withoutinterwiki'          => 'maintenance',
+               'Longpages'                 => 'maintenance',
+
+               'Userlogin'                 => 'login',
+               'Userlogout'                => 'login',
+               'CreateAccount'             => 'login',
+
+               'Recentchanges'             => 'changes',
+               'Recentchangeslinked'       => 'changes',
+               'Watchlist'                 => 'changes',
+               'Newimages'                 => 'changes',
+               'Newpages'                  => 'changes',
+               'Log'                       => 'changes',
+               
+               'Upload'                    => 'media',
+               'Imagelist'                 => 'media',
+               'MIMEsearch'                => 'media',
+               'FileDuplicateSearch'       => 'media',
+               'Filepath'                  => 'media',
+               
+               'Listusers'                 => 'users',
+               'Listgrouprights'           => 'users',
+               'Ipblocklist'               => 'users',
+               'Contributions'             => 'users',
+               'Emailuser'                 => 'users',
+               'Listadmins'                => 'users',
+               'Listbots'                  => 'users',
+               
+               'Wantedpages'               => 'needy',
+               'Wantedcategories'          => 'needy',
+               'Shortpages'                => 'needy',
+               'Ancientpages'              => 'needy',
+               'Deadendpages'              => 'needy',
+               
+               'Mostlinked'                => 'highuse',
+               'Mostlinkedcategories'      => 'highuse',
+               'Mostlinkedtemplates'       => 'highuse',
+               'Mostcategories'            => 'highuse',
+               'Mostimages'                => 'highuse',
+               'Mostrevisions'             => 'highuse',
+               
+               'Userrights'                => 'permissions',
+               'Blockip'                   => 'permissions',
+               
+               'Statistics'                => 'other',
+               'Fewestrevisions'           => 'other',
+               'Randompage'                => 'other',
+               'Disambiguations'           => 'other',
+               'Specialpages'              => 'other',
+               'Blockme'                   => 'other',
+               'Movepage'                  => 'other',
+               'MergeHistory'              => 'other',
+               'Lockdb'                    => 'other',
+               'Unlockdb'                  => 'other',
+               'Version'                   => 'other',
+               'Whatlinkshere'             => 'other',
+               'Booksources'               => 'other',
+               'Revisiondelete'            => 'other',
+               'Export'                    => 'other',
+               'Categories'                => 'other',
+               'Undelete'                  => 'other',
+               'Import'                    => 'other',
+               'Unwatchedpages'            => 'other',
+               'Randomredirect'            => 'other',
+               'Allpages'                  => 'other',
+               'Allmessages'               => 'other',
+               'Prefixindex'               => 'other',
+               'Listredirects'             => 'other',
+               'Preferences'               => 'other',
+               'Resetpass'                 => 'other',
+               'Mypage'                    => 'other',
+               'Mytalk'                    => 'other',
+               'Mycontributions'           => 'other',
+               );
 
        /**#@-*/
 
@@ -175,7 +281,8 @@ class SpecialPage
                }
 
                if( $wgEmailAuthentication ) {
-                       self::$mList['Confirmemail'] = array( 'UnlistedSpecialPage', 'Confirmemail' );
+                       self::$mList['Confirmemail'] = 'EmailConfirmation';
+                       self::$mList['Invalidateemail'] = 'EmailInvalidation';
                }
 
                # Add extension special pages
@@ -257,6 +364,37 @@ class SpecialPage
                }
                self::$mList[$page->mName] = $page;
        }
+       
+       /**
+        * Add a page to a certain display group for Special:SpecialPages
+        *
+        * @param mixed $page Must either be an array specifying a class name and 
+        *                    constructor parameters, or an object.
+        * @param string $group
+        * @static
+        */
+       static function setGroup( &$page, $group ) {
+               if ( !self::$mListInitialised ) {
+                       self::initList();
+               }
+               self::$mGroupsList[$page->mName] = $group;
+       }
+       
+       /**
+        * Add a page to a certain display group for Special:SpecialPages
+        *
+        * @param mixed $page Must either be an array specifying a class name and 
+        *                    constructor parameters, or an object.
+        * @static
+        */
+       static function getGroup( &$page ) {
+               if ( !self::$mListInitialised ) {
+                       self::initList();
+               }
+               $group = isset(self::$mGroupsList[$page->mName]) ? 
+                       self::$mGroupsList[$page->mName] : 'other';
+               return $group;
+       }
 
        /**
         * Remove a special page from the list
@@ -272,6 +410,30 @@ class SpecialPage
                unset( self::$mList[$name] );
        }
 
+       /**
+        * Check if a given name exist as a special page or as a special page alias
+        * @param $name string: name of a special page
+        * @return boolean: true if a special page exists with this name
+        */
+       static function exists( $name ) {
+               global $wgContLang;
+               if ( !self::$mListInitialised ) {
+                       self::initList();
+               }
+               if( !self::$mAliases ) {
+                       self::initAliasList();
+               }
+
+               # Remove special pages inline parameters:
+               $bits = explode( '/', $name );
+               $name = $wgContLang->caseFold($bits[0]);
+
+               return
+                       array_key_exists( $name, self::$mList )
+                       or array_key_exists( $name, self::$mAliases )
+               ;
+       }
+
        /**
         * Find the object with a given name and return it (or NULL)
         * @static
@@ -321,7 +483,7 @@ class SpecialPage
 
                foreach ( self::$mList as $name => $rec ) {
                        $page = self::getPage( $name );
-                       if ( $page->isListed() && $page->getRestriction() == '' ) {
+                       if ( $page->isListed() && !$page->isRestricted() ) {
                                $pages[$name] = $page;
                        }
                }
@@ -342,11 +504,12 @@ class SpecialPage
 
                foreach ( self::$mList as $name => $rec ) {
                        $page = self::getPage( $name );
-                       if ( $page->isListed() ) {
-                               $restriction = $page->getRestriction();
-                               if ( $restriction != '' && $wgUser->isAllowed( $restriction ) ) {
-                                       $pages[$name] = $page;
-                               }
+                       if (
+                               $page->isListed()
+                               and $page->isRestricted()
+                               and $page->userCanExecute( $wgUser )
+                       ) {
+                               $pages[$name] = $page;
                        }
                }
                return $pages;
@@ -376,7 +539,6 @@ class SpecialPage
                        $par = $bits[1];
                }
                $page = SpecialPage::getPageByAlias( $name );
-
                # Nonexistent?
                if ( !$page ) {
                        if ( !$including ) {
@@ -458,6 +620,11 @@ class SpecialPage
 
        /**
         * Get the local name for a specified canonical name
+        *
+        * @param $name
+        * @param mixed $subpage Boolean false, or string
+        *
+        * @return string
         */
        static function getLocalNameFor( $name, $subpage = false ) {
                global $wgContLang;
@@ -535,7 +702,7 @@ class SpecialPage
                        $this->mFunction = $function;
                }
                if ( $file === 'default' ) {
-                       $this->mFile = "Special{$name}.php";
+                       $this->mFile = dirname(__FILE__) . "/Special{$name}.php";
                } else {
                        $this->mFile = $file;
                }
@@ -574,11 +741,26 @@ class SpecialPage
                return $this->mLocalName;
        }
 
+       /**
+        * Can be overridden by subclasses with more complicated permissions
+        * schemes.
+        *
+        * @return bool Should the page be displayed with the restricted-access
+        *   pages?
+        */
+       public function isRestricted() {
+               return $this->mRestriction != '';
+       }
+
        /**
         * Checks if the given user (identified by an object) can execute this
-        * special page (as defined by $mRestriction)
+        * special page (as defined by $mRestriction).  Can be overridden by sub-
+        * classes with more complicated permissions schemes.
+        *
+        * @param User $user The user to check
+        * @return bool Does the user have permission to view the page?
         */
-       function userCanExecute( &$user ) {
+       public function userCanExecute( $user ) {
                return $user->isAllowed( $this->mRestriction );
        }
 
@@ -614,7 +796,7 @@ class SpecialPage
                if ( $this->userCanExecute( $wgUser ) ) {
                        $func = $this->mFunction;
                        // only load file if the function does not exist
-                       if(!function_exists($func) and $this->mFile) {
+                       if(!is_callable($func) and $this->mFile) {
                                require_once( $this->mFile );
                        }
                        # FIXME: these hooks are broken for extensions and anything else that subclasses SpecialPage. 
@@ -622,7 +804,7 @@ class SpecialPage
                                $this->outputHeader();
                        if ( ! wfRunHooks( 'SpecialPageExecuteBeforePage', array( &$this, &$par, &$func ) ) )
                                return;
-                       $func( $par, $this );
+                       call_user_func( $func, $par, $this );
                        if ( ! wfRunHooks( 'SpecialPageExecuteAfterPage', array( &$this, &$par, &$func ) ) )
                                return;
                } else {
@@ -634,9 +816,10 @@ class SpecialPage
                global $wgOut, $wgContLang;
 
                $msg = $wgContLang->lc( $this->name() ) . '-summary';
-               $out = wfMsg( $msg );
-               if ( ! wfEmptyMsg( $msg, $out ) and  $out !== '' and ! $this->including() )
+               $out = wfMsgNoTrans( $msg );
+               if ( ! wfEmptyMsg( $msg, $out ) and  $out !== '' and ! $this->including() ) {
                        $wgOut->addWikiText( $out );
+               }
 
        }
 
@@ -691,7 +874,7 @@ class SpecialPage
 
 /**
  * Shortcut to construct a special page which is unlisted by default
- * @package MediaWiki
+ * @addtogroup SpecialPage
  */
 class UnlistedSpecialPage extends SpecialPage
 {
@@ -702,7 +885,7 @@ class UnlistedSpecialPage extends SpecialPage
 
 /**
  * Shortcut to construct an includable special  page
- * @package MediaWiki
+ * @addtogroup SpecialPage
  */
 class IncludableSpecialPage extends SpecialPage
 {
@@ -711,6 +894,10 @@ class IncludableSpecialPage extends SpecialPage
        }
 }
 
+/**
+ * Shortcut to construct a special page alias.
+ * @addtogroup SpecialPage
+ */
 class SpecialRedirectToSpecial extends UnlistedSpecialPage {
        var $redirName, $redirSubpage;
 
@@ -730,10 +917,21 @@ class SpecialRedirectToSpecial extends UnlistedSpecialPage {
        }
 }
 
+/** SpecialMypage, SpecialMytalk and SpecialMycontributions special pages
+ * are used to get user independant links pointing to the user page, talk
+ * page and list of contributions.
+ * This can let us cache a single copy of any generated content for all
+ * users.
+ */
+
+/**
+ * Shortcut to construct a special page pointing to current user user's page.
+ * @addtogroup SpecialPage
+ */
 class SpecialMypage extends UnlistedSpecialPage {
        function __construct() {
                parent::__construct( 'Mypage' );
-               $this->mAllowedRedirectParams = array( 'action' );
+               $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro', 'section' );
        }
 
        function getRedirect( $subpage ) {
@@ -746,10 +944,14 @@ class SpecialMypage extends UnlistedSpecialPage {
        }
 }
 
+/**
+ * Shortcut to construct a special page pointing to current user talk page.
+ * @addtogroup SpecialPage
+ */
 class SpecialMytalk extends UnlistedSpecialPage {
        function __construct() {
                parent::__construct( 'Mytalk' );
-               $this->mAllowedRedirectParams = array( 'action' );
+               $this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro', 'section' );
        }
 
        function getRedirect( $subpage ) {
@@ -762,6 +964,10 @@ class SpecialMytalk extends UnlistedSpecialPage {
        }
 }
 
+/**
+ * Shortcut to construct a special page pointing to current user contributions.
+ * @addtogroup SpecialPage
+ */
 class SpecialMycontributions extends UnlistedSpecialPage {
        function __construct() {
                parent::__construct(  'Mycontributions' );
@@ -772,5 +978,3 @@ class SpecialMycontributions extends UnlistedSpecialPage {
                return SpecialPage::getTitleFor( 'Contributions', $wgUser->getName() );
        }
 }
-
-?>