Use local context to get message instead of relying on global variables
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 8892d97..e801683 100644 (file)
@@ -72,8 +72,6 @@ class LoginForm extends SpecialPage {
 
        /**
         * Loader
-        *
-        * @param $request WebRequest object
         */
        function load() {
                global $wgAuth, $wgHiddenPrefs, $wgEnableEmail, $wgRedirectOnLogin;
@@ -127,7 +125,11 @@ class LoginForm extends SpecialPage {
                }
 
                if( !$wgAuth->validDomain( $this->mDomain ) ) {
-                       $this->mDomain = 'invaliddomain';
+                       if ( isset( $_SESSION['wsDomain'] ) ) {
+                               $this->mDomain = $_SESSION['wsDomain'];
+                       } else {
+                               $this->mDomain = 'invaliddomain';
+                       }
                }
                $wgAuth->setDomain( $this->mDomain );
 
@@ -475,6 +477,7 @@ class LoginForm extends SpecialPage {
                $this->load();
 
                if ( $this->mUsername == '' ) {
+                       wfRunHooks( 'LoginAuthenticateAudit', array( new User, $this->mPassword, self::NO_NAME ) );
                        return self::NO_NAME;
                }
 
@@ -486,20 +489,24 @@ class LoginForm extends SpecialPage {
                // If the user doesn't have a login token yet, set one.
                if ( !self::getLoginToken() ) {
                        self::setLoginToken();
+                       wfRunHooks( 'LoginAuthenticateAudit', array( new User, $this->mPassword, self::NEED_TOKEN ) );
                        return self::NEED_TOKEN;
                }
                // If the user didn't pass a login token, tell them we need one
                if ( !$this->mToken ) {
+                       wfRunHooks( 'LoginAuthenticateAudit', array( new User, $this->mPassword, self::NEED_TOKEN ) );
                        return self::NEED_TOKEN;
                }
 
                $throttleCount = self::incLoginThrottle( $this->mUsername );
                if ( $throttleCount === true ) {
+                       wfRunHooks( 'LoginAuthenticateAudit', array( new User, $this->mPassword, self::THROTTLED ) );
                        return self::THROTTLED;
                }
 
                // Validate the login token
                if ( $this->mToken !== self::getLoginToken() ) {
+                       wfRunHooks( 'LoginAuthenticateAudit', array( new User, $this->mPassword, self::WRONG_TOKEN ) );
                        return self::WRONG_TOKEN;
                }
 
@@ -519,7 +526,12 @@ class LoginForm extends SpecialPage {
                # TODO: Allow some magic here for invalid external names, e.g., let the
                # user choose a different wiki name.
                $u = User::newFromName( $this->mUsername );
-               if( !( $u instanceof User ) || !User::isUsableName( $u->getName() ) ) {
+               if( !( $u instanceof User ) ) {
+                       wfRunHooks( 'LoginAuthenticateAudit', array( new User, $this->mPassword, self::ILLEGAL ) );
+                       return self::ILLEGAL;
+               }
+               if( !User::isUsableName( $u->getName() ) ) {
+                       wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, self::ILLEGAL ) );
                        return self::ILLEGAL;
                }
 
@@ -527,6 +539,7 @@ class LoginForm extends SpecialPage {
                if ( 0 == $u->getID() ) {
                        $status = $this->attemptAutoCreate( $u );
                        if ( $status !== self::SUCCESS ) {
+                               wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, $status ) );
                                return $status;
                        } else {
                                $isAutoCreated = true;
@@ -547,6 +560,7 @@ class LoginForm extends SpecialPage {
                // Give general extensions, such as a captcha, a chance to abort logins
                $abort = self::ABORTED;
                if( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword, &$abort, &$this->mAbortLoginErrorMsg ) ) ) {
+                       wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, $abort ) );
                        return $abort;
                }
 
@@ -736,7 +750,7 @@ class LoginForm extends SpecialPage {
                                        $code = $request->getVal( 'uselang', $user->getOption( 'language' ) );
                                        $userLang = Language::factory( $code );
                                        $wgLang = $userLang;
-                                       $this->getContext()->setLang( $userLang );
+                                       $this->getContext()->setLanguage( $userLang );
                                        return $this->successfulLogin();
                                } else {
                                        return $this->cookieRedirectCheck( 'login' );
@@ -878,7 +892,11 @@ class LoginForm extends SpecialPage {
 
                wfRunHooks( 'UserLoginComplete', array( &$currentUser, &$injected_html ) );
 
-               //let any extensions change what message is shown
+               /**
+                * Let any extensions change what message is shown.
+                * @see https://www.mediawiki.org/wiki/Manual:Hooks/BeforeWelcomeCreation
+                * @since 1.18
+                */
                wfRunHooks( 'BeforeWelcomeCreation', array( &$welcome_creation_msg, &$injected_html ) );
 
                $this->displaySuccessfulLogin( $welcome_creation_msg, $injected_html );
@@ -1052,8 +1070,9 @@ class LoginForm extends SpecialPage {
                # Prepare language selection links as needed
                if( $wgLoginLanguageSelector ) {
                        $template->set( 'languages', $this->makeLanguageSelector() );
-                       if( $this->mLanguage )
+                       if( $this->mLanguage ) {
                                $template->set( 'uselang', $this->mLanguage );
+                       }
                }
 
                // Use loginend-https for HTTPS requests if it's not blank, loginend otherwise
@@ -1224,7 +1243,7 @@ class LoginForm extends SpecialPage {
                                }
                        }
                        return count( $links ) > 0 ? $this->msg( 'loginlanguagelabel' )->rawParams(
-                               $this->getLang()->pipeList( $links ) )->escaped() : '';
+                               $this->getLanguage()->pipeList( $links ) )->escaped() : '';
                } else {
                        return '';
                }