a round of static statements
[lhc/web/wiklou.git] / includes / User.php
index 294bac7..81c45ec 100644 (file)
@@ -14,30 +14,42 @@ require_once( 'WatchedItem.php' );
 define( 'USER_TOKEN_LENGTH', 32 );
 
 # Serialized record version
-define( 'MW_USER_VERSION', 2 );
+define( 'MW_USER_VERSION', 3 );
 
 /**
  *
  * @package MediaWiki
  */
 class User {
-       /**#@+
-        * @access private
-        */
-       var $mId, $mName, $mPassword, $mEmail, $mNewtalk;
-       var $mEmailAuthenticated;
-       var $mRights, $mOptions;
-       var $mDataLoaded, $mNewpassword;
-       var $mSkin;
-       var $mBlockedby, $mBlockreason;
-       var $mTouched;
-       var $mToken;
-       var $mRealName;
-       var $mHash;
-       var $mGroups;
-       var $mVersion; // serialized version
-
-       /** Construct using User:loadDefaults() */
+       /*
+        * When adding a new private variable, dont forget to add it to __sleep()
+        */
+       /**@{{
+        * @private
+        */
+       private $mBlockedby;    //!<
+       private $mBlockreason;  //!<
+       private $mDataLoaded;   //!<
+       private $mEmail;                //!<
+       private $mEmailAuthenticated; //!<
+       private $mGroups;               //!<
+       private $mHash;                 //!<
+       private $mId;                   //!<
+       private $mName;                 //!<
+       private $mNewpassword;  //!<
+       private $mNewtalk;              //!<
+       private $mOptions;              //!<
+       private $mPassword;             //!<
+       private $mRealName;             //!<
+       private $mRegistration; //!<
+       private $mRights;               //!<
+       private $mSkin;                 //!<
+       private $mToken;                //!<
+       private $mTouched;              //!<
+       private $mVersion;              //!< serialized version
+       /**@}} */
+
+       /** Constructor using User:loadDefaults() */
        function User() {
                $this->loadDefaults();
                $this->mVersion = MW_USER_VERSION;
@@ -101,13 +113,31 @@ class User {
 
        /**
         * Serialze sleep function, for better cache efficiency and avoidance of
-        * silly "incomplete type" errors when skins are cached
+        * silly "incomplete type" errors when skins are cached. The array should
+        * contain names of private variables (see at top of User.php).
         */
        function __sleep() {
-               return array( 'mId', 'mName', 'mPassword', 'mEmail', 'mNewtalk',
-                       'mEmailAuthenticated', 'mRights', 'mOptions', 'mDataLoaded',
-                       'mNewpassword', 'mBlockedby', 'mBlockreason', 'mTouched',
-                       'mToken', 'mRealName', 'mHash', 'mGroups' );
+               return array(
+'mBlockedby',
+'mBlockreason',
+'mDataLoaded',
+'mEmail',
+'mEmailAuthenticated',
+'mGroups',
+'mHash',
+'mId',
+'mName',
+'mNewpassword',
+'mNewtalk',
+'mOptions',
+'mPassword',
+'mRealName',
+'mRegistration',
+'mRights',
+'mToken',
+'mTouched',
+'mVersion',
+);
        }
 
        /**
@@ -201,7 +231,7 @@ class User {
                || strlen( $name ) > $wgMaxNameChars
                || $name != $wgContLang->ucfirst( $name ) )
                        return false;
-               
+
                // Ensure that the name can't be misresolved as a different title,
                // such as with extra namespace keys at the start.
                $parsed = Title::newFromText( $name );
@@ -209,8 +239,22 @@ class User {
                        || $parsed->getNamespace()
                        || strcmp( $name, $parsed->getPrefixedText() ) )
                        return false;
-               else
-                       return true;
+               
+               // Check an additional blacklist of troublemaker characters.
+               // Should these be merged into the title char list?
+               $unicodeBlacklist = '/[' .
+                       '\x{0080}-\x{009f}' . # iso-8859-1 control chars
+                       '\x{00a0}' .          # non-breaking space
+                       '\x{2000}-\x{200f}' . # various whitespace
+                       '\x{2028}-\x{202f}' . # breaks and control chars
+                       '\x{3000}' .          # ideographic space
+                       '\x{e000}-\x{f8ff}' . # private use
+                       ']/u';
+               if( preg_match( $unicodeBlacklist, $name ) ) {
+                       return false;
+               }
+               
+               return true;
        }
 
        /**
@@ -292,7 +336,7 @@ class User {
                $fname = 'User::loadDefaults' . $n;
                wfProfileIn( $fname );
 
-               global $wgContLang, $wgDBname;
+               global $wgCookiePrefix;
                global $wgNamespacesToBeSearchedDefault;
 
                $this->mId = 0;
@@ -314,13 +358,15 @@ class User {
                $this->setToken(); # Random
                $this->mHash = false;
 
-               if ( isset( $_COOKIE[$wgDBname.'LoggedOut'] ) ) {
-                       $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgDBname.'LoggedOut'] );
+               if ( isset( $_COOKIE[$wgCookiePrefix.'LoggedOut'] ) ) {
+                       $this->mTouched = wfTimestamp( TS_MW, $_COOKIE[$wgCookiePrefix.'LoggedOut'] );
                }
                else {
                        $this->mTouched = '0'; # Allow any pages to be cached
                }
 
+               $this->mRegistration = wfTimestamp( TS_MW );
+
                wfProfileOut( $fname );
        }
 
@@ -330,7 +376,7 @@ class User {
         *
         * @return array
         * @static
-        * @access private
+        * @private
         */
        function getDefaultOptions() {
                /**
@@ -355,7 +401,7 @@ class User {
         * @param string $opt
         * @return string
         * @static
-        * @access public
+        * @public
         */
        function getDefaultOption( $opt ) {
                $defOpts = User::getDefaultOptions();
@@ -368,13 +414,13 @@ class User {
 
        /**
         * Get blocking information
-        * @access private
+        * @private
         * @param bool $bFromSlave Specify whether to check slave or master. To improve performance,
         *  non-critical checks are done against slaves. Check when actually saving should be done against
         *  master.
         */
        function getBlockedStatus( $bFromSlave = true ) {
-               global $wgProxyList, $wgEnableSorbs, $wgProxyWhitelist;
+               global $wgEnableSorbs, $wgProxyWhitelist;
 
                if ( -1 != $this->mBlockedby ) {
                        wfDebug( "User::getBlockedStatus: already loaded.\n" );
@@ -403,10 +449,11 @@ class User {
                }
 
                # Proxy blocking
-               if ( !$this->isSysop() && !in_array( $ip, $wgProxyWhitelist ) ) {
+               # FIXME ? proxyunbannable is to deprecate the old isSysop()
+               if ( !$this->isAllowed('proxyunbannable') && !in_array( $ip, $wgProxyWhitelist ) ) {
 
                        # Local list
-                       if ( array_key_exists( $ip, $wgProxyList ) ) {
+                       if ( wfIsLocallyBlockedProxy( $ip ) ) {
                                $this->mBlockedby = wfMsg( 'proxyblocker' );
                                $this->mBlockreason = wfMsg( 'proxyblockreason' );
                        }
@@ -475,7 +522,7 @@ class User {
         * last-hit counters will be shared across wikis.
         *
         * @return bool true if a rate limiter was tripped
-        * @access public
+        * @public
         */
        function pingLimiter( $action='edit' ) {
                global $wgRateLimits;
@@ -594,8 +641,9 @@ class User {
 
        /**
         * Initialise php session
+        * @static
         */
-       function SetupSession() {
+       static function SetupSession() {
                global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain;
                if( $wgSessionsInMemcached ) {
                        require_once( 'MemcachedSessions.php' );
@@ -613,8 +661,8 @@ class User {
         * Create a new user object using data from session
         * @static
         */
-       function loadFromSession() {
-               global $wgMemc, $wgDBname;
+       static function loadFromSession() {
+               global $wgMemc, $wgDBname, $wgCookiePrefix;
 
                if ( isset( $_SESSION['wsUserID'] ) ) {
                        if ( 0 != $_SESSION['wsUserID'] ) {
@@ -622,16 +670,16 @@ class User {
                        } else {
                                return new User();
                        }
-               } else if ( isset( $_COOKIE["{$wgDBname}UserID"] ) ) {
-                       $sId = intval( $_COOKIE["{$wgDBname}UserID"] );
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserID"] ) ) {
+                       $sId = intval( $_COOKIE["{$wgCookiePrefix}UserID"] );
                        $_SESSION['wsUserID'] = $sId;
                } else {
                        return new User();
                }
                if ( isset( $_SESSION['wsUserName'] ) ) {
                        $sName = $_SESSION['wsUserName'];
-               } else if ( isset( $_COOKIE["{$wgDBname}UserName"] ) ) {
-                       $sName = $_COOKIE["{$wgDBname}UserName"];
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}UserName"] ) ) {
+                       $sName = $_COOKIE["{$wgCookiePrefix}UserName"];
                        $_SESSION['wsUserName'] = $sName;
                } else {
                        return new User();
@@ -654,8 +702,8 @@ class User {
 
                if ( isset( $_SESSION['wsToken'] ) ) {
                        $passwordCorrect = $_SESSION['wsToken'] == $user->mToken;
-               } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
-                       $passwordCorrect = $user->mToken == $_COOKIE["{$wgDBname}Token"];
+               } else if ( isset( $_COOKIE["{$wgCookiePrefix}Token"] ) ) {
+                       $passwordCorrect = $user->mToken == $_COOKIE["{$wgCookiePrefix}Token"];
                } else {
                        return new User(); # Can't log in from session
                }
@@ -676,7 +724,6 @@ class User {
         * Load a user from the database
         */
        function loadFromDatabase() {
-               global $wgCommandLineMode;
                $fname = "User::loadFromDatabase";
 
                # Counter-intuitive, breaks various things, use User::setLoaded() if you want to suppress
@@ -700,7 +747,7 @@ class User {
                $dbr =& wfGetDB( DB_SLAVE );
                $s = $dbr->selectRow( 'user', array( 'user_name','user_password','user_newpassword','user_email',
                  'user_email_authenticated',
-                 'user_real_name','user_options','user_touched', 'user_token' ),
+                 'user_real_name','user_options','user_touched', 'user_token', 'user_registration' ),
                  array( 'user_id' => $this->mId ), $fname );
 
                if ( $s !== false ) {
@@ -713,6 +760,7 @@ class User {
                        $this->decodeOptions( $s->user_options );
                        $this->mTouched = wfTimestamp(TS_MW,$s->user_touched);
                        $this->mToken = $s->user_token;
+                       $this->mRegistration = wfTimestampOrNull( TS_MW, $s->user_registration );
 
                        $res = $dbr->select( 'user_groups',
                                array( 'ug_group' ),
@@ -722,7 +770,15 @@ class User {
                        while( $row = $dbr->fetchObject( $res ) ) {
                                $this->mGroups[] = $row->ug_group;
                        }
-                       $effectiveGroups = array_merge( array( '*', 'user' ), $this->mGroups );
+                       $implicitGroups = array( '*', 'user' );
+
+                       global $wgAutoConfirmAge;
+                       $accountAge = time() - wfTimestampOrNull( TS_UNIX, $this->mRegistration );
+                       if( $accountAge >= $wgAutoConfirmAge ) {
+                               $implicitGroups[] = 'autoconfirmed';
+                       }
+
+                       $effectiveGroups = array_merge( $implicitGroups, $this->mGroups );
                        $this->mRights = $this->getGroupPermissions( $effectiveGroups );
                }
 
@@ -752,20 +808,18 @@ class User {
        /**
         * Return the title dbkey form of the name, for eg user pages.
         * @return string
-        * @access public
+        * @public
         */
        function getTitleKey() {
                return str_replace( ' ', '_', $this->getName() );
        }
 
        function getNewtalk() {
-               global $wgUseEnotif;
-               $fname = 'User::getNewtalk';
                $this->loadFromDatabase();
 
                # Load the newtalk status if it is unloaded (mNewtalk=-1)
-               if( $this->mNewtalk == -1 ) {
-                       $this->mNewtalk = 0; # reset talk page status
+               if( $this->mNewtalk === -1 ) {
+                       $this->mNewtalk = false; # reset talk page status
 
                        # Check memcached separately for anons, who have no
                        # entire User object stored in there.
@@ -774,49 +828,140 @@ class User {
                                $key = "$wgDBname:newtalk:ip:" . $this->getName();
                                $newtalk = $wgMemc->get( $key );
                                if( is_integer( $newtalk ) ) {
-                                       $this->mNewtalk = $newtalk ? 1 : 0;
-                                       return (bool)$this->mNewtalk;
+                                       $this->mNewtalk = (bool)$newtalk;
+                               } else {
+                                       $this->mNewtalk = $this->checkNewtalk( 'user_ip', $this->getName() );
+                                       $wgMemc->set( $key, $this->mNewtalk, time() ); // + 1800 );
                                }
+                       } else {
+                               $this->mNewtalk = $this->checkNewtalk( 'user_id', $this->mId );
                        }
+               }
 
-                       $dbr =& wfGetDB( DB_SLAVE );
-                       if ( $wgUseEnotif ) {
-                               $res = $dbr->select( 'watchlist',
-                                       array( 'wl_user' ),
-                                       array( 'wl_title'     => $this->getTitleKey(),
-                                                  'wl_namespace' => NS_USER_TALK,
-                                                  'wl_user'      => $this->mId,
-                                                  'wl_notificationtimestamp ' . $dbr->notNullTimestamp() ),
-                                       'User::getNewtalk' );
-                               if( $dbr->numRows($res) > 0 ) {
-                                       $this->mNewtalk = 1;
-                               }
-                               $dbr->freeResult( $res );
-                       } elseif ( $this->mId ) {
-                               $res = $dbr->select( 'user_newtalk', 1, array( 'user_id' => $this->mId ), $fname );
+               return (bool)$this->mNewtalk;
+       }
 
-                               if ( $dbr->numRows($res)>0 ) {
-                                       $this->mNewtalk= 1;
-                               }
-                               $dbr->freeResult( $res );
-                       } else {
-                               $res = $dbr->select( 'user_newtalk', 1, array( 'user_ip' => $this->getName() ), $fname );
-                               $this->mNewtalk = $dbr->numRows( $res ) > 0 ? 1 : 0;
-                               $dbr->freeResult( $res );
-                       }
+       /**
+        * Return the talk page(s) this user has new messages on.
+        */
+       function getNewMessageLinks() {
+       global  $wgDBname;
+               $talks = array();
+               if (!wfRunHooks('UserRetrieveNewTalks', array(&$this, &$talks)))
+                       return $talks;
 
-                       if( !$this->mId ) {
-                               $wgMemc->set( $key, $this->mNewtalk, time() ); // + 1800 );
-                       }
+               if (!$this->getNewtalk())
+                       return array();
+               $up = $this->getUserPage();
+               $utp = $up->getTalkPage();
+               return array(array("wiki" => $wgDBname, "link" => $utp->getLocalURL()));
+       }
+
+               
+       /**
+        * Perform a user_newtalk check on current slaves; if the memcached data
+        * is funky we don't want newtalk state to get stuck on save, as that's
+        * damn annoying.
+        *
+        * @param string $field
+        * @param mixed $id
+        * @return bool
+        * @private
+        */
+       function checkNewtalk( $field, $id ) {
+               $fname = 'User::checkNewtalk';
+               $dbr =& wfGetDB( DB_SLAVE );
+               $ok = $dbr->selectField( 'user_newtalk', $field,
+                       array( $field => $id ), $fname );
+               return $ok !== false;
+       }
+
+       /**
+        * Add or update the
+        * @param string $field
+        * @param mixed $id
+        * @private
+        */
+       function updateNewtalk( $field, $id ) {
+               $fname = 'User::updateNewtalk';
+               if( $this->checkNewtalk( $field, $id ) ) {
+                       wfDebug( "$fname already set ($field, $id), ignoring\n" );
+                       return false;
                }
+               $dbw =& wfGetDB( DB_MASTER );
+               $dbw->insert( 'user_newtalk',
+                       array( $field => $id ),
+                       $fname,
+                       'IGNORE' );
+               wfDebug( "$fname: set on ($field, $id)\n" );
+               return true;
+       }
 
-               return ( 0 != $this->mNewtalk );
+       /**
+        * Clear the new messages flag for the given user
+        * @param string $field
+        * @param mixed $id
+        * @private
+        */
+       function deleteNewtalk( $field, $id ) {
+               $fname = 'User::deleteNewtalk';
+               if( !$this->checkNewtalk( $field, $id ) ) {
+                       wfDebug( "$fname: already gone ($field, $id), ignoring\n" );
+                       return false;
+               }
+               $dbw =& wfGetDB( DB_MASTER );
+               $dbw->delete( 'user_newtalk',
+                       array( $field => $id ),
+                       $fname );
+               wfDebug( "$fname: killed on ($field, $id)\n" );
+               return true;
        }
 
+       /**
+        * Update the 'You have new messages!' status.
+        * @param bool $val
+        */
        function setNewtalk( $val ) {
+               if( wfReadOnly() ) {
+                       return;
+               }
+
                $this->loadFromDatabase();
                $this->mNewtalk = $val;
-               $this->invalidateCache();
+
+               $fname = 'User::setNewtalk';
+
+               if( $this->isAnon() ) {
+                       $field = 'user_ip';
+                       $id = $this->getName();
+               } else {
+                       $field = 'user_id';
+                       $id = $this->getId();
+               }
+
+               if( $val ) {
+                       $changed = $this->updateNewtalk( $field, $id );
+               } else {
+                       $changed = $this->deleteNewtalk( $field, $id );
+               }
+
+               if( $changed ) {
+                       if( $this->isAnon() ) {
+                               // Anons have a separate memcached space, since
+                               // user records aren't kept for them.
+                               global $wgDBname, $wgMemc;
+                               $key = "$wgDBname:newtalk:ip:$val";
+                               $wgMemc->set( $key, $val ? 1 : 0 );
+                       } else {
+                               if( $val ) {
+                                       // Make sure the user page is watched, so a notification
+                                       // will be sent out if enabled.
+                                       $this->addWatch( $this->getTalkPage() );
+                               }
+                       }
+                       $this->invalidateCache();
+                       $this->saveSettings();
+               }
        }
 
        function invalidateCache() {
@@ -903,6 +1048,10 @@ class User {
                $this->mRealName = $str;
        }
 
+       /**
+        * @param string $oname The option to check
+        * @return string
+        */
        function getOption( $oname ) {
                $this->loadFromDatabase();
                if ( array_key_exists( $oname, $this->mOptions ) ) {
@@ -912,6 +1061,14 @@ class User {
                }
        }
 
+       /**
+        * @param string $oname The option to check
+        * @return bool False if the option is not selected, true if it is
+        */
+       function getBoolOption( $oname ) {
+               return (bool)$this->getOption( $oname );
+       }
+
        function setOption( $oname, $val ) {
                $this->loadFromDatabase();
                if ( $oname == 'skin' ) {
@@ -952,7 +1109,7 @@ class User {
        }
 
        /**
-        * Remove the user from the given group.
+        * Add the user to the given group.
         * This takes immediate effect.
         * @string $group
         */
@@ -1016,21 +1173,30 @@ class User {
        }
 
        /**
-        * Check if a user is sysop
+        * Deprecated in 1.6, die in 1.7, to be removed in 1.8
         * @deprecated
         */
        function isSysop() {
-               return $this->isAllowed( 'protect' );
+               wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isSysop() method\n" );
+               #return $this->isAllowed( 'protect' );
        }
 
-       /** @deprecated */
+       /**
+        * Deprecated in 1.6, die in 1.7, to be removed in 1.8
+        * @deprecated
+        */
        function isDeveloper() {
-               return $this->isAllowed( 'siteadmin' );
+               wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isDeveloper() method\n" );
+               #return $this->isAllowed( 'siteadmin' );
        }
 
-       /** @deprecated */
+       /**
+        * Deprecated in 1.6, die in 1.7, to be removed in 1.8
+        * @deprecated
+        */
        function isBureaucrat() {
-               return $this->isAllowed( 'makesysop' );
+               wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isBureaucrat() method\n" );
+               #return $this->isAllowed( 'makesysop' );
        }
 
        /**
@@ -1048,6 +1214,10 @@ class User {
         * @return boolean True: action is allowed, False: action should not be allowed
         */
        function isAllowed($action='') {
+               if ( $action === '' )
+                       // In the spirit of DWIM
+                       return true;
+
                $this->loadFromDatabase();
                return in_array( $action , $this->mRights );
        }
@@ -1062,51 +1232,11 @@ class User {
                        $fname = 'User::getSkin';
                        wfProfileIn( $fname );
 
-                       # get all skin names available
-                       $skinNames = Skin::getSkinNames();
-
                        # get the user skin
                        $userSkin = $this->getOption( 'skin' );
-                       $userSkin = $wgRequest->getText('useskin', $userSkin);
-                       if ( $userSkin == '' ) { $userSkin = 'standard'; }
-
-                       if ( !isset( $skinNames[$userSkin] ) ) {
-                               # in case the user skin could not be found find a replacement
-                               $fallback = array(
-                                       0 => 'Standard',
-                                       1 => 'Nostalgia',
-                                       2 => 'CologneBlue');
-                               # if phptal is enabled we should have monobook skin that
-                               # superseed the good old SkinStandard.
-                               if ( isset( $skinNames['monobook'] ) ) {
-                                       $fallback[0] = 'MonoBook';
-                               }
+                       $userSkin = $wgRequest->getVal('useskin', $userSkin);
 
-                               if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
-                                       $sn = $fallback[$userSkin];
-                               } else {
-                                       $sn = 'Standard';
-                               }
-                       } else {
-                               # The user skin is available
-                               $sn = $skinNames[$userSkin];
-                       }
-
-                       # Grab the skin class and initialise it. Each skin checks for PHPTal
-                       # and will not load if it's not enabled.
-                       require_once( $IP.'/skins/'.$sn.'.php' );
-
-                       # Check if we got if not failback to default skin
-                       $className = 'Skin'.$sn;
-                       if( !class_exists( $className ) ) {
-                               # DO NOT die if the class isn't found. This breaks maintenance
-                               # scripts and can cause a user account to be unrecoverable
-                               # except by SQL manipulation if a previously valid skin name
-                               # is no longer valid.
-                               $className = 'SkinStandard';
-                               require_once( $IP.'/skins/Standard.php' );
-                       }
-                       $this->mSkin =& new $className;
+                       $this->mSkin =& Skin::newFromKey( $userSkin );
                        wfProfileOut( $fname );
                }
                return $this->mSkin;
@@ -1151,12 +1281,20 @@ class User {
        function clearNotification( &$title ) {
                global $wgUser, $wgUseEnotif;
 
-               if ( !$wgUseEnotif ) {
+
+               if ($title->getNamespace() == NS_USER_TALK &&
+                       $title->getText() == $this->getName() ) {
+                       if (!wfRunHooks('UserClearNewTalkNotification', array(&$this)))
+                               return;
+                       $this->setNewtalk( false );
+               }
+
+               if( !$wgUseEnotif ) {
                        return;
                }
 
-               $userid = $this->getID();
-               if ($userid==0) {
+               if( $this->isAnon() ) {
+                       // Nothing else to do...
                        return;
                }
 
@@ -1198,11 +1336,12 @@ class User {
         * the next change of any watched page.
         *
         * @param int $currentUser user ID number
-        * @access public
+        * @public
         */
        function clearAllNotifications( $currentUser ) {
                global $wgUseEnotif;
                if ( !$wgUseEnotif ) {
+                       $this->setNewtalk( false );
                        return;
                }
                if( $currentUser != 0 )  {
@@ -1222,7 +1361,7 @@ class User {
        }
 
        /**
-        * @access private
+        * @private
         * @return string Encoding options
         */
        function encodeOptions() {
@@ -1235,7 +1374,7 @@ class User {
        }
 
        /**
-        * @access private
+        * @private
         */
        function decodeOptions( $str ) {
                $a = explode( "\n", $str );
@@ -1247,22 +1386,22 @@ class User {
        }
 
        function setCookies() {
-               global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
+               global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookiePrefix;
                if ( 0 == $this->mId ) return;
                $this->loadFromDatabase();
                $exp = time() + $wgCookieExpiration;
 
                $_SESSION['wsUserID'] = $this->mId;
-               setcookie( $wgDBname.'UserID', $this->mId, $exp, $wgCookiePath, $wgCookieDomain );
+               setcookie( $wgCookiePrefix.'UserID', $this->mId, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
 
                $_SESSION['wsUserName'] = $this->getName();
-               setcookie( $wgDBname.'UserName', $this->getName(), $exp, $wgCookiePath, $wgCookieDomain );
+               setcookie( $wgCookiePrefix.'UserName', $this->getName(), $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
 
                $_SESSION['wsToken'] = $this->mToken;
                if ( 1 == $this->getOption( 'rememberpassword' ) ) {
-                       setcookie( $wgDBname.'Token', $this->mToken, $exp, $wgCookiePath, $wgCookieDomain );
+                       setcookie( $wgCookiePrefix.'Token', $this->mToken, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
                } else {
-                       setcookie( $wgDBname.'Token', '', time() - 3600 );
+                       setcookie( $wgCookiePrefix.'Token', '', time() - 3600 );
                }
        }
 
@@ -1271,28 +1410,27 @@ class User {
         * It will clean the session cookie
         */
        function logout() {
-               global $wgCookiePath, $wgCookieDomain, $wgDBname;
+               global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookiePrefix;
                $this->loadDefaults();
                $this->setLoaded( true );
 
                $_SESSION['wsUserID'] = 0;
 
-               setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
-               setcookie( $wgDBname.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
+               setcookie( $wgCookiePrefix.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
+               setcookie( $wgCookiePrefix.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
 
                # Remember when user logged out, to prevent seeing cached pages
-               setcookie( $wgDBname.'LoggedOut', wfTimestampNow(), time() + 86400, $wgCookiePath, $wgCookieDomain );
+               setcookie( $wgCookiePrefix.'LoggedOut', wfTimestampNow(), time() + 86400, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
        }
 
        /**
         * Save object settings into database
         */
        function saveSettings() {
-               global $wgMemc, $wgDBname, $wgUseEnotif;
+               global $wgMemc, $wgDBname;
                $fname = 'User::saveSettings';
 
                if ( wfReadOnly() ) { return; }
-               $this->saveNewtalk();
                if ( 0 == $this->mId ) { return; }
 
                $dbw =& wfGetDB( DB_MASTER );
@@ -1314,79 +1452,6 @@ class User {
                $wgMemc->delete( "$wgDBname:user:id:$this->mId" );
        }
 
-       /**
-        * Save value of new talk flag.
-        */
-       function saveNewtalk() {
-               global $wgDBname, $wgMemc, $wgUseEnotif;
-
-               $fname = 'User::saveNewtalk';
-
-               $changed = false;
-
-               if ( wfReadOnly() ) { return ; }
-               $dbr =& wfGetDB( DB_SLAVE );
-               $dbw =& wfGetDB( DB_MASTER );
-               $changed = false;
-               if ( $wgUseEnotif ) {
-                       if ( ! $this->getNewtalk() ) {
-                               # Delete the watchlist entry for user_talk page X watched by user X
-                               $dbw->delete( 'watchlist',
-                                       array( 'wl_user'      => $this->mId,
-                                                  'wl_title'     => $this->getTitleKey(),
-                                                  'wl_namespace' => NS_USER_TALK ),
-                                       $fname );
-                               if ( $dbw->affectedRows() ) {
-                                       $changed = true;
-                               }
-                               if( !$this->mId ) {
-                                       # Anon users have a separate memcache space for newtalk
-                                       # since they don't store their own info. Trim...
-                                       $wgMemc->delete( "$wgDBname:newtalk:ip:" . $this->getName() );
-                               }
-                       }
-               } else {
-                       if ($this->getID() != 0) {
-                               $field = 'user_id';
-                               $value = $this->getID();
-                               $key = false;
-                       } else {
-                               $field = 'user_ip';
-                               $value = $this->getName();
-                               $key = "$wgDBname:newtalk:ip:$value";
-                       }
-
-                       $dbr =& wfGetDB( DB_SLAVE );
-                       $dbw =& wfGetDB( DB_MASTER );
-
-                       $res = $dbr->selectField('user_newtalk', $field,
-                                                                        array($field => $value), $fname);
-
-                       $changed = true;
-                       if ($res !== false && $this->mNewtalk == 0) {
-                               $dbw->delete('user_newtalk', array($field => $value), $fname);
-                               if ( $key ) {
-                                       $wgMemc->set( $key, 0 );
-                               }
-                       } else if ($res === false && $this->mNewtalk == 1) {
-                               $dbw->insert('user_newtalk', array($field => $value), $fname);
-                               if ( $key ) {
-                                       $wgMemc->set( $key, 1 );
-                               }
-                       } else {
-                               $changed = false;
-                       }
-               }
-
-               # Update user_touched, so that newtalk notifications in the client cache are invalidated
-               if ( $changed && $this->getID() ) {
-                       $dbw->update('user',
-                               /*SET*/ array( 'user_touched' => $this->mTouched ),
-                               /*WHERE*/ array( 'user_id' => $this->getID() ),
-                               $fname);
-                       $wgMemc->set( "$wgDBname:user:id:{$this->mId}", $this, 86400 );
-               }
-       }
 
        /**
         * Checks if a user with the given name exists, returns the ID
@@ -1423,7 +1488,8 @@ class User {
                                'user_email_authenticated' => $dbw->timestampOrNull( $this->mEmailAuthenticated ),
                                'user_real_name' => $this->mRealName,
                                'user_options' => $this->encodeOptions(),
-                               'user_token' => $this->mToken
+                               'user_token' => $this->mToken,
+                               'user_registration' => $dbw->timestamp( $this->mRegistration ),
                        ), $fname
                );
                $this->mId = $dbw->insertId();
@@ -1480,6 +1546,19 @@ class User {
 
        }
 
+       /**
+        * Generate a string which will be different for any combination of
+        * user options which would produce different parser output.
+        * This will be used as part of the hash key for the parser cache,
+        * so users will the same options can share the same cached data
+        * safely.
+        *
+        * Extensions which require it should install 'PageRenderingHash' hook,
+        * which will give them a chance to modify this key based on their own
+        * settings.
+        *
+        * @return string
+        */
        function getPageRenderingHash() {
                global $wgContLang;
                if( $this->mHash ){
@@ -1499,8 +1578,12 @@ class User {
                $extra = $wgContLang->getExtraHashOptions();
                $confstr .= $extra;
 
+               // Give a chance for extensions to modify the hash, if they have
+               // extra options or other effects on the parser cache.
+               wfRunHooks( 'PageRenderingHash', array( &$confstr ) );
+
                $this->mHash = $confstr;
-               return $confstr ;
+               return $confstr;
        }
 
        function isAllowedToCreateAccount() {
@@ -1519,7 +1602,7 @@ class User {
         * Get this user's personal page title.
         *
         * @return Title
-        * @access public
+        * @public
         */
        function getUserPage() {
                return Title::makeTitle( NS_USER, $this->getName() );
@@ -1529,7 +1612,7 @@ class User {
         * Get this user's talk page title.
         *
         * @return Title
-        * @access public
+        * @public
         */
        function getTalkPage() {
                $title = $this->getUserPage();
@@ -1540,18 +1623,23 @@ class User {
         * @static
         */
        function getMaxID() {
-               $dbr =& wfGetDB( DB_SLAVE );
-               return $dbr->selectField( 'user', 'max(user_id)', false, 'User::getMaxID' );
+               static $res; // cache
+
+               if ( isset( $res ) )
+                       return $res;
+               else {
+                       $dbr =& wfGetDB( DB_SLAVE );
+                       return $res = $dbr->selectField( 'user', 'max(user_id)', false, 'User::getMaxID' );
+               }
        }
 
        /**
         * Determine whether the user is a newbie. Newbies are either
-        * anonymous IPs, or the 1% most recently created accounts.
-        * Bots and sysops are excluded.
+        * anonymous IPs, or the most recently created accounts.
         * @return bool True if it is a newbie.
         */
        function isNewbie() {
-               return $this->isAnon() || $this->mId > User::getMaxID() * 0.99 && !$this->isAllowed( 'delete' ) && !$this->isBot();
+               return !$this->isAllowed( 'autoconfirmed' );
        }
 
        /**
@@ -1603,7 +1691,7 @@ class User {
         * @param mixed $salt - Optional function-specific data for hash.
         *                      Use a string or an array of strings.
         * @return string
-        * @access public
+        * @public
         */
        function editToken( $salt = '' ) {
                if( !isset( $_SESSION['wsEditToken'] ) ) {
@@ -1637,27 +1725,15 @@ class User {
         * @param string $val - the input value to compare
         * @param string $salt - Optional function-specific data for hash
         * @return bool
-        * @access public
+        * @public
         */
        function matchEditToken( $val, $salt = '' ) {
                global $wgMemc;
-
-/*
-               if ( !isset( $_SESSION['wsEditToken'] ) ) {
-                       $logfile = '/home/wikipedia/logs/session_debug/session.log';
-                       $mckey = memsess_key( session_id() );
-                       $uname = @posix_uname();
-                       $msg = "wsEditToken not set!\n" .
-                       'apache server=' . $uname['nodename'] . "\n" .
-                       'session_id = ' . session_id() . "\n" .
-                       '$_SESSION=' . var_export( $_SESSION, true ) . "\n" .
-                       '$_COOKIE=' . var_export( $_COOKIE, true ) . "\n" .
-                       "mc get($mckey) = " . var_export( $wgMemc->get( $mckey ), true ) . "\n\n\n";
-
-                       @error_log( $msg, 3, $logfile );
+               $sessionToken = $this->editToken( $salt );
+               if ( $val != $sessionToken ) {
+                       wfDebug( "User::matchEditToken: broken session data\n" );
                }
-*/
-               return ( $val == $this->editToken( $salt ) );
+               return $val == $sessionToken;
        }
 
        /**
@@ -1693,7 +1769,9 @@ class User {
                }
 
                require_once( 'UserMailer.php' );
-               $error = userMailer( $this->getEmail(), $from, $subject, $body );
+               $to = new MailAddress( $this );
+               $sender = new MailAddress( $from );
+               $error = userMailer( $to, $sender, $subject, $body );
 
                if( $error == '' ) {
                        return true;
@@ -1707,7 +1785,7 @@ class User {
         * A hash (unsalted since it's used as a key) is stored.
         * @param &$expiration mixed output: accepts the expiration time
         * @return string
-        * @access private
+        * @private
         */
        function confirmationToken( &$expiration ) {
                $fname = 'User::confirmationToken';
@@ -1734,7 +1812,7 @@ class User {
         * the URL the user can use to confirm.
         * @param &$expiration mixed output: accepts the expiration time
         * @return string
-        * @access private
+        * @private
         */
        function confirmationTokenUrl( &$expiration ) {
                $token = $this->confirmationToken( $expiration );
@@ -1783,13 +1861,18 @@ class User {
        function isEmailConfirmed() {
                global $wgEmailAuthentication;
                $this->loadFromDatabase();
-               if( $this->isAnon() )
-                       return false;
-               if( !$this->isValidEmailAddr( $this->mEmail ) )
-                       return false;
-               if( $wgEmailAuthentication && !$this->getEmailAuthenticationTimestamp() )
-                       return false;
-               return true;
+               $confirmed = true;
+               if( wfRunHooks( 'EmailConfirmed', array( &$this, &$confirmed ) ) ) {
+                       if( $this->isAnon() )
+                               return false;
+                       if( !$this->isValidEmailAddr( $this->mEmail ) )
+                               return false;
+                       if( $wgEmailAuthentication && !$this->getEmailAuthenticationTimestamp() )
+                               return false;
+                       return true;
+               } else {
+                       return $confirmed;
+               }
        }
 
        /**
@@ -1811,11 +1894,11 @@ class User {
 
        /**
         * @param string $group key name
-        * @return string localized descriptive name, if provided
+        * @return string localized descriptive name for group, if provided
         * @static
         */
        function getGroupName( $group ) {
-               $key = "group-$group-name";
+               $key = "group-$group";
                $name = wfMsg( $key );
                if( $name == '' || $name == "&lt;$key&gt;" ) {
                        return $group;
@@ -1824,6 +1907,22 @@ class User {
                }
        }
 
+       /**
+        * @param string $group key name
+        * @return string localized descriptive name for member of a group, if provided
+        * @static
+        */
+       function getGroupMember( $group ) {
+               $key = "group-$group-member";
+               $name = wfMsg( $key );
+               if( $name == '' || $name == "&lt;$key&gt;" ) {
+                       return $group;
+               } else {
+                       return $name;
+               }
+       }
+
+
        /**
         * Return the set of defined explicit groups.
         * The * and 'user' groups are not included.
@@ -1834,9 +1933,26 @@ class User {
                global $wgGroupPermissions;
                return array_diff(
                        array_keys( $wgGroupPermissions ),
-                       array( '*', 'user' ) );
+                       array( '*', 'user', 'autoconfirmed' ) );
        }
-
+       
+       /**
+        * Get the title of a page describing a particular group
+        *
+        * @param $group Name of the group
+        * @return mixed
+        */
+       function getGroupPage( $group ) {
+               $page = wfMsgForContent( 'grouppage-' . $group );
+               if( !wfEmptyMsg( 'grouppage-' . $group, $page ) ) {
+                       $title = Title::newFromText( $page );
+                       if( is_object( $title ) )
+                               return $title;
+               }
+               return false;
+       }
+       
+       
 }
 
 ?>