Handle automatic reassignment of edits from duplicate accounts to the main
[lhc/web/wiklou.git] / includes / SpecialPage.php
index 767b2c7..5469001 100644 (file)
  * DO NOT manipulate this array at run-time.
  *
  * @package MediaWiki
+ * @subpackage SpecialPage
  */
 
+
 /**
  *
  */
-global $wgSpecialPages;
+global $wgSpecialPages, $wgUser;
 
 /**
  * @access private
  */
 $wgSpecialPages = array(
-       'DoubleRedirects'       => new UnlistedSpecialPage ( 'DoubleRedirects' ),
-       'BrokenRedirects'       => new UnlistedSpecialPage ( 'BrokenRedirects' ),
-       'Disambiguations'       => new UnlistedSpecialPage ( 'Disambiguations' ),
-       
+       'DoubleRedirects'       => new SpecialPage ( 'DoubleRedirects' ),
+       'BrokenRedirects'       => new SpecialPage ( 'BrokenRedirects' ),
+       'Disambiguations'       => new SpecialPage ( 'Disambiguations' ),
+
        'Userlogin'         => new SpecialPage( 'Userlogin' ),
        'Userlogout'        => new UnlistedSpecialPage( 'Userlogout' ),
        'Preferences'       => new SpecialPage( 'Preferences' ),
        'Watchlist'         => new SpecialPage( 'Watchlist' ),
-       'Recentchanges'     => new SpecialPage( 'Recentchanges' ),
+       
+       'Recentchanges'     => new IncludableSpecialPage( 'Recentchanges' ),
        'Upload'            => new SpecialPage( 'Upload' ),
        'Imagelist'         => new SpecialPage( 'Imagelist' ),
        'Newimages'         => new SpecialPage( 'Newimages' ),
        'Listusers'         => new SpecialPage( 'Listusers' ),
-       'Listadmins'        => new SpecialPage( 'Listadmins' ),
        'Statistics'        => new SpecialPage( 'Statistics' ),
-       'Randompage'        => new SpecialPage( 'Randompage' ),
+       'Random'        => new SpecialPage( 'Randompage' ),
        'Lonelypages'       => new SpecialPage( 'Lonelypages' ),
        'Uncategorizedpages'=> new SpecialPage( 'Uncategorizedpages' ),
-       'Unusedimages'      => new SpecialPage( 'Unusedimages' )
-);
-
-global $wgDisableCounters;
-if( !$wgDisableCounters ) {
-       $wgSpecialPages['Popularpages'] = new SpecialPage( 'Popularpages' );
-}
-
-global $wgUseData ;
-if ( $wgUseData ) {
-       $wgSpecialPages['Data'] = new SpecialPage( 'Data' );
-}
-
-$wgSpecialPages = array_merge($wgSpecialPages, array (
+       'Uncategorizedcategories'=> new SpecialPage( 'Uncategorizedcategories' ),
+       'Unusedimages'      => new SpecialPage( 'Unusedimages' ),
        'Wantedpages'   => new SpecialPage( 'Wantedpages' ),
        'Shortpages'    => new SpecialPage( 'Shortpages' ),
        'Longpages'             => new SpecialPage( 'Longpages' ),
-       'Newpages'              => new SpecialPage( 'Newpages' ),
+       'Newpages'              => new IncludableSpecialPage( 'Newpages' ),
        'Ancientpages'  => new SpecialPage( 'Ancientpages' ),
        'Deadendpages'  => new SpecialPage( 'Deadendpages' ),
-       'Allpages'              => new SpecialPage( 'Allpages' ),
+       'Allpages'              => new IncludableSpecialPage( 'Allpages' ),
        'Ipblocklist'   => new SpecialPage( 'Ipblocklist' ),
-       'Maintenance'   => new SpecialPage( 'Maintenance' ),
        'Specialpages'  => new UnlistedSpecialPage( 'Specialpages' ),
        'Contributions' => new UnlistedSpecialPage( 'Contributions' ),
        'Emailuser'             => new UnlistedSpecialPage( 'Emailuser' ),
@@ -71,27 +60,39 @@ $wgSpecialPages = array_merge($wgSpecialPages, array (
        'Recentchangeslinked' => new UnlistedSpecialPage( 'Recentchangeslinked' ),
        'Movepage'              => new UnlistedSpecialPage( 'Movepage' ),
        'Blockme'       => new UnlistedSpecialPage( 'Blockme' ),
-       'Geo'           => new UnlistedSpecialPage( 'Geo' ),
-       'Validate'      => new UnlistedSpecialPage( 'Validate' ),
        'Booksources'   => new SpecialPage( 'Booksources' ),
        'Categories'    => new SpecialPage( 'Categories' ),
        'Export'                => new SpecialPage( 'Export' ),
        'Version'               => new SpecialPage( 'Version' ),
        'Allmessages'   => new SpecialPage( 'Allmessages' ),
-       'Search'                => new UnlistedSpecialPage( 'Search' ),
        'Log'           => new SpecialPage( 'Log' ),
-       'Blockip'               => new SpecialPage( 'Blockip', 'sysop' ),
-       'Asksql'                => new SpecialPage( 'Asksql', 'sysop' ),
-       'Undelete'              => new SpecialPage( 'Undelete', 'sysop' ),
-       'Makesysop'             => new SpecialPage( 'Makesysop', 'sysop' ),
-
-# Special:Import is half-written
-#      "Import"                => new SpecialPage( "Import", "sysop" ),
-       'Lockdb'                => new SpecialPage( 'Lockdb', 'developer' ),
-       'Unlockdb'              => new SpecialPage( 'Unlockdb', 'developer' ),
-       'Sitesettings'  => new SpecialPage( 'Sitesettings', 'sysop' ),
-       'Userlevels'    => new SpecialPage( 'Userlevels', 'sysop' ),
-));
+       'Blockip'               => new SpecialPage( 'Blockip', 'block' ),
+       'Undelete'              => new SpecialPage( 'Undelete', 'delete' ),
+       "Import"                => new SpecialPage( "Import", 'import' ),
+       'Lockdb'                => new SpecialPage( 'Lockdb', 'siteadmin' ),
+       'Unlockdb'              => new SpecialPage( 'Unlockdb', 'siteadmin' ),
+       'Userrights'    => new SpecialPage( 'Userrights', 'userrights' ),
+       'Groups'                => new SpecialPage( 'Groups' ),
+);
+
+global $wgUseValidation ;
+if ( $wgUseValidation )
+       $wgSpecialPages['Validate'] = new SpecialPage( 'Validate' );
+
+global $wgDisableCounters;
+if( !$wgDisableCounters ) {
+       $wgSpecialPages['Popularpages'] = new SpecialPage( 'Popularpages' );
+}
+
+global $wgDisableInternalSearch;
+if( !$wgDisableInternalSearch ) {
+       $wgSpecialPages['Search'] = new UnlistedSpecialPage( 'Search' );
+}
+
+global $wgEmailAuthentication;
+if( $wgEmailAuthentication ) {
+       $wgSpecialPages['Confirmemail'] = new UnlistedSpecialPage( 'Confirmemail' );
+}
 
 /**
  * Parent special page class, also static functions for handling the special
@@ -125,8 +126,19 @@ class SpecialPage
         * File which needs to be included before the function above can be called
         */
        var $mFile;
-       /**#@- */
+       /**
+        * Whether or not this special page is being included from an article
+        */
+       var $mIncluding;
+       /**
+        * Whether the special page can be included in an article
+        */
+       var $mIncludable;
+       
 
+       /**#@-*/
+
+       
        /**
         * Add a page to the list of valid special pages
         * $obj->execute() must send HTML to $wgOut then return
@@ -161,6 +173,29 @@ class SpecialPage
                        return NULL;
                }
        }
+       
+       /**
+        * @static
+        * @param string $name
+        * @return mixed Title object if the redirect exists, otherwise NULL
+        */
+       function &getRedirect( $name ) {
+               global $wgUser;
+               switch ( $name ) {
+                       case 'Mypage':
+                               return Title::makeTitle( NS_USER, $wgUser->getName() );
+                       case 'Mytalk':
+                               return Title::makeTitle( NS_USER_TALK, $wgUser->getName() );
+                       case 'Mycontributions':
+                               return Title::makeTitle( NS_SPECIAL, 'Contributions/' . $wgUser->getName() );
+                       case 'Listadmins':
+                               return Title::makeTitle( NS_SPECIAL, 'Listusers' );
+                       case 'Randompage':
+                               return Title::makeTitle( NS_SPECIAL, 'Random' );
+                       default:
+                               return NULL;
+               }
+       }
 
        /**
         * Return categorised listable special pages
@@ -188,14 +223,18 @@ class SpecialPage
         * The path     may contain parameters, e.g. Special:Name/Params
         * Extracts the special page name and call the execute method, passing the parameters
         *
-        * @param $title should be a title object
+        * 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}}
         */
-       function executePath( &$title ) {
+       function executePath( &$title, $including = false ) {
                global $wgSpecialPages, $wgOut, $wgTitle;
 
                $bits = split( "/", $title->getDBkey(), 2 );
                $name = $bits[0];
-               if( empty( $bits[1] ) ) {
+               if( !isset( $bits[1] ) ) { // bug 2087
                        $par = NULL;
                } else {
                        $par = $bits[1];
@@ -203,18 +242,60 @@ class SpecialPage
 
                $page =& SpecialPage::getPage( $name );
                if ( is_null( $page ) ) {
-                       $wgOut->setArticleRelated( false );
-                       $wgOut->setRobotpolicy( "noindex,follow" );
-                       $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
+                       if ( $including ) {
+                               return false;
+                       } else {
+                               $redir =& SpecialPage::getRedirect( $name );
+                               if ( isset( $redir ) ) {
+                                       if ( isset( $par ) ) 
+                                               $wgOut->redirect( $redir->getFullURL() . '/' . $par );
+                                       else
+                                               $wgOut->redirect( $redir->getFullURL() );
+                                       $retVal = $redir;
+                               } else {
+                                       $wgOut->setArticleRelated( false );
+                                       $wgOut->setRobotpolicy( "noindex,follow" );
+                                       $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
+                                       $retVal = false;
+                               }
+                       }
                } else {
+                       if ( $including && !$page->includable() ) {
+                               return false;
+                       }
                        if($par !== NULL) {
                                $wgTitle = Title::makeTitle( NS_SPECIAL, $name );
                        } else {
                                $wgTitle = $title;
                        }
+                       $page->including( $including );
 
                        $page->execute( $par );
+                       $retVal = true;
                }
+               return $retVal;
+       }
+
+       /**
+        * Just like executePath() except it returns the HTML instead of outputting it
+        * Returns false if there was no such special page, or a title object if it was
+        * a redirect.
+        * @static
+        */
+       function capturePath( &$title ) {
+               global $wgOut, $wgTitle;
+
+               $oldTitle = $wgTitle;
+               $oldOut = $wgOut;
+               $wgOut = new OutputPage;
+               
+               $ret = SpecialPage::executePath( $title, true );
+               if ( $ret === true ) {
+                       $ret = $wgOut->getHTML();
+               }
+               $wgTitle = $oldTitle;
+               $wgOut = $oldOut;
+               return $ret;
        }
 
        /**
@@ -233,10 +314,11 @@ class SpecialPage
         * @param string $function Function called by execute(). By default it is constructed from $name
         * @param string $file File which is included by execute(). It is also constructed from $name by default
         */
-       function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default' ) {
+       function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
                $this->mName = $name;
                $this->mRestriction = $restriction;
                $this->mListed = $listed;
+               $this->mIncludable = $includable;
                if ( $function == false ) {
                        $this->mFunction = 'wfSpecial'.$name;
                } else {
@@ -253,6 +335,9 @@ class SpecialPage
        function getName() { return $this->mName; }
        function getRestriction() { return $this->mRestriction; }
        function isListed() { return $this->mListed; }
+       function getFile() { return $this->mFile; }
+       function including( $x = NULL ) { return wfSetVar( $this->mIncluding, $x ); }
+       function includable( $x = NULL ) { return wfSetVar( $this->mIncludable, $x ); } 
 
        /**
         * Checks if the given user (identified by an object) can execute this
@@ -306,7 +391,7 @@ class SpecialPage
                                require_once( $this->mFile );
                        }
                        $func = $this->mFunction;
-                       $func( $par );
+                       $func( $par, $this );
                } else {
                        $this->displayRestrictionError();
                }
@@ -334,6 +419,7 @@ class SpecialPage
        function setListed( $listed ) {
                return wfSetVar( $this->mListed, $listed );
        }
+
 }
 
 /**
@@ -346,3 +432,14 @@ class UnlistedSpecialPage extends SpecialPage
                SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
        }
 }
+
+/**
+ * Shortcut to construct an includable special  page
+ */
+class IncludableSpecialPage extends SpecialPage
+{
+       function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
+               SpecialPage::SpecialPage( $name, $restriction, $listed, $function, $file, true );
+       }
+}
+?>