Fix missing mw-ui-button on Login and create page
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index afa12a0..bdd6751 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
@@ -104,9 +105,12 @@ class LoginForm extends SpecialPage {
         * @param WebRequest $request
         */
        public function __construct( $request = null ) {
+               global $wgUseMediaWikiUIEverywhere;
                parent::__construct( 'Userlogin' );
 
                $this->mOverrideRequest = $request;
+               // Override UseMediaWikiEverywhere to true, to force login and create form to use mw ui
+               $wgUseMediaWikiUIEverywhere = true;
        }
 
        /**
@@ -237,11 +241,19 @@ class LoginForm extends SpecialPage {
                }
                $this->setHeaders();
 
-               // In the case where the user is already logged in, do not show the login page.
-               // The use case scenario for this is when a user opens a large number of tabs, is
-               // redirected to the login page on all of them, and then logs in on one, expecting
-               // all the others to work properly.
-               if ( $this->mType !== 'signup' && !$this->mPosted && $this->getUser()->isLoggedIn() ) {
+               // In the case where the user is already logged in, and was redirected to the login form from a
+               // page that requires login, do not show the login page. The use case scenario for this is when
+               // a user opens a large number of tabs, is redirected to the login page on all of them, and then
+               // logs in on one, expecting all the others to work properly.
+               //
+               // However, do show the form if it was visited intentionally (no 'returnto' is present). People
+               // who often switch between several accounts have grown accustomed to this behavior.
+               if (
+                       $this->mType !== 'signup' &&
+                       !$this->mPosted &&
+                       $this->getUser()->isLoggedIn() &&
+                       ( $this->mReturnTo !== '' || $this->mReturnToQuery !== '' )
+               ) {
                        $this->successfulLogin();
                }
 
@@ -697,6 +709,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 +1016,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' );
                }
@@ -1397,16 +1426,9 @@ class LoginForm extends SpecialPage {
                }
 
                $template->set( 'secureLoginUrl', $this->mSecureLoginUrl );
-               // Use loginend-https for HTTPS requests if it's not blank, loginend otherwise
-               // Ditto for signupend.  New forms use neither.
+               // Use signupend-https for HTTPS requests if it's not blank, signupend otherwise
                $usingHTTPS = $this->mRequest->getProtocol() == 'https';
-               $loginendHTTPS = $this->msg( 'loginend-https' );
                $signupendHTTPS = $this->msg( 'signupend-https' );
-               if ( $usingHTTPS && !$loginendHTTPS->isBlank() ) {
-                       $template->set( 'loginend', $loginendHTTPS->parse() );
-               } else {
-                       $template->set( 'loginend', $this->msg( 'loginend' )->parse() );
-               }
                if ( $usingHTTPS && !$signupendHTTPS->isBlank() ) {
                        $template->set( 'signupend', $signupendHTTPS->parse() );
                } else {