jenkins-bot has submitted this change and it was merged. Change subject: Special:UserLogin: Don't show login button when not required ......................................................................
Special:UserLogin: Don't show login button when not required If no AuthenticationRequest requires a separate login button, it shouldn'tbe visible. This is, for example, the case, when only link providers are used, that require the user to redirect to a third party site, as it usually just shows a single submit button. In this case, the login button is still visible because of other additional fields, such as the remember me button. This change checks each primary authentication provider, if it provides its provide his own submit button or not, and if so, removes the login button completely. Bug: T141471 Change-Id: Ib18a69582cb3f79d438ab009d8755f0d5e415bcb --- M includes/specialpage/AuthManagerSpecialPage.php M includes/specialpage/LoginSignupSpecialPage.php M includes/specials/SpecialChangeCredentials.php 3 files changed, 33 insertions(+), 19 deletions(-) Approvals: Florianschmidtwelzow: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/specialpage/AuthManagerSpecialPage.php b/includes/specialpage/AuthManagerSpecialPage.php index 9833c73..bf8ef9f 100644 --- a/includes/specialpage/AuthManagerSpecialPage.php +++ b/includes/specialpage/AuthManagerSpecialPage.php @@ -537,7 +537,7 @@ $form->setAction( $this->getFullTitle()->getFullURL( $this->getPreservedParams() ) ); $form->addHiddenField( $this->getTokenName(), $this->getToken()->toString() ); $form->addHiddenField( 'authAction', $this->authAction ); - $form->suppressDefaultSubmit( !$this->needsSubmitButton( $formDescriptor ) ); + $form->suppressDefaultSubmit( !$this->needsSubmitButton( $requests ) ); return $form; } @@ -555,24 +555,38 @@ } /** - * Returns true if the form has fields which take values. If all available providers use the - * redirect flow, the form might contain nothing but submit buttons, in which case we should - * not add an extra submit button which does nothing. + * Returns true if the form built from the given AuthenticationRequests has fields which take + * values. If all available providers use the redirect flow, the form might contain nothing + * but submit buttons, in which case we should not add an extra submit button which does nothing. * - * @param array $formDescriptor A HTMLForm descriptor + * @param AuthenticationRequest[] $requests An array of AuthenticationRequests from which the + * form will be built * @return bool */ - protected function needsSubmitButton( $formDescriptor ) { - return (bool)array_filter( $formDescriptor, function ( $item ) { - $class = false; - if ( array_key_exists( 'class', $item ) ) { - $class = $item['class']; - } elseif ( array_key_exists( 'type', $item ) ) { - $class = HTMLForm::$typeMappings[$item['type']]; + protected function needsSubmitButton( array $requests ) { + foreach ( $requests as $req ) { + if ( $req->required === AuthenticationRequest::PRIMARY_REQUIRED && + $this->doesRequestNeedsSubmitButton( $req ) + ) { + return true; } - return !is_a( $class, \HTMLInfoField::class, true ) && - !is_a( $class, \HTMLSubmitField::class, true ); - } ); + } + return false; + } + + /** + * Checks if the given AuthenticationRequest needs a submit button or not. + * + * @param AuthenticationRequest $req The request to check + * @return bool + */ + protected function doesRequestNeedsSubmitButton( AuthenticationRequest $req ) { + foreach ( $req->getFieldInfo() as $field => $info ) { + if ( $info['type'] === 'button' ) { + return false; + } + } + return true; } /** diff --git a/includes/specialpage/LoginSignupSpecialPage.php b/includes/specialpage/LoginSignupSpecialPage.php index 2a9a938..90774ef 100644 --- a/includes/specialpage/LoginSignupSpecialPage.php +++ b/includes/specialpage/LoginSignupSpecialPage.php @@ -586,7 +586,7 @@ $this->fakeTemplate = $fakeTemplate; // FIXME there should be a saner way to pass this to the hook // this will call onAuthChangeFormFields() $formDescriptor = static::fieldInfoToFormDescriptor( $requests, $fieldInfo, $this->authAction ); - $this->postProcessFormDescriptor( $formDescriptor ); + $this->postProcessFormDescriptor( $formDescriptor, $requests ); $context = $this->getContext(); if ( $context->getRequest() !== $this->getRequest() ) { @@ -1249,7 +1249,7 @@ /** * @param array $formDescriptor */ - protected function postProcessFormDescriptor( &$formDescriptor ) { + protected function postProcessFormDescriptor( &$formDescriptor, $requests ) { // Pre-fill username (if not creating an account, T46775). if ( isset( $formDescriptor['username'] ) && @@ -1267,7 +1267,7 @@ // don't show a submit button if there is nothing to submit (i.e. the only form content // is other submit buttons, for redirect flows) - if ( !$this->needsSubmitButton( $formDescriptor ) ) { + if ( !$this->needsSubmitButton( $requests ) ) { unset( $formDescriptor['createaccount'], $formDescriptor['loginattempt'] ); } diff --git a/includes/specials/SpecialChangeCredentials.php b/includes/specials/SpecialChangeCredentials.php index 382dac7..9bf25ae 100644 --- a/includes/specials/SpecialChangeCredentials.php +++ b/includes/specials/SpecialChangeCredentials.php @@ -159,7 +159,7 @@ return $form; } - protected function needsSubmitButton( $formDescriptor ) { + protected function needsSubmitButton( array $requests ) { // Change/remove forms show are built from a single AuthenticationRequest and do not allow // for redirect flow; they always need a submit button. return true; -- To view, visit https://gerrit.wikimedia.org/r/313596 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib18a69582cb3f79d438ab009d8755f0d5e415bcb Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/core Gerrit-Branch: REL1_27 Gerrit-Owner: Cicalese <cical...@mitre.org> Gerrit-Reviewer: Cicalese <cical...@mitre.org> Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits