X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FUser.php;h=665a68955c5df26145a897ff9c966bfc4f449b7a;hb=e66ee985e0792d2c28ebb0d5b299af5bce87eb9b;hp=8a5e74d08e03df18f5e1346ee5b8667f0b4375f8;hpb=612fbbf536c818686ab32a55911b77cc812394d5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/User.php b/includes/User.php index 8a5e74d08e..665a68955c 100644 --- a/includes/User.php +++ b/includes/User.php @@ -519,19 +519,24 @@ class User implements IDBAccessObject { * If the code is invalid or has expired, returns NULL. * * @param string $code Confirmation code + * @param int $flags User::READ_* bitfield * @return User|null */ - public static function newFromConfirmationCode( $code ) { - $dbr = wfGetDB( DB_SLAVE ); - $id = $dbr->selectField( 'user', 'user_id', array( - 'user_email_token' => md5( $code ), - 'user_email_token_expires > ' . $dbr->addQuotes( $dbr->timestamp() ), - ) ); - if ( $id !== false ) { - return User::newFromId( $id ); - } else { - return null; - } + public static function newFromConfirmationCode( $code, $flags = 0 ) { + $db = ( $flags & self::READ_LATEST ) == self::READ_LATEST + ? wfGetDB( DB_MASTER ) + : wfGetDB( DB_SLAVE ); + + $id = $db->selectField( + 'user', + 'user_id', + array( + 'user_email_token' => md5( $code ), + 'user_email_token_expires > ' . $db->addQuotes( $db->timestamp() ), + ) + ); + + return $id ? User::newFromId( $id ) : null; } /** @@ -3385,19 +3390,24 @@ class User implements IDBAccessObject { return; } - $nextid = $oldid ? $title->getNextRevisionID( $oldid ) : null; + $that = $this; + // Try to update the DB post-send and only if needed... + DeferredUpdates::addCallableUpdate( function() use ( $that, $title, $oldid ) { + if ( !$that->getNewtalk() ) { + return; // no notifications to clear + } - if ( !$oldid || !$nextid ) { - // If we're looking at the latest revision, we should definitely clear it - $this->setNewtalk( false ); - } else { - // Otherwise we should update its revision, if it's present - if ( $this->getNewtalk() ) { - // Naturally the other one won't clear by itself - $this->setNewtalk( false ); - $this->setNewtalk( true, Revision::newFromId( $nextid ) ); + // Delete the last notifications (they stack up) + $that->setNewtalk( false ); + + // If there is a new, unseen, revision, use its timestamp + $nextid = $oldid + ? $title->getNextRevisionID( $oldid, Title::GAID_FOR_UPDATE ) + : null; + if ( $nextid ) { + $that->setNewtalk( true, Revision::newFromId( $nextid ) ); } - } + } ); } if ( !$wgUseEnotif && !$wgShowUpdatedMarker ) { @@ -3682,12 +3692,10 @@ class User implements IDBAccessObject { $this->clearSharedCache(); // User was changed in the meantime or loaded with stale data $from = ( $this->queryFlagsUsed & self::READ_LATEST ) ? 'master' : 'slave'; - MWExceptionHandler::logException( new MWException( + throw new MWException( "CAS update failed on user_touched for user ID '{$this->mId}' (read from $from);" . - "the version of the user to be saved is older than the current version." - ) ); - - return; + " the version of the user to be saved is older than the current version." + ); } $this->mTouched = $newTouched; @@ -3723,15 +3731,13 @@ class User implements IDBAccessObject { : wfGetDB( DB_SLAVE ); $options = ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING ) - ? array( 'FOR UPDATE' ) + ? array( 'LOCK IN SHARE MODE' ) : array(); - $id = $db->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__, $options ); - if ( $id === false ) { - $id = 0; - } + $id = $db->selectField( 'user', + 'user_id', array( 'user_name' => $s ), __METHOD__, $options ); - return $id; + return (int)$id; } /** @@ -4251,7 +4257,9 @@ class User implements IDBAccessObject { } $to = MailAddress::newFromUser( $this ); - return UserMailer::send( $to, $sender, $subject, $body, $replyto ); + return UserMailer::send( $to, $sender, $subject, $body, array( + 'replyTo' => $replyto, + ) ); } /**