Merge "Add CollationFa"
[lhc/web/wiklou.git] / includes / specialpage / LoginSignupSpecialPage.php
index 1e03774..540ce4b 100644 (file)
@@ -149,9 +149,9 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                $entryWarning = $this->msg( $request->getVal( 'warning', '' ) );
                // bc: provide login link as a parameter for messages where the translation
                // was not updated
-               $loginreqlink = Linker::linkKnown(
+               $loginreqlink = $this->getLinkRenderer()->makeKnownLink(
                        $this->getPageTitle(),
-                       $this->msg( 'loginreqlink' )->escaped(),
+                       $this->msg( 'loginreqlink' )->text(),
                        [],
                        [
                                'returnto' => $this->mReturnTo,
@@ -294,6 +294,14 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                        return;
                }
 
+               if ( $this->canBypassForm( $button_name ) ) {
+                       $this->setRequest( [], true );
+                       $this->getRequest()->setVal( $this->getTokenName(), $this->getToken() );
+                       if ( $button_name ) {
+                               $this->getRequest()->setVal( $button_name, true );
+                       }
+               }
+
                $status = $this->trySubmit();
 
                if ( !$status || !$status->isGood() ) {
@@ -366,6 +374,46 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                }
        }
 
+       /**
+        * Determine if the login form can be bypassed. This will be the case when no more than one
+        * button is present and no other user input fields that are not marked as 'skippable' are
+        * present. If the login form were not bypassed, the user would be presented with a
+        * superfluous page on which they must press the single button to proceed with login.
+        * Not only does this cause an additional mouse click and page load, it confuses users,
+        * especially since there are a help link and forgotten password link that are
+        * provided on the login page that do not apply to this situation.
+        *
+        * @param string|null &$button_name if the form has a single button, returns
+        *   the name of the button; otherwise, returns null
+        * @return bool
+        */
+       private function canBypassForm( &$button_name ) {
+               $button_name = null;
+               if ( $this->isContinued() ) {
+                       return false;
+               }
+               $fields = AuthenticationRequest::mergeFieldInfo( $this->authRequests );
+               foreach ( $fields as $fieldname => $field ) {
+                       if ( !isset( $field['type'] ) ) {
+                               return false;
+                       }
+                       if ( !empty( $field['skippable'] ) ) {
+                               continue;
+                       }
+                       if ( $field['type'] === 'button' ) {
+                               if ( $button_name !== null ) {
+                                       $button_name = null;
+                                       return false;
+                               } else {
+                                       $button_name = $fieldname;
+                               }
+                       } elseif ( $field['type'] !== 'null' ) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+
        /**
         * Show the success page.
         *
@@ -593,7 +641,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
         * @return HTMLForm
         */
        protected function getAuthForm( array $requests, $action, $msg = '', $msgType = 'error' ) {
-               global $wgSecureLogin, $wgLoginLanguageSelector;
+               global $wgSecureLogin;
                // FIXME merge this with parent
 
                if ( isset( $this->authForm ) ) {
@@ -619,7 +667,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                $form = HTMLForm::factory( 'vform', $formDescriptor, $context );
 
                $form->addHiddenField( 'authAction', $this->authAction );
-               if ( $wgLoginLanguageSelector && $this->mLanguage ) {
+               if ( $this->mLanguage ) {
                        $form->addHiddenField( 'uselang', $this->mLanguage );
                }
                $form->addHiddenField( 'force', $this->securityLevel );
@@ -654,7 +702,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
         */
        protected function getFakeTemplate( $msg, $msgType ) {
                global $wgAuth, $wgEnableEmail, $wgHiddenPrefs, $wgEmailConfirmToEdit, $wgEnableUserEmail,
-                          $wgSecureLogin, $wgLoginLanguageSelector, $wgPasswordResetRoutes;
+                          $wgSecureLogin, $wgPasswordResetRoutes;
 
                // 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
@@ -712,7 +760,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                # Don't show a "create account" link if the user can't.
                if ( $this->showCreateAccountLink() ) {
                        # Pass any language selection on to the mode switch link
-                       if ( $wgLoginLanguageSelector && $this->mLanguage ) {
+                       if ( $this->mLanguage ) {
                                $linkq .= '&uselang=' . $this->mLanguage;
                        }
                        // Supply URL, login template creates the button.
@@ -844,7 +892,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
         * @return array
         */
        protected function getFieldDefinitions( $template ) {
-               global $wgEmailConfirmToEdit, $wgLoginLanguageSelector;
+               global $wgEmailConfirmToEdit;
 
                $isLoggedIn = $this->getUser()->isLoggedIn();
                $continuePart = $this->isContinued() ? 'continue-' : '';
@@ -1086,9 +1134,9 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                                        'type' => 'info',
                                        'raw' => true,
                                        'cssclass' => 'mw-form-related-link-container',
-                                       'default' => Linker::link(
+                                       'default' => $this->getLinkRenderer()->makeLink(
                                                SpecialPage::getTitleFor( 'PasswordReset' ),
-                                               $this->msg( 'userlogin-resetpassword-link' )->escaped()
+                                               $this->msg( 'userlogin-resetpassword-link' )->text()
                                        ),
                                        'weight' => 230,
                                ];
@@ -1100,7 +1148,7 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                                $linkTitle = $this->getTitleFor( $this->isSignup() ? 'Userlogin' :'CreateAccount' );
                                $linkq = $this->getReturnToQueryStringFragment();
                                // Pass any language selection on to the mode switch link
-                               if ( $wgLoginLanguageSelector && $this->mLanguage ) {
+                               if ( $this->mLanguage ) {
                                        $linkq .= '&uselang=' . $this->mLanguage;
                                }
                                $loggedIn = $this->getUser()->isLoggedIn();
@@ -1267,9 +1315,9 @@ abstract class LoginSignupSpecialPage extends AuthManagerSpecialPage {
                $targetLanguage = Language::factory( $lang );
                $attr['lang'] = $attr['hreflang'] = $targetLanguage->getHtmlCode();
 
-               return Linker::linkKnown(
+               return $this->getLinkRenderer()->makeKnownLink(
                        $this->getPageTitle(),
-                       htmlspecialchars( $text ),
+                       $text,
                        $attr,
                        $query
                );