Merge "Tests: Add missing expect numbers in QUnit tests."
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 3a73ebd..27701d4 100644 (file)
@@ -95,9 +95,9 @@ class LoginForm extends SpecialPage {
                $this->mReason = $request->getText( 'wpReason' );
                $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
                $this->mPosted = $request->wasPosted();
-               $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' );
                $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' )
                                                                        && $wgEnableEmail;
+               $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' ) && !$this->mCreateaccountMail;
                $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
                $this->mAction = $request->getVal( 'action' );
                $this->mRemember = $request->getCheck( 'wpRemember' );
@@ -212,7 +212,7 @@ class LoginForm extends SpecialPage {
                $result = $this->mailPasswordInternal( $u, false, 'createaccount-title', 'createaccount-text' );
 
                wfRunHooks( 'AddNewAccount', array( $u, true ) );
-               $u->addNewUserLogEntry( true, $this->mReason );
+               $u->addNewUserLogEntry( 'byemail', $this->mReason );
 
                $out = $this->getOutput();
                $out->setPageTitle( $this->msg( 'accmailtitle' ) );
@@ -274,7 +274,7 @@ class LoginForm extends SpecialPage {
                        // wrong.
                        $this->getContext()->setUser( $u );
                        wfRunHooks( 'AddNewAccount', array( $u, false ) );
-                       $u->addNewUserLogEntry();
+                       $u->addNewUserLogEntry( 'create' );
                        if( $this->hasSessionCookie() ) {
                                $this->successfulCreation();
                        } else {
@@ -286,7 +286,7 @@ class LoginForm extends SpecialPage {
                        $out->addWikiMsg( 'accountcreatedtext', $u->getName() );
                        $out->addReturnTo( $this->getTitle() );
                        wfRunHooks( 'AddNewAccount', array( $u, false ) );
-                       $u->addNewUserLogEntry( false, $this->mReason );
+                       $u->addNewUserLogEntry( 'create2', $this->mReason );
                }
                return true;
        }
@@ -314,8 +314,10 @@ class LoginForm extends SpecialPage {
                if( 'local' != $this->mDomain && $this->mDomain != '' ) {
                        if(
                                !$wgAuth->canCreateAccounts() &&
-                               ( !$wgAuth->userExists( $this->mUsername ||
-                                 !$wgAuth->authenticate( $this->mUsername, $this->mPassword ) ) )
+                               (
+                                       !$wgAuth->userExists( $this->mUsername ) ||
+                                       !$wgAuth->authenticate( $this->mUsername, $this->mPassword )
+                               )
                        ) {
                                return Status::newFatal( 'wrongpassword' );
                        }
@@ -371,32 +373,34 @@ class LoginForm extends SpecialPage {
                        return Status::newFatal( 'noname' );
                } elseif ( 0 != $u->idForName() ) {
                        return Status::newFatal( 'userexists' );
-               } elseif ( 0 != strcmp( $this->mPassword, $this->mRetype ) ) {
-                       return Status::newFatal( 'badretype' );
                }
 
-               # check for minimal password length
-               $valid = $u->getPasswordValidity( $this->mPassword );
-               if ( $valid !== true ) {
-                       if ( !$this->mCreateaccountMail ) {
+               if ( $this->mCreateaccountMail ) {
+                       # do not force a password for account creation by email
+                       # set invalid password, it will be replaced later by a random generated password
+                       $this->mPassword = null;
+               } else {
+                       if ( $this->mPassword !== $this->mRetype ) {
+                               return Status::newFatal( 'badretype' );
+                       }
+
+                       # check for minimal password length
+                       $valid = $u->getPasswordValidity( $this->mPassword );
+                       if ( $valid !== true ) {
                                if ( !is_array( $valid ) ) {
                                        $valid = array( $valid, $wgMinimalPasswordLength );
                                }
                                return call_user_func_array( 'Status::newFatal', $valid );
-                       } else {
-                               # do not force a password for account creation by email
-                               # set invalid password, it will be replaced later by a random generated password
-                               $this->mPassword = null;
                        }
                }
 
                # if you need a confirmed email address to edit, then obviously you
                # need an email address.
-               if ( $wgEmailConfirmToEdit && empty( $this->mEmail ) ) {
+               if ( $wgEmailConfirmToEdit && strval( $this->mEmail ) === '' ) {
                        return Status::newFatal( 'noemailtitle' );
                }
 
-               if( !empty( $this->mEmail ) && !Sanitizer::validateEmail( $this->mEmail ) ) {
+               if ( strval( $this->mEmail ) !== '' && !Sanitizer::validateEmail( $this->mEmail ) ) {
                        return Status::newFatal( 'invalidemailaddress' );
                }
 
@@ -828,7 +832,7 @@ class LoginForm extends SpecialPage {
        }
 
        function resetLoginForm( $error ) {
-               $this->getOutput()->addHTML( Xml::element('p', array( 'class' => 'error' ), $error ) );
+               $this->getOutput()->addHTML( Xml::element( 'p', array( 'class' => 'error' ), $error ) );
                $reset = new SpecialChangePassword();
                $reset->setContext( $this->getContext() );
                $reset->execute( null );
@@ -1011,7 +1015,7 @@ class LoginForm extends SpecialPage {
                global $wgEnableEmail, $wgEnableUserEmail;
                global $wgHiddenPrefs, $wgLoginLanguageSelector;
                global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration;
-               global $wgSecureLogin, $wgPasswordResetRoutes;
+               global $wgSecureLogin, $wgSecureLoginDefaultHTTPS, $wgPasswordResetRoutes;
 
                $titleObj = $this->getTitle();
                $user = $this->getUser();
@@ -1031,7 +1035,8 @@ class LoginForm extends SpecialPage {
                        }
                }
 
-               if ( $this->mUsername == '' ) {
+               // Pre-fill username (if not creating an account, bug 44775).
+               if ( $this->mUsername == '' && $this->mType != 'signup' ) {
                        if ( $user->isLoggedIn() ) {
                                $this->mUsername = $user->getName();
                        } else {
@@ -1044,6 +1049,7 @@ class LoginForm extends SpecialPage {
                        $q = 'action=submitlogin&type=signup';
                        $linkq = 'type=login';
                        $linkmsg = 'gotaccount';
+                       $this->getOutput()->addModules( 'mediawiki.special.userlogin.signup' );
                } else {
                        $template = new UserloginTemplate();
                        $q = 'action=submitlogin&type=login';
@@ -1075,6 +1081,11 @@ class LoginForm extends SpecialPage {
                        $template->set( 'link', '' );
                }
 
+               // Decide if we default stickHTTPS on
+               if ( $wgSecureLoginDefaultHTTPS && $this->mAction != 'submitlogin' && !$this->mLoginattempt ) {
+                       $this->mStickHTTPS = true;
+               }
+
                $resetLink = $this->mType == 'signup'
                        ? null
                        : is_array( $wgPasswordResetRoutes ) && in_array( true, array_values( $wgPasswordResetRoutes ) );
@@ -1083,6 +1094,7 @@ class LoginForm extends SpecialPage {
                $template->set( 'name', $this->mUsername );
                $template->set( 'password', $this->mPassword );
                $template->set( 'retype', $this->mRetype );
+               $template->set( 'createemailset', $this->mCreateaccountMail );
                $template->set( 'email', $this->mEmail );
                $template->set( 'realname', $this->mRealName );
                $template->set( 'domain', $this->mDomain );