API: Improve list=random
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index f446a98..0410ef0 100644 (file)
@@ -44,6 +44,24 @@ class LoginForm extends SpecialPage {
        const WRONG_TOKEN = 13;
        const USER_MIGRATED = 14;
 
+       public static $statusCodes = array(
+               self::SUCCESS => 'success',
+               self::NO_NAME => 'no_name',
+               self::ILLEGAL => 'illegal',
+               self::WRONG_PLUGIN_PASS => 'wrong_plugin_pass',
+               self::NOT_EXISTS => 'not_exists',
+               self::WRONG_PASS => 'wrong_pass',
+               self::EMPTY_PASS => 'empty_pass',
+               self::RESET_PASS => 'reset_pass',
+               self::ABORTED => 'aborted',
+               self::CREATE_BLOCKED => 'create_blocked',
+               self::THROTTLED => 'throttled',
+               self::USER_BLOCKED => 'user_blocked',
+               self::NEED_TOKEN => 'need_token',
+               self::WRONG_TOKEN => 'wrong_token',
+               self::USER_MIGRATED => 'user_migrated',
+       );
+
        /**
         * Valid error and warning messages
         *
@@ -541,7 +559,13 @@ class LoginForm extends SpecialPage {
                $u = User::newFromName( $this->mUsername, 'creatable' );
                if ( !$u ) {
                        return Status::newFatal( 'noname' );
-               } elseif ( 0 != $u->idForName( User::READ_LOCKING ) ) {
+               }
+
+               # Make sure the user does not exist already
+               $lock = $wgMemc->getScopedLock( wfGlobalCacheKey( 'account', md5( $this->mUsername ) ) );
+               if ( !$lock ) {
+                       return Status::newFatal( 'usernameinprogress' );
+               } elseif ( $u->idForName( User::READ_LOCKING ) ) {
                        return Status::newFatal( 'userexists' );
                }
 
@@ -921,8 +945,8 @@ class LoginForm extends SpecialPage {
                global $wgMemc, $wgLang, $wgSecureLogin, $wgPasswordAttemptThrottle,
                        $wgInvalidPasswordReset;
 
-               $status = $this->authenticateUserData();
-               switch ( $status ) {
+               $authRes = $this->authenticateUserData();
+               switch ( $authRes ) {
                        case self::SUCCESS:
                                # We've verified now, update the real record
                                $user = $this->getUser();
@@ -1048,8 +1072,8 @@ class LoginForm extends SpecialPage {
 
                LoggerFactory::getInstance( 'authmanager' )->info( 'Login attempt', array(
                        'event' => 'login',
-                       'successful' => $status === self::SUCCESS,
-                       'status' => $status,
+                       'successful' => $authRes === self::SUCCESS,
+                       'status' => LoginForm::$statusCodes[$authRes],
                ) );
        }
 
@@ -1343,9 +1367,6 @@ class LoginForm extends SpecialPage {
                        'mediawiki.ui.input',
                        'mediawiki.special.userlogin.common.styles'
                ) );
-               $out->addModules( array(
-                       'mediawiki.special.userlogin.common.js'
-               ) );
 
                if ( $this->mType == 'signup' ) {
                        // XXX hack pending RL or JS parse() support for complex content messages