Localisation updates from http://translatewiki.net.
[lhc/web/wiklou.git] / includes / User.php
index e95e530..5de4b2c 100644 (file)
@@ -847,7 +847,7 @@ class User {
                // Multiply by 1.25 to get the number of hex characters we need
                $length = $length * 1.25;
                // Generate random hex chars
-               $hex = MWCryptRand::generateHex( $length, __METHOD__ );
+               $hex = MWCryptRand::generateHex( $length );
                // Convert from base 16 to base 32 to get a proper password like string
                return wfBaseConvert( $hex, 16, 32 );
        }
@@ -1283,11 +1283,11 @@ class User {
                }
 
                # User/IP blocking
-               $block = Block::newFromTarget( $this->getName(), $ip, !$bFromSlave );
+               $block = Block::newFromTarget( $this, $ip, !$bFromSlave );
 
                # Proxy blocking
                if ( !$block instanceof Block && $ip !== null && !$this->isAllowed( 'proxyunbannable' )
-                       && !in_array( $ip, $wgProxyWhitelist ) ) 
+                       && !in_array( $ip, $wgProxyWhitelist ) )
                {
                        # Local list
                        if ( self::isLocallyBlockedProxy( $ip ) ) {
@@ -1517,7 +1517,7 @@ class User {
                        $count = $wgMemc->get( $key );
                        // Already pinged?
                        if( $count ) {
-                               if( $count > $max ) {
+                               if( $count >= $max ) {
                                        wfDebug( __METHOD__ . ": tripped! $key at $count $summary\n" );
                                        if( $wgRateLimitLog ) {
                                                wfSuppressWarnings();
@@ -1926,10 +1926,19 @@ class User {
                        $this->mTouched = self::newTouchedTimestamp();
 
                        $dbw = wfGetDB( DB_MASTER );
-                       $dbw->update( 'user',
-                               array( 'user_touched' => $dbw->timestamp( $this->mTouched ) ),
-                               array( 'user_id' => $this->mId ),
-                               __METHOD__ );
+
+                       // Prevent contention slams by checking user_touched first
+                       $now = $dbw->timestamp( $this->mTouched );
+                       $needsPurge = $dbw->selectField( 'user', '1',
+                               array( 'user_id' => $this->mId, 'user_touched < ' . $dbw->addQuotes( $now ) )
+                       );
+                       if ( $needsPurge ) {
+                               $dbw->update( 'user',
+                                       array( 'user_touched' => $now ),
+                                       array( 'user_id' => $this->mId, 'user_touched < ' . $dbw->addQuotes( $now ) ),
+                                       __METHOD__
+                               );
+                       }
 
                        $this->clearSharedCache();
                }
@@ -2041,10 +2050,9 @@ class User {
         * @param $token String|bool If specified, set the token to this value
         */
        public function setToken( $token = false ) {
-               global $wgSecretKey, $wgProxyKey;
                $this->load();
                if ( !$token ) {
-                       $this->mToken = MWCryptRand::generateHex( USER_TOKEN_LENGTH, __METHOD__ );
+                       $this->mToken = MWCryptRand::generateHex( USER_TOKEN_LENGTH );
                } else {
                        $this->mToken = $token;
                }
@@ -2113,6 +2121,42 @@ class User {
                wfRunHooks( 'UserSetEmail', array( $this, &$this->mEmail ) );
        }
 
+       /**
+        * Set the user's e-mail address and a confirmation mail if needed.
+        *
+        * @since 1.20
+        * @param $str String New e-mail address
+        * @return Status
+        */
+       public function setEmailWithConfirmation( $str ) {
+               global $wgEnableEmail, $wgEmailAuthentication;
+
+               if ( !$wgEnableEmail ) {
+                       return Status::newFatal( 'emaildisabled' );
+               }
+
+               $oldaddr = $this->getEmail();
+               if ( $str === $oldaddr ) {
+                       return Status::newGood( true );
+               }
+
+               $this->setEmail( $str );
+
+               if ( $str !== '' && $wgEmailAuthentication ) {
+                       # Send a confirmation request to the new address if needed
+                       $type = $oldaddr != '' ? 'changed' : 'set';
+                       $result = $this->sendConfirmationMail( $type );
+                       if ( $result->isGood() ) {
+                               # Say the the caller that a confirmation mail has been sent
+                               $result->value = 'eauth';
+                       }
+               } else {
+                       $result = Status::newGood( true );
+               }
+
+               return $result;
+       }
+
        /**
         * Get the user's real name
         * @return String User's real name
@@ -2246,7 +2290,10 @@ class User {
         * Reset all options to the site defaults
         */
        public function resetOptions() {
+               $this->load();
+
                $this->mOptions = self::getDefaultOptions();
+               $this->mOptionsLoaded = true;
        }
 
        /**
@@ -2976,7 +3023,7 @@ class User {
         */
        public function getPageRenderingHash() {
                wfDeprecated( __METHOD__, '1.17' );
-               
+
                global $wgUseDynamicDates, $wgRenderHashAppend, $wgLang, $wgContLang;
                if( $this->mHash ){
                        return $this->mHash;
@@ -3179,7 +3226,7 @@ class User {
                } else {
                        $token = $request->getSessionData( 'wsEditToken' );
                        if ( $token === null ) {
-                               $token = MWCryptRand::generateHex( 32, __METHOD__ );
+                               $token = MWCryptRand::generateHex( 32 );
                                $request->setSessionData( 'wsEditToken', $token );
                        }
                        if( is_array( $salt ) ) {
@@ -3197,7 +3244,7 @@ class User {
         * @deprecated since 1.20; Use MWCryptRand for secure purposes or wfRandomString for pesudo-randomness
         */
        public static function generateToken( $salt = '' ) {
-               return MWCryptRand::generateHex( 32, __METHOD__ );
+               return MWCryptRand::generateHex( 32 );
        }
 
        /**
@@ -3303,11 +3350,12 @@ class User {
                global $wgUserEmailConfirmationTokenExpiry;
                $now = time();
                $expires = $now + $wgUserEmailConfirmationTokenExpiry;
+               $expiration = wfTimestamp( TS_MW, $expires );
                $this->load();
-               $token = MWCryptRand::generateHex( 32, __METHOD__ );
+               $token = MWCryptRand::generateHex( 32 );
                $hash = md5( $token );
                $this->mEmailToken = $hash;
-               $this->mEmailTokenExpires = wfTimestamp( TS_MW, $expires );
+               $this->mEmailTokenExpires = $expiration;
                return $token;
        }
 
@@ -3326,7 +3374,7 @@ class User {
         * @return String New token URL
         */
        private function invalidationTokenUrl( $token ) {
-               return $this->getTokenUrl( 'Invalidateemail', $token );
+               return $this->getTokenUrl( 'InvalidateEmail', $token );
        }
 
        /**
@@ -3856,7 +3904,7 @@ class User {
 
                if( $wgPasswordSalt ) {
                        if ( $salt === false ) {
-                               $salt = MWCryptRand::generateHex( 8, __METHOD__ );
+                               $salt = MWCryptRand::generateHex( 8 );
                        }
                        return ':B:' . $salt . ':' . md5( $salt . '-' . md5( $password ) );
                } else {
@@ -3888,7 +3936,7 @@ class User {
                } elseif ( $type == ':B:' ) {
                        # Salted
                        list( $salt, $realHash ) = explode( ':', substr( $hash, 3 ), 2 );
-                       return md5( $salt.'-'.md5( $password ) ) == $realHash;
+                       return md5( $salt.'-'.md5( $password ) ) === $realHash;
                } else {
                        # Old-style
                        return self::oldCrypt( $password, $userId ) === $hash;