Merge "skins: Remove 'usemsgcache' and deprecate getDynamicStylesheetQuery"
[lhc/web/wiklou.git] / includes / user / User.php
index 8ebd2d2..c9fe959 100644 (file)
@@ -27,6 +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;
@@ -986,13 +987,13 @@ class User implements IDBAccessObject, UserIdentity {
         * @return bool
         */
        public static function isValidUserName( $name ) {
-               global $wgContLang, $wgMaxNameChars;
+               global $wgMaxNameChars;
 
                if ( $name == ''
                        || self::isIP( $name )
                        || strpos( $name, '/' ) !== false
                        || strlen( $name ) > $wgMaxNameChars
-                       || $name != $wgContLang->ucfirst( $name )
+                       || $name != MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name )
                ) {
                        return false;
                }
@@ -1010,10 +1011,10 @@ class User implements IDBAccessObject, UserIdentity {
                // 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 ) ) {
@@ -1050,7 +1051,7 @@ class User implements IDBAccessObject, UserIdentity {
                // Certain names may be reserved for batch processes.
                foreach ( $reservedUsernames as $reserved ) {
                        if ( substr( $reserved, 0, 4 ) == 'msg:' ) {
-                               $reserved = wfMessage( substr( $reserved, 4 ) )->inContentLanguage()->text();
+                               $reserved = wfMessage( substr( $reserved, 4 ) )->inContentLanguage()->plain();
                        }
                        if ( $reserved == $name ) {
                                return false;
@@ -1228,8 +1229,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public static function getCanonicalName( $name, $validate = 'valid' ) {
                // Force usernames to capital
-               global $wgContLang;
-               $name = $wgContLang->ucfirst( $name );
+               $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name );
 
                # Reject names containing '#'; these will be cleaned up
                # with title normalisation, but then it's too late to
@@ -1761,24 +1761,29 @@ class User implements IDBAccessObject, UserIdentity {
         * @return array Array of String options
         */
        public static function getDefaultOptions() {
-               global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgContLang, $wgDefaultSkin;
+               global $wgNamespacesToBeSearchedDefault, $wgDefaultUserOptions, $wgDefaultSkin;
 
                static $defOpt = null;
                static $defOptLang = null;
 
-               if ( $defOpt !== null && $defOptLang === $wgContLang->getCode() ) {
-                       // $wgContLang does not change (and should not change) mid-request,
-                       // but the unit tests change it anyway, and expect this method to
-                       // return values relevant to the current $wgContLang.
+               $contLang = MediaWikiServices::getInstance()->getContentLanguage();
+               if ( $defOpt !== null && $defOptLang === $contLang->getCode() ) {
+                       // The content language does not change (and should not change) mid-request, but the
+                       // unit tests change it anyway, and expect this method to return values relevant to the
+                       // current content language.
                        return $defOpt;
                }
 
                $defOpt = $wgDefaultUserOptions;
                // Default language setting
-               $defOptLang = $wgContLang->getCode();
+               $defOptLang = $contLang->getCode();
                $defOpt['language'] = $defOptLang;
                foreach ( LanguageConverter::$languagesWithVariants as $langCode ) {
-                       $defOpt[$langCode == $wgContLang->getCode() ? 'variant' : "variant-$langCode"] = $langCode;
+                       if ( $langCode === $contLang->getCode() ) {
+                               $defOpt['variant'] = $langCode;
+                       } else {
+                               $defOpt["variant-$langCode"] = $langCode;
+                       }
                }
 
                // NOTE: don't use SearchEngineConfig::getSearchableNamespaces here,
@@ -2161,10 +2166,6 @@ class User implements IDBAccessObject, UserIdentity {
                        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
@@ -2196,6 +2197,11 @@ class User implements IDBAccessObject, UserIdentity {
                        }
                }
 
+               // 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;
@@ -4204,9 +4210,12 @@ class User implements IDBAccessObject, UserIdentity {
                                $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."
                                );
                        }
 
@@ -5073,10 +5082,10 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public static function getAllGroups() {
                global $wgGroupPermissions, $wgRevokePermissions;
-               return array_diff(
+               return array_values( array_diff(
                        array_merge( array_keys( $wgGroupPermissions ), array_keys( $wgRevokePermissions ) ),
                        self::getImplicitGroups()
-               );
+               ) );
        }
 
        /**
@@ -5453,8 +5462,6 @@ class User implements IDBAccessObject, UserIdentity {
         * @param array|null $data Rows for the current user out of the user_properties table
         */
        protected function loadOptions( $data = null ) {
-               global $wgContLang;
-
                $this->load();
 
                if ( $this->mOptionsLoaded ) {
@@ -5468,7 +5475,7 @@ class User implements IDBAccessObject, UserIdentity {
                        // There's no need to do it for logged-in users: they can set preferences,
                        // and handling of page content is done by $pageLang->getPreferredVariant() and such,
                        // so don't override user's choice (especially when the user chooses site default).
-                       $variant = $wgContLang->getDefaultVariant();
+                       $variant = MediaWikiServices::getInstance()->getContentLanguage()->getDefaultVariant();
                        $this->mOptions['variant'] = $variant;
                        $this->mOptions['language'] = $variant;
                        $this->mOptionsLoaded = true;