Merge "Made the prior user existence check in LoginForm use DB_MASTER"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 11 Jul 2015 00:37:31 +0000 (00:37 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 11 Jul 2015 00:37:31 +0000 (00:37 +0000)
includes/User.php
includes/specials/SpecialUserlogin.php

index 26d54ab..95ac0f1 100644 (file)
@@ -3706,19 +3706,29 @@ class User implements IDBAccessObject {
 
        /**
         * If only this user's username is known, and it exists, return the user ID.
+        *
+        * @param int $flags Bitfield of User:READ_* constants; useful for existence checks
         * @return int
         */
-       public function idForName() {
+       public function idForName( $flags = 0 ) {
                $s = trim( $this->getName() );
                if ( $s === '' ) {
                        return 0;
                }
 
-               $dbr = wfGetDB( DB_SLAVE );
-               $id = $dbr->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__ );
+               $db = ( ( $flags & self::READ_LATEST ) == self::READ_LATEST )
+                       ? wfGetDB( DB_MASTER )
+                       : wfGetDB( DB_SLAVE );
+
+               $options = ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING )
+                       ? array( 'FOR UPDATE' )
+                       : array();
+
+               $id = $db->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__, $options );
                if ( $id === false ) {
                        $id = 0;
                }
+
                return $id;
        }
 
index 472fdb7..aa51415 100644 (file)
@@ -529,9 +529,9 @@ class LoginForm extends SpecialPage {
 
                # Now create a dummy user ($u) and check if it is valid
                $u = User::newFromName( $this->mUsername, 'creatable' );
-               if ( !is_object( $u ) ) {
+               if ( !$u ) {
                        return Status::newFatal( 'noname' );
-               } elseif ( 0 != $u->idForName() ) {
+               } elseif ( 0 != $u->idForName( User::READ_LOCKING ) ) {
                        return Status::newFatal( 'userexists' );
                }