Merge "Set Language in SpecialSearchTest.php"
[lhc/web/wiklou.git] / includes / specials / SpecialUserlogin.php
index 0da598b..fec1e3a 100644 (file)
@@ -372,6 +372,7 @@ class LoginForm extends SpecialPage {
                        return;
                }
 
+               /** @var User $u */
                $u = $status->getValue();
 
                // Wipe the initial password and mail a temporary one
@@ -485,7 +486,7 @@ class LoginForm extends SpecialPage {
         * @return Status
         */
        public function addNewAccountInternal() {
-               global $wgAuth, $wgMemc, $wgAccountCreationThrottle, $wgEmailConfirmToEdit;
+               global $wgAuth, $wgAccountCreationThrottle, $wgEmailConfirmToEdit;
 
                // If the user passes an invalid domain, something is fishy
                if ( !$wgAuth->validDomain( $this->mDomain ) ) {
@@ -565,8 +566,9 @@ class LoginForm extends SpecialPage {
                        return Status::newFatal( 'noname' );
                }
 
+               $cache = ObjectCache::getLocalClusterInstance();
                # Make sure the user does not exist already
-               $lock = $wgMemc->getScopedLock( wfGlobalCacheKey( 'account', md5( $this->mUsername ) ) );
+               $lock = $cache->getScopedLock( $cache->makeGlobalKey( 'account', md5( $this->mUsername ) ) );
                if ( !$lock ) {
                        return Status::newFatal( 'usernameinprogress' );
                } elseif ( $u->idForName( User::READ_LOCKING ) ) {
@@ -633,14 +635,14 @@ class LoginForm extends SpecialPage {
                } else {
                        if ( ( $wgAccountCreationThrottle && $currentUser->isPingLimitable() ) ) {
                                $key = wfMemcKey( 'acctcreate', 'ip', $ip );
-                               $value = $wgMemc->get( $key );
+                               $value = $cache->get( $key );
                                if ( !$value ) {
-                                       $wgMemc->set( $key, 0, 86400 );
+                                       $cache->set( $key, 0, $cache::TTL_DAY );
                                }
                                if ( $value >= $wgAccountCreationThrottle ) {
                                        return Status::newFatal( 'acct_creation_throttle_hit', $wgAccountCreationThrottle );
                                }
-                               $wgMemc->incr( $key );
+                               $cache->incr( $key );
                        }
                }
 
@@ -783,8 +785,10 @@ class LoginForm extends SpecialPage {
                // Give general extensions, such as a captcha, a chance to abort logins
                $abort = self::ABORTED;
                if ( !Hooks::run( 'AbortLogin', array( $u, $this->mPassword, &$abort, &$msg ) ) ) {
+                       if ( !in_array( $abort, array_keys( self::$statusCodes ), true ) ) {
+                               throw new Exception( 'Invalid status code returned from AbortLogin hook: ' . $abort );
+                       }
                        $this->mAbortLoginErrorMsg = $msg;
-
                        return $abort;
                }
 
@@ -867,7 +871,7 @@ class LoginForm extends SpecialPage {
         * @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;
+               global $wgPasswordAttemptThrottle, $wgRequest;
                $username = trim( $username ); // sanity
 
                $throttleCount = 0;
@@ -876,11 +880,12 @@ class LoginForm extends SpecialPage {
                        $count = $wgPasswordAttemptThrottle['count'];
                        $period = $wgPasswordAttemptThrottle['seconds'];
 
-                       $throttleCount = $wgMemc->get( $throttleKey );
+                       $cache = ObjectCache::getLocalClusterInstance();
+                       $throttleCount = $cache->get( $throttleKey );
                        if ( !$throttleCount ) {
-                               $wgMemc->add( $throttleKey, 1, $period ); // start counter
+                               $cache->add( $throttleKey, 1, $period ); // start counter
                        } elseif ( $throttleCount < $count ) {
-                               $wgMemc->incr( $throttleKey );
+                               $cache->incr( $throttleKey );
                        } elseif ( $throttleCount >= $count ) {
                                return true;
                        }
@@ -895,11 +900,11 @@ class LoginForm extends SpecialPage {
         * @return void
         */
        public static function clearLoginThrottle( $username ) {
-               global $wgMemc, $wgRequest;
+               global $wgRequest;
                $username = trim( $username ); // sanity
 
                $throttleKey = wfMemcKey( 'password-throttle', $wgRequest->getIP(), md5( $username ) );
-               $wgMemc->delete( $throttleKey );
+               ObjectCache::getLocalClusterInstance()->delete( $throttleKey );
        }
 
        /**
@@ -958,9 +963,9 @@ class LoginForm extends SpecialPage {
        }
 
        function processLogin() {
-               global $wgMemc, $wgLang, $wgSecureLogin, $wgPasswordAttemptThrottle,
-                       $wgInvalidPasswordReset;
+               global $wgLang, $wgSecureLogin, $wgPasswordAttemptThrottle, $wgInvalidPasswordReset;
 
+               $cache = ObjectCache::getLocalClusterInstance();
                $authRes = $this->authenticateUserData();
                switch ( $authRes ) {
                        case self::SUCCESS:
@@ -982,7 +987,7 @@ class LoginForm extends SpecialPage {
                                // Reset the throttle
                                $request = $this->getRequest();
                                $key = wfMemcKey( 'password-throttle', $request->getIP(), md5( $this->mUsername ) );
-                               $wgMemc->delete( $key );
+                               $cache->delete( $key );
 
                                if ( $this->hasSessionCookie() || $this->mSkipCookieCheck ) {
                                        /* Replace the language object to provide user interface in
@@ -1385,11 +1390,6 @@ class LoginForm extends SpecialPage {
                ) );
 
                if ( $this->mType == 'signup' ) {
-                       // XXX hack pending RL or JS parse() support for complex content messages
-                       // https://phabricator.wikimedia.org/T27349
-                       $out->addJsConfigVars( 'wgCreateacctImgcaptchaHelp',
-                               $this->msg( 'createacct-imgcaptcha-help' )->parse() );
-
                        // Additional styles and scripts for signup form
                        $out->addModules( array(
                                'mediawiki.special.userlogin.signup.js'