removed useless line
[lhc/web/wiklou.git] / includes / User.php
index 60e06fb..187309e 100644 (file)
@@ -14,7 +14,7 @@ require_once( 'WatchedItem.php' );
 define( 'USER_TOKEN_LENGTH', 32 );
 
 # Serialized record version
-define( 'MW_USER_VERSION', 2 );
+define( 'MW_USER_VERSION', 3 );
 
 /**
  *
@@ -36,6 +36,7 @@ class User {
        var $mHash;
        var $mGroups;
        var $mVersion; // serialized version
+       var $mRegistration;
 
        /** Construct using User:loadDefaults() */
        function User() {
@@ -107,7 +108,7 @@ class User {
                return array( 'mId', 'mName', 'mPassword', 'mEmail', 'mNewtalk',
                        'mEmailAuthenticated', 'mRights', 'mOptions', 'mDataLoaded',
                        'mNewpassword', 'mBlockedby', 'mBlockreason', 'mTouched',
-                       'mToken', 'mRealName', 'mHash', 'mGroups' );
+                       'mToken', 'mRealName', 'mHash', 'mGroups', 'mRegistration' );
        }
 
        /**
@@ -321,6 +322,8 @@ class User {
                        $this->mTouched = '0'; # Allow any pages to be cached
                }
 
+               $this->mRegistration = wfTimestamp( TS_MW );
+               
                wfProfileOut( $fname );
        }
 
@@ -651,7 +654,7 @@ class User {
                } else {
                        wfDebug( "User::loadFromSession() got from cache!\n" );
                }
-
+               
                if ( isset( $_SESSION['wsToken'] ) ) {
                        $passwordCorrect = $_SESSION['wsToken'] == $user->mToken;
                } else if ( isset( $_COOKIE["{$wgDBname}Token"] ) ) {
@@ -699,7 +702,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 ) {
@@ -712,6 +715,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' ),
@@ -721,7 +725,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 );
                }
 
@@ -824,6 +836,7 @@ class User {
        }
        
        /**
+        * Clear the new messages flag for the given user
         * @param string $field
         * @param mixed $id
         * @access private
@@ -1022,7 +1035,7 @@ class User {
        }
 
        /**
-        * Remove the user from the given group.
+        * Add the user to the given group.
         * This takes immediate effect.
         * @string $group
         */
@@ -1118,6 +1131,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 );
        }
@@ -1132,9 +1149,6 @@ 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->getVal('useskin', $userSkin);
@@ -1286,20 +1300,20 @@ class User {
        }
 
        function setCookies() {
-               global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgDBname;
+               global $wgCookieExpiration, $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgDBname;
                if ( 0 == $this->mId ) return;
                $this->loadFromDatabase();
                $exp = time() + $wgCookieExpiration;
 
                $_SESSION['wsUserID'] = $this->mId;
-               setcookie( $wgDBname.'UserID', $this->mId, $exp, $wgCookiePath, $wgCookieDomain );
+               setcookie( $wgDBname.'UserID', $this->mId, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
 
                $_SESSION['wsUserName'] = $this->getName();
-               setcookie( $wgDBname.'UserName', $this->getName(), $exp, $wgCookiePath, $wgCookieDomain );
+               setcookie( $wgDBname.'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( $wgDBname.'Token', $this->mToken, $exp, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
                } else {
                        setcookie( $wgDBname.'Token', '', time() - 3600 );
                }
@@ -1310,17 +1324,17 @@ class User {
         * It will clean the session cookie
         */
        function logout() {
-               global $wgCookiePath, $wgCookieDomain, $wgDBname;
+               global $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgDBname;
                $this->loadDefaults();
                $this->setLoaded( true );
 
                $_SESSION['wsUserID'] = 0;
 
-               setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
-               setcookie( $wgDBname.'Token', '', time() - 3600, $wgCookiePath, $wgCookieDomain );
+               setcookie( $wgDBname.'UserID', '', time() - 3600, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
+               setcookie( $wgDBname.'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( $wgDBname.'LoggedOut', wfTimestampNow(), time() + 86400, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
        }
 
        /**
@@ -1388,7 +1402,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();
@@ -1445,6 +1460,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 ){
@@ -1463,9 +1491,13 @@ class User {
                // add in language specific options, if any
                $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() {
@@ -1517,12 +1549,11 @@ class User {
 
        /**
         * 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' );
        }
 
        /**
@@ -1807,9 +1838,9 @@ class User {
                global $wgGroupPermissions;
                return array_diff(
                        array_keys( $wgGroupPermissions ),
-                       array( '*', 'user' ) );
+                       array( '*', 'user', 'autoconfirmed' ) );
        }
-
+       
 }
 
 ?>