Merge "Add version comments for 1.24 to all updaters"
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 1c9fed7..4006e49 100644 (file)
@@ -27,7 +27,6 @@
  * @ingroup SpecialPage
  */
 class LoginForm extends SpecialPage {
-
        const SUCCESS = 0;
        const NO_NAME = 1;
        const ILLEGAL = 2;
@@ -43,26 +42,38 @@ class LoginForm extends SpecialPage {
        const NEED_TOKEN = 12;
        const WRONG_TOKEN = 13;
 
-       var $mUsername, $mPassword, $mRetype, $mReturnTo, $mCookieCheck, $mPosted;
-       var $mAction, $mCreateaccount, $mCreateaccountMail;
-       var $mLoginattempt, $mRemember, $mEmail, $mDomain, $mLanguage;
-       var $mSkipCookieCheck, $mReturnToQuery, $mToken, $mStickHTTPS;
-       var $mType, $mReason, $mRealName;
-       var $mAbortLoginErrorMsg = null;
+       public $mAbortLoginErrorMsg = null;
+
+       protected $mUsername;
+       protected $mPassword;
+       protected $mRetype;
+       protected $mReturnTo;
+       protected $mCookieCheck;
+       protected $mPosted;
+       protected $mAction;
+       protected $mCreateaccount;
+       protected $mCreateaccountMail;
+       protected $mLoginattempt;
+       protected $mRemember;
+       protected $mEmail;
+       protected $mDomain;
+       protected $mLanguage;
+       protected $mSkipCookieCheck;
+       protected $mReturnToQuery;
+       protected $mToken;
+       protected $mStickHTTPS;
+       protected $mType;
+       protected $mReason;
+       protected $mRealName;
+
        private $mTempPasswordUsed;
        private $mLoaded = false;
        private $mSecureLoginUrl;
 
-       /**
-        * @ var WebRequest
-        */
+       /** @var WebRequest */
        private $mOverrideRequest = null;
 
-       /**
-        * Effective request; set at the beginning of load
-        *
-        * @var WebRequest $mRequest
-        */
+       /** @var WebRequest Effective request; set at the beginning of load */
        private $mRequest = null;
 
        /**
@@ -101,16 +112,19 @@ class LoginForm extends SpecialPage {
                $this->mCookieCheck = $request->getVal( 'wpCookieCheck' );
                $this->mPosted = $request->wasPosted();
                $this->mCreateaccountMail = $request->getCheck( 'wpCreateaccountMail' )
-                                                                       && $wgEnableEmail;
+                       && $wgEnableEmail;
                $this->mCreateaccount = $request->getCheck( 'wpCreateaccount' ) && !$this->mCreateaccountMail;
                $this->mLoginattempt = $request->getCheck( 'wpLoginattempt' );
                $this->mAction = $request->getVal( 'action' );
                $this->mRemember = $request->getCheck( 'wpRemember' );
                $this->mFromHTTP = $request->getBool( 'fromhttp', false );
-               $this->mStickHTTPS = ( !$this->mFromHTTP && $request->getProtocol() === 'https' ) || $request->getBool( 'wpForceHttps', false );
+               $this->mStickHTTPS = ( !$this->mFromHTTP && $request->getProtocol() === 'https' )
+                       || $request->getBool( 'wpForceHttps', false );
                $this->mLanguage = $request->getText( 'uselang' );
                $this->mSkipCookieCheck = $request->getCheck( 'wpSkipCookieCheck' );
-               $this->mToken = ( $this->mType == 'signup' ) ? $request->getVal( 'wpCreateaccountToken' ) : $request->getVal( 'wpLoginToken' );
+               $this->mToken = $this->mType == 'signup'
+                       ? $request->getVal( 'wpCreateaccountToken' )
+                       : $request->getVal( 'wpLoginToken' );
                $this->mReturnTo = $request->getVal( 'returnto', '' );
                $this->mReturnToQuery = $request->getVal( 'returntoquery', '' );
 
@@ -134,9 +148,10 @@ class LoginForm extends SpecialPage {
                # 2. Do not return to PasswordReset after a successful password change
                #    but goto Wiki start page (Main_Page) instead ( bug 33997 )
                $returnToTitle = Title::newFromText( $this->mReturnTo );
-               if ( is_object( $returnToTitle ) && (
-                       $returnToTitle->isSpecial( 'Userlogout' )
-                       || $returnToTitle->isSpecial( 'PasswordReset' ) ) ) {
+               if ( is_object( $returnToTitle )
+                       && ( $returnToTitle->isSpecial( 'Userlogout' )
+                               || $returnToTitle->isSpecial( 'PasswordReset' ) )
+               ) {
                        $this->mReturnTo = '';
                        $this->mReturnToQuery = '';
                }
@@ -151,7 +166,7 @@ class LoginForm extends SpecialPage {
        }
 
        /*
-        * @param $subPage string|null
+        * @param string|null $subPage
         */
        public function execute( $subPage ) {
                if ( session_id() == '' ) {
@@ -183,6 +198,7 @@ class LoginForm extends SpecialPage {
                                $this->getOutput()->redirect( $url );
                                // Since we only do this redir to change proto, always vary
                                $this->getOutput()->addVaryHeader( 'X-Forwarded-Proto' );
+
                                return;
                        } else {
                                // A wiki without HTTPS login support should set $wgServer to
@@ -196,16 +212,20 @@ class LoginForm extends SpecialPage {
 
                if ( !is_null( $this->mCookieCheck ) ) {
                        $this->onCookieRedirectCheck( $this->mCookieCheck );
+
                        return;
                } elseif ( $this->mPosted ) {
                        if ( $this->mCreateaccount ) {
                                $this->addNewAccount();
+
                                return;
                        } elseif ( $this->mCreateaccountMail ) {
                                $this->addNewAccountMailPassword();
+
                                return;
                        } elseif ( ( 'submitlogin' == $this->mAction ) || $this->mLoginattempt ) {
                                $this->processLogin();
+
                                return;
                        }
                }
@@ -218,6 +238,7 @@ class LoginForm extends SpecialPage {
        function addNewAccountMailPassword() {
                if ( $this->mEmail == '' ) {
                        $this->mainLoginForm( $this->msg( 'noemailcreate' )->escaped() );
+
                        return;
                }
 
@@ -225,6 +246,7 @@ class LoginForm extends SpecialPage {
                if ( !$status->isGood() ) {
                        $error = $status->getMessage();
                        $this->mainLoginForm( $error->toString() );
+
                        return;
                }
 
@@ -261,6 +283,7 @@ class LoginForm extends SpecialPage {
                if ( !$status->isGood() ) {
                        $error = $status->getMessage();
                        $this->mainLoginForm( $error->toString() );
+
                        return false;
                }
 
@@ -324,6 +347,7 @@ class LoginForm extends SpecialPage {
                        wfRunHooks( 'AddNewAccount', array( $u, false ) );
                        $u->addNewUserLogEntry( 'create2', $this->mReason );
                }
+
                return true;
        }
 
@@ -366,6 +390,7 @@ class LoginForm extends SpecialPage {
                # Request forgery checks.
                if ( !self::getCreateaccountToken() ) {
                        self::setCreateaccountToken();
+
                        return Status::newFatal( 'nocookiesfornew' );
                }
 
@@ -387,14 +412,20 @@ class LoginForm extends SpecialPage {
                } elseif ( $creationBlock instanceof Block ) {
                        // Throws an ErrorPageError.
                        $this->userBlockedMessage( $creationBlock );
+
                        // This should never be reached.
                        return false;
                }
 
                # Include checks that will include GlobalBlocking (Bug 38333)
-               $permErrors = $this->getPageTitle()->getUserPermissionsErrors( 'createaccount', $currentUser, true );
+               $permErrors = $this->getPageTitle()->getUserPermissionsErrors(
+                       'createaccount',
+                       $currentUser,
+                       true
+               );
+
                if ( count( $permErrors ) ) {
-                               throw new PermissionsError( 'createaccount', $permErrors );
+                       throw new PermissionsError( 'createaccount', $permErrors );
                }
 
                $ip = $this->getRequest()->getIP();
@@ -402,8 +433,9 @@ class LoginForm extends SpecialPage {
                        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.
+               // 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.
                $title = Title::makeTitleSafe( NS_USER, $this->mUsername );
                if ( !is_object( $title ) ) {
                        return Status::newFatal( 'noname' );
@@ -432,6 +464,7 @@ class LoginForm extends SpecialPage {
                                if ( !is_array( $valid ) ) {
                                        $valid = array( $valid, $wgMinimalPasswordLength );
                                }
+
                                return call_user_func_array( 'Status::newFatal', $valid );
                        }
                }
@@ -463,6 +496,7 @@ class LoginForm extends SpecialPage {
                                // To return a different error code, return a Status object.
                                $abortError = new Message( 'createaccount-hook-aborted', array( $abortError ) );
                                $abortError->text();
+
                                return Status::newFatal( $abortError );
                        } else {
                                // For MediaWiki 1.23+ and updated hooks, return the Status object
@@ -473,7 +507,8 @@ class LoginForm extends SpecialPage {
 
                // Hook point to check for exempt from account creation throttle
                if ( !wfRunHooks( 'ExemptFromAccountCreationThrottle', array( $ip ) ) ) {
-                       wfDebug( "LoginForm::exemptFromAccountCreationThrottle: a hook allowed account creation w/o throttle\n" );
+                       wfDebug( "LoginForm::exemptFromAccountCreationThrottle: a hook " .
+                               "allowed account creation w/o throttle\n" );
                } else {
                        if ( ( $wgAccountCreationThrottle && $currentUser->isPingLimitable() ) ) {
                                $key = wfMemcKey( 'acctcreate', 'ip', $ip );
@@ -493,6 +528,7 @@ class LoginForm extends SpecialPage {
                }
 
                self::clearCreateaccountToken();
+
                return $this->initUser( $u, false );
        }
 
@@ -500,9 +536,9 @@ class LoginForm extends SpecialPage {
         * Actually add a user to the database.
         * Give it a User object that has been initialised with a name.
         *
-        * @param $u User object.
-        * @param $autocreate boolean -- true if this is an autocreation via auth plugin
-        * @return Status object, with the User object in the value member on success
+        * @param User $u
+        * @param bool $autocreate True if this is an autocreation via auth plugin
+        * @return Status Status object, with the User object in the value member on success
         * @private
         */
        function initUser( $u, $autocreate ) {
@@ -523,7 +559,6 @@ class LoginForm extends SpecialPage {
 
                $wgAuth->initUser( $u, $autocreate );
 
-               $u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
                $u->saveSettings();
 
                // Update user count
@@ -560,6 +595,7 @@ class LoginForm extends SpecialPage {
                // If the user doesn't have a login token yet, set one.
                if ( !self::getLoginToken() ) {
                        self::setLoginToken();
+
                        return self::NEED_TOKEN;
                }
                // If the user didn't pass a login token, tell them we need one
@@ -585,6 +621,7 @@ class LoginForm extends SpecialPage {
                // will effectively be using stale data.
                if ( $this->getUser()->getName() === $this->mUsername ) {
                        wfDebug( __METHOD__ . ": already logged in as {$this->mUsername}\n" );
+
                        return self::SUCCESS;
                }
 
@@ -610,6 +647,7 @@ class LoginForm extends SpecialPage {
                $msg = null;
                if ( !wfRunHooks( 'AbortLogin', array( $u, $this->mPassword, &$abort, &$msg ) ) ) {
                        $this->mAbortLoginErrorMsg = $msg;
+
                        return $abort;
                }
 
@@ -674,6 +712,7 @@ class LoginForm extends SpecialPage {
                        $retval = self::SUCCESS;
                }
                wfRunHooks( 'LoginAuthenticateAudit', array( $u, $this->mPassword, $retval ) );
+
                return $retval;
        }
 
@@ -681,7 +720,7 @@ class LoginForm extends SpecialPage {
         * Increment the login attempt throttle hit count for the (username,current IP)
         * tuple unless the throttle was already reached.
         * @param string $username The user name
-        * @return Bool|Integer The integer hit count or True if it is already at the limit
+        * @return bool|int The integer hit count or True if it is already at the limit
         */
        public static function incLoginThrottle( $username ) {
                global $wgPasswordAttemptThrottle, $wgMemc, $wgRequest;
@@ -723,26 +762,32 @@ class LoginForm extends SpecialPage {
         * Attempt to automatically create a user on login. Only succeeds if there
         * is an external authentication method which allows it.
         *
-        * @param $user User
+        * @param User $user
         *
-        * @return integer Status code
+        * @return int Status code
         */
        function attemptAutoCreate( $user ) {
                global $wgAuth;
 
                if ( $this->getUser()->isBlockedFromCreateAccount() ) {
                        wfDebug( __METHOD__ . ": user is blocked from account creation\n" );
+
                        return self::CREATE_BLOCKED;
                }
+
                if ( !$wgAuth->autoCreate() ) {
                        return self::NOT_EXISTS;
                }
+
                if ( !$wgAuth->userExists( $user->getName() ) ) {
                        wfDebug( __METHOD__ . ": user does not exist\n" );
+
                        return self::NOT_EXISTS;
                }
+
                if ( !$wgAuth->authenticate( $user->getName(), $this->mPassword ) ) {
                        wfDebug( __METHOD__ . ": \$wgAuth->authenticate() returned false, aborting\n" );
+
                        return self::WRONG_PLUGIN_PASS;
                }
 
@@ -751,6 +796,7 @@ class LoginForm extends SpecialPage {
                        // Hook point to add extra creation throttles and blocks
                        wfDebug( "LoginForm::attemptAutoCreate: a hook blocked creation: $abortError\n" );
                        $this->mAbortLoginErrorMsg = $abortError;
+
                        return self::ABORTED;
                }
 
@@ -760,6 +806,7 @@ class LoginForm extends SpecialPage {
                if ( !$status->isOK() ) {
                        $errors = $status->getErrorsByType( 'error' );
                        $this->mAbortLoginErrorMsg = $errors[0]['message'];
+
                        return self::ABORTED;
                }
 
@@ -774,21 +821,16 @@ class LoginForm extends SpecialPage {
                        case self::SUCCESS:
                                # We've verified now, update the real record
                                $user = $this->getUser();
-                               if ( (bool)$this->mRemember != $user->getBoolOption( 'rememberpassword' ) ) {
-                                       $user->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
-                                       $user->saveSettings();
-                               } else {
-                                       $user->invalidateCache();
-                               }
+                               $user->invalidateCache();
 
                                if ( $user->requiresHTTPS() ) {
                                        $this->mStickHTTPS = true;
                                }
 
                                if ( $wgSecureLogin && !$this->mStickHTTPS ) {
-                                       $user->setCookies( null, false );
+                                       $user->setCookies( $this->mRequest, false, $this->mRemember );
                                } else {
-                                       $user->setCookies();
+                                       $user->setCookies( $this->mRequest, null, $this->mRemember );
                                }
                                self::clearLoginToken();
 
@@ -870,8 +912,8 @@ class LoginForm extends SpecialPage {
                        case self::THROTTLED:
                                $error = $this->mAbortLoginErrorMsg ?: 'login-throttled';
                                $this->mainLoginForm( $this->msg( $error )
-                               ->params ( $this->getLanguage()->formatDuration( $wgPasswordAttemptThrottle['seconds'] ) )
-                               ->text()
+                                       ->params( $this->getLanguage()->formatDuration( $wgPasswordAttemptThrottle['seconds'] ) )
+                                       ->text()
                                );
                                break;
                        case self::USER_BLOCKED:
@@ -906,13 +948,15 @@ class LoginForm extends SpecialPage {
        }
 
        /**
-        * @param $u User object
-        * @param $throttle Boolean
-        * @param string $emailTitle message name of email title
-        * @param string $emailText message name of email text
-        * @return Status object
+        * @param User $u
+        * @param bool $throttle
+        * @param string $emailTitle Message name of email title
+        * @param string $emailText Message name of email text
+        * @return Status
         */
-       function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle', $emailText = 'passwordremindertext' ) {
+       function mailPasswordInternal( $u, $throttle = true, $emailTitle = 'passwordremindertitle',
+               $emailText = 'passwordremindertext'
+       ) {
                global $wgNewPasswordExpiry;
 
                if ( $u->getEmail() == '' ) {
@@ -993,9 +1037,9 @@ class LoginForm extends SpecialPage {
        /**
         * Display an "successful action" page.
         *
-        * @param string|Message $title page's title
-        * @param $msgname string
-        * @param $injected_html string
+        * @param string|Message $title Page's title
+        * @param string $msgname
+        * @param string $injected_html
         */
        private function displaySuccessfulAction( $title, $msgname, $injected_html ) {
                $out = $this->getOutput();
@@ -1014,7 +1058,7 @@ class LoginForm extends SpecialPage {
         * there is a block on them or their IP which prevents account creation.  Note that
         * User::isBlockedFromCreateAccount(), which gets this block, ignores the 'hardblock'
         * setting on blocks (bug 13611).
-        * @param $block Block the block causing this error
+        * @param Block $block The block causing this error
         * @throws ErrorPageError
         */
        function userBlockedMessage( Block $block ) {
@@ -1050,7 +1094,7 @@ class LoginForm extends SpecialPage {
         * Extensions can use this to reuse the "return to" logic after
         * inject steps (such as redirection) into the login process.
         *
-        * @param $type string, one of the following:
+        * @param string $type One of the following:
         *    - error: display a return to link ignoring $wgRedirectOnLogin
         *    - success: display a return to link using $wgRedirectOnLogin if needed
         *    - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
@@ -1071,7 +1115,7 @@ class LoginForm extends SpecialPage {
        /**
         * Add a "return to" link or redirect to it.
         *
-        * @param $type string, one of the following:
+        * @param string $type One of the following:
         *    - error: display a return to link ignoring $wgRedirectOnLogin
         *    - success: display a return to link using $wgRedirectOnLogin if needed
         *    - successredirect: send an HTTP redirect using $wgRedirectOnLogin if needed
@@ -1133,6 +1177,7 @@ class LoginForm extends SpecialPage {
                                throw new PermissionsError( 'createaccount', $permErrors );
                        } elseif ( $user->isBlockedFromCreateAccount() ) {
                                $this->userBlockedMessage( $user->isBlockedFromCreateAccount() );
+
                                return;
                        } elseif ( wfReadOnly() ) {
                                throw new ReadOnlyError;
@@ -1240,7 +1285,7 @@ class LoginForm extends SpecialPage {
                $template->set( 'resetlink', $resetLink );
                $template->set( 'canremember', ( $wgCookieExpiration > 0 ) );
                $template->set( 'usereason', $user->isLoggedIn() );
-               $template->set( 'remember', $user->getOption( 'rememberpassword' ) || $this->mRemember );
+               $template->set( 'remember', $this->mRemember );
                $template->set( 'cansecurelogin', ( $wgSecureLogin === true ) );
                $template->set( 'stickhttps', (int)$this->mStickHTTPS );
                $template->set( 'loggedin', $user->isLoggedIn() );
@@ -1299,7 +1344,7 @@ class LoginForm extends SpecialPage {
         * Whether the login/create account form should display a link to the
         * other form (in addition to whatever the skin provides).
         *
-        * @param $user User
+        * @param User $user
         * @return bool
         */
        private function showCreateOrLoginLink( &$user ) {
@@ -1324,15 +1369,17 @@ class LoginForm extends SpecialPage {
         */
        function hasSessionCookie() {
                global $wgDisableCookieCheck;
+
                return $wgDisableCookieCheck ? true : $this->getRequest()->checkSessionCookie();
        }
 
        /**
         * Get the login token from the current session
-        * @return Mixed
+        * @return mixed
         */
        public static function getLoginToken() {
                global $wgRequest;
+
                return $wgRequest->getSessionData( 'wsLoginToken' );
        }
 
@@ -1356,10 +1403,11 @@ class LoginForm extends SpecialPage {
 
        /**
         * Get the createaccount token from the current session
-        * @return Mixed
+        * @return mixed
         */
        public static function getCreateaccountToken() {
                global $wgRequest;
+
                return $wgRequest->getSessionData( 'wsCreateaccountToken' );
        }
 
@@ -1442,6 +1490,7 @@ class LoginForm extends SpecialPage {
                                        $links[] = $this->makeLanguageSelectorLink( $parts[0], trim( $parts[1] ) );
                                }
                        }
+
                        return count( $links ) > 0 ? $this->msg( 'loginlanguagelabel' )->rawParams(
                                $this->getLanguage()->pipeList( $links ) )->escaped() : '';
                } else {