Merge "Allow extensions to indicate a username doesn't exist"
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index afa12a0..845413e 100644 (file)
@@ -41,6 +41,7 @@ class LoginForm extends SpecialPage {
        const USER_BLOCKED = 11;
        const NEED_TOKEN = 12;
        const WRONG_TOKEN = 13;
+       const USER_MIGRATED = 14;
 
        /**
         * Valid error and warning messages
@@ -697,6 +698,14 @@ class LoginForm extends SpecialPage {
                }
 
                $u = User::newFromName( $this->mUsername );
+
+               // Give extensions a way to indicate the username has been updated,
+               // rather than telling the user the account doesn't exist.
+               if ( !wfRunHooks( 'LoginUserMigrated', array( $u, &$msg ) ) ) {
+                       $this->mAbortLoginErrorMsg = $msg;
+                       return self::USER_MIGRATED;
+               }
+
                if ( !( $u instanceof User ) || !User::isUsableName( $u->getName() ) ) {
                        return self::ILLEGAL;
                }
@@ -996,6 +1005,15 @@ class LoginForm extends SpecialPage {
                                $this->mainLoginForm( $this->msg( $error,
                                                wfEscapeWikiText( $this->mUsername ) )->text() );
                                break;
+                       case self::USER_MIGRATED:
+                               $error = $this->mAbortLoginErrorMsg ?: 'login-migrated-generic';
+                               $params = array();
+                               if ( is_array( $error ) ) {
+                                       $error = array_shift( $this->mAbortLoginErrorMsg );
+                                       $params = $this->mAbortLoginErrorMsg;
+                               }
+                               $this->mainLoginForm( $this->msg( $error, $params )->text() );
+                               break;
                        default:
                                throw new MWException( 'Unhandled case value' );
                }
@@ -1374,7 +1392,6 @@ class LoginForm extends SpecialPage {
                $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
                $template->set( 'stickhttps', (int)$this->mStickHTTPS );
                $template->set( 'loggedin', $user->isLoggedIn() );
-               $template->set( 'loggedinuser', $user->getName() );
 
                if ( $this->mType == 'signup' ) {
                        if ( !self::getCreateaccountToken() ) {