X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguage.php;h=9eea7ab1b8a88aa91f0d7c59450ef2a2aa2a84cd;hb=6b4b646d0322da3d458c6b2c26d3f7724f112b7e;hp=3dbde01b636ff5161666c5bff4cf85d2e9827aa3;hpb=7099937b42cdf52948ae0c3c5f761ca573f7e530;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/Language.php b/languages/Language.php index 3dbde01b63..9eea7ab1b8 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -27,6 +27,7 @@ */ use CLDRPluralRuleParser\Evaluator; +use Wikimedia\Assert\Assert; /** * Internationalisation code @@ -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.