Merge "Fix the grammar of apihelp-query+backlinks-param-limit"
[lhc/web/wiklou.git] / includes / User.php
index 06ae856..cefbe62 100644 (file)
@@ -3385,19 +3385,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 ) {
@@ -3684,7 +3689,7 @@ class User implements IDBAccessObject {
                        $from = ( $this->queryFlagsUsed & self::READ_LATEST ) ? 'master' : 'slave';
                        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."
+                               " the version of the user to be saved is older than the current version."
                        );
                }
 
@@ -3721,15 +3726,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;
        }
 
        /**
@@ -4249,7 +4252,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,
+               ) );
        }
 
        /**