Merge "Revert "Use display name in category page subheadings if provided""
[lhc/web/wiklou.git] / includes / specialpage / LoginSignupSpecialPage.php
index 9d17e7d..1e03774 100644 (file)
@@ -156,7 +156,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                        [
                                'returnto' => $this->mReturnTo,
                                'returntoquery' => $this->mReturnToQuery,
-                               'uselang' => $this->mLanguage,
+                               'uselang' => $this->mLanguage ?: null,
                                'fromhttp' => $wgSecureLogin && $this->mFromHTTP ? '1' : null,
                        ]
                );
@@ -359,7 +359,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                                $this->authAction = $this->isSignup() ? AuthManager::ACTION_CREATE_CONTINUE
                                        : AuthManager::ACTION_LOGIN_CONTINUE;
                                $this->authRequests = $response->neededRequests;
-                               $this->mainLoginForm( $response->neededRequests, $response->message, 'warning' );
+                               $this->mainLoginForm( $response->neededRequests, $response->message, $response->messageType );
                                break;
                        default:
                                throw new LogicException( 'invalid AuthenticationResponse' );
@@ -499,7 +499,25 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
 
                $form = $this->getAuthForm( $requests, $this->authAction, $msg, $msgtype );
                $form->prepareForm();
-               $formHtml = $form->getHTML( $msg ? Status::newFatal( $msg ) : false );
+
+               $submitStatus = Status::newGood();
+               if ( $msg && $msgtype === 'warning' ) {
+                       $submitStatus->warning( $msg );
+               } elseif ( $msg && $msgtype === 'error' ) {
+                       $submitStatus->fatal( $msg );
+               }
+
+               // warning header for non-standard workflows (e.g. security reauthentication)
+               if (
+                       !$this->isSignup() &&
+                       $this->getUser()->isLoggedIn() &&
+                       $this->authAction !== AuthManager::ACTION_LOGIN_CONTINUE
+               ) {
+                       $reauthMessage = $this->securityLevel ? 'userlogin-reauth' : 'userlogin-loggedin';
+                       $submitStatus->warning( $reauthMessage, $this->getUser()->getName() );
+               }
+
+               $formHtml = $form->getHTML( $submitStatus );
 
                $out->addHTML( $this->getPageHtml( $formHtml ) );
        }
@@ -601,7 +619,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                $form = HTMLForm::factory( 'vform', $formDescriptor, $context );
 
                $form->addHiddenField( 'authAction', $this->authAction );
-               if ( $wgLoginLanguageSelector ) {
+               if ( $wgLoginLanguageSelector && $this->mLanguage ) {
                        $form->addHiddenField( 'uselang', $this->mLanguage );
                }
                $form->addHiddenField( 'force', $this->securityLevel );
@@ -621,13 +639,6 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                        $form->setId( 'userlogin2' );
                }
 
-               // warning header for non-standard workflows (e.g. security reauthentication)
-               if ( !$this->isSignup() && $this->getUser()->isLoggedIn() ) {
-                       $reauthMessage = $this->securityLevel ? 'userlogin-reauth' : 'userlogin-loggedin';
-                       $form->addHeaderText( Html::rawElement( 'div', [ 'class' => 'warningbox' ],
-                               $this->msg( $reauthMessage )->params( $this->getUser()->getName() )->parse() ) );
-               }
-
                $form->suppressDefaultSubmit();
 
                $this->authForm = $form;
@@ -648,7 +659,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                // make a best effort to get the value of fields which used to be fixed in the old login
                // template but now might or might not exist depending on what providers are used
                $request = $this->getRequest();
-               $data = (object) [
+               $data = (object)[
                        'mUsername' => $request->getText( 'wpName' ),
                        'mPassword' => $request->getText( 'wpPassword' ),
                        'mRetype' => $request->getText( 'wpRetype' ),
@@ -752,14 +763,21 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                $wgAuth->modifyUITemplate( $template, $action );
 
                $oldTemplate = $template;
-               $hookName = $this->isSignup() ? 'UserCreateForm' : 'UserLoginForm';
-               Hooks::run( $hookName, [ &$template ] );
-               if ( $oldTemplate !== $template ) {
-                       wfDeprecated( "reference in $hookName hook", '1.27' );
+
+               // Both Hooks::run are explicit here to make findHooks.php happy
+               if ( $this->isSignup() ) {
+                       Hooks::run( 'UserCreateForm', [ &$template ] );
+                       if ( $oldTemplate !== $template ) {
+                               wfDeprecated( "reference in UserCreateForm hook", '1.27' );
+                       }
+               } else {
+                       Hooks::run( 'UserLoginForm', [ &$template ] );
+                       if ( $oldTemplate !== $template ) {
+                               wfDeprecated( "reference in UserLoginForm hook", '1.27' );
+                       }
                }
 
                return $template;
-
        }
 
        public function onAuthChangeFormFields(
@@ -1063,7 +1081,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                }
                if ( !$this->isSignup() && $this->showExtraInformation() ) {
                        $passwordReset = new PasswordReset( $this->getConfig(), AuthManager::singleton() );
-                       if ( $passwordReset->isAllowed( $this->getUser() ) ) {
+                       if ( $passwordReset->isAllowed( $this->getUser() )->isGood() ) {
                                $fieldDefinitions['passwordReset'] = [
                                        'type' => 'info',
                                        'raw' => true,