X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguage.php;h=9eea7ab1b8a88aa91f0d7c59450ef2a2aa2a84cd;hb=6b4b646d0322da3d458c6b2c26d3f7724f112b7e;hp=445e6cb7f001eb93029698e376bb89a8c1df9c6d;hpb=8aef89fdcc59361496adead46ed35c2f0d6485ed;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/Language.php b/languages/Language.php index 445e6cb7f0..9eea7ab1b8 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -27,6 +27,7 @@ */ use CLDRPluralRuleParser\Evaluator; +use Wikimedia\Assert\Assert; /** * Internationalisation code @@ -245,7 +246,7 @@ class Language { // It's not possible to customise this code with class files, so // just return a Language object. This is to support uselang= hacks. $lang = new Language; - $lang->setCode( $code ); + $lang->mCode = $code; return $lang; } @@ -267,7 +268,7 @@ class Language { $class = self::classFromCode( $fallbackCode ); if ( class_exists( $class ) ) { $lang = new $class; - $lang->setCode( $code ); + $lang->mCode = $code; return $lang; } } @@ -385,6 +386,7 @@ class Language { */ public static function isValidCode( $code ) { static $cache = []; + Assert::parameterType( 'string', $code, '$code' ); if ( !isset( $cache[$code] ) ) { // People think language codes are html safe, so enforce it. // Ideally we should only allow a-zA-Z0-9- @@ -404,20 +406,11 @@ class Language { * * @param string $code * - * @throws MWException * @since 1.18 * @return bool */ public static function isValidBuiltInCode( $code ) { - if ( !is_string( $code ) ) { - if ( is_object( $code ) ) { - $addmsg = " of class " . get_class( $code ); - } else { - $addmsg = ''; - } - $type = gettype( $code ); - throw new MWException( __METHOD__ . " must be passed a string, $type given$addmsg" ); - } + Assert::parameterType( 'string', $code, '$code' ); return (bool)preg_match( '/^[a-z0-9-]{2,}$/', $code ); } @@ -2845,9 +2838,9 @@ class Language { } /** + * TODO: $s is not always a string per T218883 * @param string $s * @return string - * @throws MWException */ function checkTitleEncoding( $s ) { if ( is_array( $s ) ) { @@ -3593,14 +3586,12 @@ class Language { $length -= $ellipsisLength; $string = $getSubstring( $string, 0, $length ); // xyz... $string = $this->removeBadCharLast( $string ); - $string = rtrim( $string ); - $string = $string . $ellipsis; + $string = rtrim( $string ) . $ellipsis; } else { $length += $ellipsisLength; $string = $getSubstring( $string, $length ); // ...xyz $string = $this->removeBadCharFirst( $string ); - $string = ltrim( $string ); - $string = $ellipsis . $string; + $string = $ellipsis . ltrim( $string ); } } @@ -4331,32 +4322,6 @@ class Language { $this->mConverter->updateConversionTable( $title ); } - /** - * Prepare external link text for conversion. When the text is - * a URL, it shouldn't be converted, and it'll be wrapped in - * the "raw" tag (-{R| }-) to prevent conversion. - * - * This function is called "markNoConversion" for historical - * 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 ); - } else { - return $text; - } - } - /** * A regular expression to match legal word-trailing characters * which should be merged onto a link of the form [[foo]]bar. @@ -4449,6 +4414,7 @@ class Language { * @deprecated since 1.32, use Language::factory to create a new object instead. */ public function setCode( $code ) { + wfDeprecated( __METHOD__, '1.32' ); $this->mCode = $code; // Ensure we don't leave incorrect cached data lying around $this->mHtmlCode = null;