Merge "resources: Strip '$' and 'mw' from file closures"
[lhc/web/wiklou.git] / includes / user / User.php
index ea8cd57..d6d4db2 100644 (file)
@@ -147,6 +147,9 @@ class User implements IDBAccessObject, UserIdentity {
                'editmyuserjs',
                'editmywatchlist',
                'editsemiprotected',
+               'editsitecss',
+               'editsitejson',
+               'editsitejs',
                'editusercss',
                'edituserjson',
                'edituserjs',
@@ -983,13 +986,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;
                }
@@ -1007,10 +1010,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 ) ) {
@@ -1225,8 +1228,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
@@ -1758,24 +1760,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,
@@ -5070,10 +5077,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()
-               );
+               ) );
        }
 
        /**
@@ -5450,8 +5457,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 ) {
@@ -5465,7 +5470,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;
@@ -5507,12 +5512,6 @@ class User implements IDBAccessObject, UserIdentity {
                                }
                        }
 
-                       // Convert the email blacklist from a new line delimited string
-                       // to an array of ids.
-                       if ( isset( $data['email-blacklist'] ) && $data['email-blacklist'] ) {
-                               $data['email-blacklist'] = array_map( 'intval', explode( "\n", $data['email-blacklist'] ) );
-                       }
-
                        foreach ( $data as $property => $value ) {
                                $this->mOptionOverrides[$property] = $value;
                                $this->mOptions[$property] = $value;
@@ -5540,26 +5539,6 @@ class User implements IDBAccessObject, UserIdentity {
                // Not using getOptions(), to keep hidden preferences in database
                $saveOptions = $this->mOptions;
 
-               // Convert usernames to ids.
-               if ( isset( $this->mOptions['email-blacklist'] ) ) {
-                       if ( $this->mOptions['email-blacklist'] ) {
-                               $value = $this->mOptions['email-blacklist'];
-                               // Email Blacklist may be an array of ids or a string of new line
-                               // delimnated user names.
-                               if ( is_array( $value ) ) {
-                                       $ids = array_filter( $value, 'is_numeric' );
-                               } else {
-                                       $lookup = CentralIdLookup::factory();
-                                       $ids = $lookup->centralIdsFromNames( explode( "\n", $value ), $this );
-                               }
-                               $this->mOptions['email-blacklist'] = $ids;
-                               $saveOptions['email-blacklist'] = implode( "\n", $this->mOptions['email-blacklist'] );
-                       } else {
-                               // If the blacklist is empty, set it to null rather than an empty string.
-                               $this->mOptions['email-blacklist'] = null;
-                       }
-               }
-
                // Allow hooks to abort, for instance to save to a global profile.
                // Reset options to default state before saving.
                if ( !Hooks::run( 'UserSaveOptions', [ $this, &$saveOptions ] ) ) {