Merge "Title: Use directly Language::factory instead of wfGetLangObj"
[lhc/web/wiklou.git] / languages / Language.php
index 1320a57..1623c36 100644 (file)
@@ -154,9 +154,9 @@ class Language {
        /**
         * Unicode directional formatting characters, for embedBidi()
         */
-       static private $lre = "\xE2\x80\xAA"; // U+202A LEFT-TO-RIGHT EMBEDDING
-       static private $rle = "\xE2\x80\xAB"; // U+202B RIGHT-TO-LEFT EMBEDDING
-       static private $pdf = "\xE2\x80\xAC"; // U+202C POP DIRECTIONAL FORMATTING
+       static private $lre = "\u{202A}"; // U+202A LEFT-TO-RIGHT EMBEDDING
+       static private $rle = "\u{202B}"; // U+202B RIGHT-TO-LEFT EMBEDDING
+       static private $pdf = "\u{202C}"; // U+202C POP DIRECTIONAL FORMATTING
 
        /**
         * Directionality test regex for embedBidi(). Matches the first strong directionality codepoint:
@@ -188,9 +188,7 @@ class Language {
                }
 
                // get the language object to process
-               $langObj = isset( self::$mLangObjCache[$code] )
-                       ? self::$mLangObjCache[$code]
-                       : self::newFromCode( $code );
+               $langObj = self::$mLangObjCache[$code] ?? self::newFromCode( $code );
 
                // merge the language object in to get it up front in the cache
                self::$mLangObjCache = array_merge( [ $code => $langObj ], self::$mLangObjCache );
@@ -542,7 +540,7 @@ class Language {
         */
        public function getNsText( $index ) {
                $ns = $this->getNamespaces();
-               return isset( $ns[$index] ) ? $ns[$index] : false;
+               return $ns[$index] ?? false;
        }
 
        /**
@@ -577,7 +575,7 @@ class Language {
                $ns = $wgExtraGenderNamespaces +
                        (array)self::$dataCache->getItem( $this->mCode, 'namespaceGenderAliases' );
 
-               return isset( $ns[$index][$gender] ) ? $ns[$index][$gender] : $this->getNsText( $index );
+               return $ns[$index][$gender] ?? $this->getNsText( $index );
        }
 
        /**
@@ -613,7 +611,7 @@ class Language {
        function getLocalNsIndex( $text ) {
                $lctext = $this->lc( $text );
                $ids = $this->getNamespaceIds();
-               return isset( $ids[$lctext] ) ? $ids[$lctext] : false;
+               return $ids[$lctext] ?? false;
        }
 
        /**
@@ -700,7 +698,7 @@ class Language {
                        return $ns;
                }
                $ids = $this->getNamespaceIds();
-               return isset( $ids[$lctext] ) ? $ids[$lctext] : false;
+               return $ids[$lctext] ?? false;
        }
 
        /**
@@ -2917,33 +2915,33 @@ class Language {
                        if ( $code < 0xac00 || 0xd7a4 <= $code ) {
                                return $matches[1];
                        } elseif ( $code < 0xb098 ) {
-                               return "\xe3\x84\xb1";
+                               return "\u{3131}";
                        } elseif ( $code < 0xb2e4 ) {
-                               return "\xe3\x84\xb4";
+                               return "\u{3134}";
                        } elseif ( $code < 0xb77c ) {
-                               return "\xe3\x84\xb7";
+                               return "\u{3137}";
                        } elseif ( $code < 0xb9c8 ) {
-                               return "\xe3\x84\xb9";
+                               return "\u{3139}";
                        } elseif ( $code < 0xbc14 ) {
-                               return "\xe3\x85\x81";
+                               return "\u{3141}";
                        } elseif ( $code < 0xc0ac ) {
-                               return "\xe3\x85\x82";
+                               return "\u{3142}";
                        } elseif ( $code < 0xc544 ) {
-                               return "\xe3\x85\x85";
+                               return "\u{3145}";
                        } elseif ( $code < 0xc790 ) {
-                               return "\xe3\x85\x87";
+                               return "\u{3147}";
                        } elseif ( $code < 0xcc28 ) {
-                               return "\xe3\x85\x88";
+                               return "\u{3148}";
                        } elseif ( $code < 0xce74 ) {
-                               return "\xe3\x85\x8a";
+                               return "\u{314A}";
                        } elseif ( $code < 0xd0c0 ) {
-                               return "\xe3\x85\x8b";
+                               return "\u{314B}";
                        } elseif ( $code < 0xd30c ) {
-                               return "\xe3\x85\x8c";
+                               return "\u{314C}";
                        } elseif ( $code < 0xd558 ) {
-                               return "\xe3\x85\x8d";
+                               return "\u{314D}";
                        } else {
-                               return "\xe3\x85\x8e";
+                               return "\u{314E}";
                        }
                } else {
                        return '';
@@ -2954,6 +2952,7 @@ class Language {
         * @deprecated No-op since 1.28
         */
        function initEncoding() {
+               wfDeprecated( __METHOD__, '1.28' );
                // No-op.
        }
 
@@ -2963,6 +2962,7 @@ class Language {
         * @deprecated No-op since 1.28
         */
        function recodeForEdit( $s ) {
+               wfDeprecated( __METHOD__, '1.28' );
                return $s;
        }
 
@@ -2972,6 +2972,7 @@ class Language {
         * @deprecated No-op since 1.28
         */
        function recodeInput( $s ) {
+               wfDeprecated( __METHOD__, '1.28' );
                return $s;
        }
 
@@ -3090,8 +3091,8 @@ class Language {
         * @return string
         */
        function getDirMark( $opposite = false ) {
-               $lrm = "\xE2\x80\x8E"; # LEFT-TO-RIGHT MARK, commonly abbreviated LRM
-               $rlm = "\xE2\x80\x8F"; # RIGHT-TO-LEFT MARK, commonly abbreviated RLM
+               $lrm = "\u{200E}"; # LEFT-TO-RIGHT MARK, commonly abbreviated LRM
+               $rlm = "\u{200F}"; # RIGHT-TO-LEFT MARK, commonly abbreviated RLM
                if ( $opposite ) {
                        return $this->isRTL() ? $lrm : $rlm;
                }
@@ -3154,7 +3155,7 @@ class Language {
                        return;
                }
                $this->mMagicHookDone = true;
-               Hooks::run( 'LanguageGetMagic', [ &$this->mMagicExtensions, $this->getCode() ] );
+               Hooks::run( 'LanguageGetMagic', [ &$this->mMagicExtensions, $this->getCode() ], '1.16' );
        }
 
        /**
@@ -3210,7 +3211,7 @@ class Language {
                        $this->mExtendedSpecialPageAliases =
                                self::$dataCache->getItem( $this->mCode, 'specialPageAliases' );
                        Hooks::run( 'LanguageGetSpecialPageAliases',
-                               [ &$this->mExtendedSpecialPageAliases, $this->getCode() ] );
+                               [ &$this->mExtendedSpecialPageAliases, $this->getCode() ], '1.16' );
                }
 
                return $this->mExtendedSpecialPageAliases;
@@ -3556,7 +3557,7 @@ class Language {
         * @return string
         */
        private function truncateInternal(
-               $string, $length, $ellipsis = '...', $adjustLength = true, $measureLength, $getSubstring
+               $string, $length, $ellipsis, $adjustLength, $measureLength, $getSubstring
        ) {
                if ( !is_callable( $measureLength ) || !is_callable( $getSubstring ) ) {
                        throw new InvalidArgumentException( 'Invalid callback provided' );
@@ -3960,7 +3961,7 @@ class Language {
                if ( $gender === 'female' ) {
                        return $forms[1];
                }
-               return isset( $forms[2] ) ? $forms[2] : $forms[0];
+               return $forms[2] ?? $forms[0];
        }
 
        /**
@@ -4323,13 +4324,18 @@ class Language {
         * the "raw" tag (-{R| }-) to prevent conversion.
         *
         * This function is called "markNoConversion" for historical
-        * reasons.
+        * reasons *BUT DIFFERS SIGNIFICANTLY* from
+        * LanguageConverter::markNoConversion(), with which it is easily
+        * confused.
         *
         * @param string $text Text to be used for external link
         * @param bool $noParse Wrap it without confirming it's a real URL first
         * @return string The tagged text
+        * @deprecated since 1.32, use LanguageConverter::markNoConversion()
+        *  instead.
         */
        public function markNoConversion( $text, $noParse = false ) {
+               wfDeprecated( __METHOD__, '1.32' );
                // Excluding protocal-relative URLs may avoid many false positives.
                if ( $noParse || preg_match( '/^(?:' . wfUrlProtocolsWithoutProtRel() . ')/', $text ) ) {
                        return $this->mConverter->markNoConversion( $text );
@@ -4473,7 +4479,7 @@ class Language {
         * @throws MWException
         * @return string $prefix . $mangledCode . $suffix
         */
-       public static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
+       public static function getFileName( $prefix, $code, $suffix = '.php' ) {
                if ( !self::isValidBuiltInCode( $code ) ) {
                        throw new MWException( "Invalid language code \"$code\"" );
                }