Merge "If a user logs in while not on https, then the user should be sent back to...
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 3 Dec 2014 22:36:23 +0000 (22:36 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 3 Dec 2014 22:36:23 +0000 (22:36 +0000)
1  2 
includes/specials/SpecialUserlogin.php
includes/templates/Userlogin.php

@@@ -113,21 -113,6 +113,21 @@@ class LoginForm extends SpecialPage 
                $wgUseMediaWikiUIEverywhere = true;
        }
  
 +      /**
 +       * Returns an array of all valid error messages.
 +       *
 +       * @return array
 +       */
 +      public static function getValidErrorMessages() {
 +              static $messages = null;
 +              if ( !$messages ) {
 +                      $messages = self::$validErrorMessages;
 +                      wfRunHooks( 'LoginFormValidErrorMessages', array( &$messages ) );
 +              }
 +
 +              return $messages;
 +      }
 +
        /**
         * Loader
         */
                $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
                $this->mAction = $request->getVal( 'action' );
                $this->mRemember = $request->getCheck( 'wpRemember' );
-               $this->mFromHTTP = $request->getBool( 'fromhttp', false );
+               $this->mFromHTTP = $request->getBool( 'fromhttp', false )
+                       || $request->getBool( 'wpFromhttp', false );
                $this->mStickHTTPS = ( !$this->mFromHTTP && $request->getProtocol() === 'https' )
                        || $request->getBool( 'wpForceHttps', false );
                $this->mLanguage = $request->getText( 'uselang' );
  
                // Only show valid error or warning messages.
                if ( $entryError->exists()
 -                      && in_array( $entryError->getKey(), self::$validErrorMessages )
 +                      && in_array( $entryError->getKey(), self::getValidErrorMessages() )
                ) {
                        $this->mEntryErrorType = 'error';
                        $this->mEntryError = $entryError->rawParams( $loginreqlink )->escaped();
  
                } elseif ( $entryWarning->exists()
 -                      && in_array( $entryWarning->getKey(), self::$validErrorMessages )
 +                      && in_array( $entryWarning->getKey(), self::getValidErrorMessages() )
                ) {
                        $this->mEntryErrorType = 'warning';
                        $this->mEntryError = $entryWarning->rawParams( $loginreqlink )->escaped();
                        return Status::newFatal( 'sorbs_create_account_reason' );
                }
  
 -              // Normalize the name so that silly things don't cause "invalid username"
 -              // errors. User::newFromName does some rather strict checking, rejecting
 -              // e.g. leading/trailing/multiple spaces. But first we need to reject
 -              // usernames that would be treated as titles with a fragment part.
 -              if ( strpos( $this->mUsername, '#' ) !== false ) {
 -                      return Status::newFatal( 'noname' );
 -              }
 -              $title = Title::makeTitleSafe( NS_USER, $this->mUsername );
 -              if ( !is_object( $title ) ) {
 -                      return Status::newFatal( 'noname' );
 -              }
 -
                # Now create a dummy user ($u) and check if it is valid
 -              $u = User::newFromName( $title->getText(), 'creatable' );
 +              $u = User::newFromName( $this->mUsername, 'creatable' );
                if ( !is_object( $u ) ) {
                        return Status::newFatal( 'noname' );
                } elseif ( 0 != $u->idForName() ) {
                        $template->set( 'signupend', $this->msg( 'signupend' )->parse() );
                }
  
+               // If using HTTPS coming from HTTP, then the 'fromhttp' parameter must be preserved
+               if ( $usingHTTPS ) {
+                       $template->set( 'fromhttp', $this->mFromHTTP );
+               }
                // Give authentication and captcha plugins a chance to modify the form
                $wgAuth->modifyUITemplate( $template, $this->mType );
                if ( $this->mType == 'signup' ) {
@@@ -150,7 -150,6 +150,7 @@@ class UserloginTemplate extends BaseTem
                                <?php
                                $attrs = array(
                                        'id' => 'wpLoginAttempt',
 +                                      'name' => 'wpLoginAttempt',
                                        'tabindex' => '6',
                                );
                                $modifiers = array(
                        <?php if ( $this->haveData( 'uselang' ) ) { ?><input type="hidden" name="uselang" value="<?php $this->text( 'uselang' ); ?>" /><?php } ?>
                        <?php if ( $this->haveData( 'token' ) ) { ?><input type="hidden" name="wpLoginToken" value="<?php $this->text( 'token' ); ?>" /><?php } ?>
                        <?php if ( $this->data['cansecurelogin'] ) {?><input type="hidden" name="wpForceHttps" value="<?php $this->text( 'stickhttps' ); ?>" /><?php } ?>
+                       <?php if ( $this->data['cansecurelogin'] && $this->haveData( 'fromhttp' )) {?><input type="hidden" name="wpFromhttp" value="<?php $this->text( 'fromhttp' ); ?>" /><?php } ?>
                </form>
        </div>
  </div>