Cleanup: Fix yoda and indentation in SpecialUserlogin.php
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 7e66797..fd8ecb3 100644 (file)
@@ -286,6 +286,7 @@ class LoginForm extends SpecialPage {
 
        /**
         * @private
+        * @throws PermissionsError|ReadOnlyError
         * @return bool|User
         */
        function addNewAccountInternal() {
@@ -442,7 +443,13 @@ class LoginForm extends SpecialPage {
                }
 
                self::clearCreateaccountToken();
-               return $this->initUser( $u, false );
+
+               $status = $this->initUser( $u, false );
+               if ( !$status->isOK() ) {
+                       $this->mainLoginForm( $status->getHTML() );
+                       return false;
+               }
+               return $status->value;
        }
 
        /**
@@ -451,13 +458,16 @@ class LoginForm extends SpecialPage {
         *
         * @param $u User object.
         * @param $autocreate boolean -- true if this is an autocreation via auth plugin
-        * @return User object.
+        * @return Status object, with the User object in the value member on success
         * @private
         */
        function initUser( $u, $autocreate ) {
                global $wgAuth;
 
-               $u->addToDatabase();
+               $status = $u->addToDatabase();
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
 
                if ( $wgAuth->allowPasswordChange() ) {
                        $u->setPassword( $this->mPassword );
@@ -483,7 +493,7 @@ class LoginForm extends SpecialPage {
                # Update user count
                DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 0, 0, 0, 1 ) );
 
-               return $u;
+               return Status::newGood( $u );
        }
 
        /**
@@ -549,7 +559,7 @@ class LoginForm extends SpecialPage {
                }
 
                $isAutoCreated = false;
-               if ( 0 == $u->getID() ) {
+               if ( $u->getID() == 0 ) {
                        $status = $this->attemptAutoCreate( $u );
                        if ( $status !== self::SUCCESS ) {
                                return $status;
@@ -559,8 +569,9 @@ class LoginForm extends SpecialPage {
                } else {
                        global $wgExternalAuthType, $wgAutocreatePolicy;
                        if ( $wgExternalAuthType && $wgAutocreatePolicy != 'never'
-                       && is_object( $this->mExtUser )
-                       && $this->mExtUser->authenticate( $this->mPassword ) ) {
+                               && is_object( $this->mExtUser )
+                               && $this->mExtUser->authenticate( $this->mPassword )
+                       ) {
                                # The external user and local user have the same name and
                                # password, so we assume they're the same.
                                $this->mExtUser->linkToLocal( $u->getID() );
@@ -729,7 +740,14 @@ class LoginForm extends SpecialPage {
                }
 
                wfDebug( __METHOD__ . ": creating account\n" );
-               $this->initUser( $user, true );
+               $status = $this->initUser( $user, true );
+
+               if ( !$status->isOK() ) {
+                       $errors = $status->getErrorsByType( 'error' );
+                       $this->mAbortLoginErrorMsg = $errors[0]['message'];
+                       return self::ABORTED;
+               }
+
                return self::SUCCESS;
        }
 
@@ -838,7 +856,7 @@ class LoginForm extends SpecialPage {
         * @return Status object
         */
        function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
-               global $wgServer, $wgScript, $wgNewPasswordExpiry;
+               global $wgCanonicalServer, $wgScript, $wgNewPasswordExpiry;
 
                if ( $u->getEmail() == '' ) {
                        return Status::newFatal( 'noemail', $u->getName() );
@@ -855,7 +873,7 @@ class LoginForm extends SpecialPage {
                $u->setNewpassword( $np, $throttle );
                $u->saveSettings();
                $userLanguage = $u->getOption( 'language' );
-               $m = $this->msg( $emailText, $ip, $u->getName(), $np, '<' . $wgServer . $wgScript . '>',
+               $m = $this->msg( $emailText, $ip, $u->getName(), $np, '<' . $wgCanonicalServer . $wgScript . '>',
                        round( $wgNewPasswordExpiry / 86400 ) )->inLanguage( $userLanguage )->text();
                $result = $u->sendMail( $this->msg( $emailTitle )->inLanguage( $userLanguage )->text(), $m );
 
@@ -988,16 +1006,19 @@ class LoginForm extends SpecialPage {
                if ( $wgSecureLogin && !$this->mStickHTTPS ) {
                        $options = array( 'http' );
                        $proto = PROTO_HTTP;
-               } else {
+               } elseif( $wgSecureLogin ) {
                        $options = array( 'https' );
                        $proto = PROTO_HTTPS;
+               } else {
+                       $options = array();
+                       $proto = PROTO_RELATIVE;
                }
 
                if ( $type == 'successredirect' ) {
                        $redirectUrl = $returnToTitle->getFullURL( $returnToQuery, false, $proto );
                        $this->getOutput()->redirect( $redirectUrl );
                } else {
-                       $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, $options );
+                       $this->getOutput()->addReturnTo( $returnToTitle, $returnToQuery, null, $options );
                }
        }