Merge "user: Allow "CAS update failed" exceptions to be normalised"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 20 Sep 2018 22:31:11 +0000 (22:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 20 Sep 2018 22:31:11 +0000 (22:31 +0000)
1  2 
includes/user/User.php

diff --combined includes/user/User.php
@@@ -27,6 -27,7 +27,7 @@@ use MediaWiki\Auth\AuthManager
  use MediaWiki\Auth\AuthenticationResponse;
  use MediaWiki\Auth\AuthenticationRequest;
  use MediaWiki\User\UserIdentity;
+ use MediaWiki\Logger\LoggerFactory;
  use Wikimedia\IPSet;
  use Wikimedia\ScopedCallback;
  use Wikimedia\Rdbms\Database;
@@@ -1010,10 -1011,10 +1011,10 @@@ class User implements IDBAccessObject, 
                // Should these be merged into the title char list?
                $unicodeBlacklist = '/[' .
                        '\x{0080}-\x{009f}' . # iso-8859-1 control chars
 -                      '\x{00a0}' .          # non-breaking space
 +                      '\x{00a0}' . # non-breaking space
                        '\x{2000}-\x{200f}' . # various whitespace
                        '\x{2028}-\x{202f}' . # breaks and control chars
 -                      '\x{3000}' .          # ideographic space
 +                      '\x{3000}' . # ideographic space
                        '\x{e000}-\x{f8ff}' . # private use
                        ']/u';
                if ( preg_match( $unicodeBlacklist, $name ) ) {
                        if ( isset( $limits['user'] ) ) {
                                $userLimit = $limits['user'];
                        }
 -                      // limits for newbie logged-in users
 -                      if ( $isNewbie && isset( $limits['newbie'] ) ) {
 -                              $keys[$cache->makeKey( 'limiter', $action, 'user', $id )] = $limits['newbie'];
 -                      }
                }
  
                // limits for anons and for newbie logged-in users
                        }
                }
  
 +              // limits for newbie logged-in users (override all the normal user limits)
 +              if ( $id !== 0 && $isNewbie && isset( $limits['newbie'] ) ) {
 +                      $userLimit = $limits['newbie'];
 +              }
 +
                // Set the user limit key
                if ( $userLimit !== false ) {
                        list( $max, $period ) = $userLimit;
                                $this->clearSharedCache( 'refresh' );
                                // User was changed in the meantime or loaded with stale data
                                $from = ( $this->queryFlagsUsed & self::READ_LATEST ) ? 'master' : 'replica';
-                               throw new MWException(
-                                       "CAS update failed on user_touched for user ID '{$this->mId}' (read from $from);" .
-                                       " the version of the user to be saved is older than the current version."
+                               LoggerFactory::getInstance( 'preferences' )->warning(
+                                       "CAS update failed on user_touched for user ID '{user_id}' ({db_flag} read)",
+                                       [ 'user_id' => $this->mId, 'db_flag' => $from ]
+                               );
+                               throw new MWException( "CAS update failed on user_touched. " .
+                                       "The version of the user to be saved is older than the current version."
                                );
                        }