X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguage.php;h=4e663c250c060ac3906c50d655af5c438052ccd6;hb=75e473005d666b1675404305aab154474216dce2;hp=a9bbc20c1d490b667bd6958e7cc349600906cd89;hpb=09072db2c800c9206245c6a7d98eba64b4c95ac0;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/Language.php b/languages/Language.php index a9bbc20c1d..4e663c250c 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -27,6 +27,7 @@ */ use CLDRPluralRuleParser\Evaluator; +use MediaWiki\MediaWikiServices; use Wikimedia\Assert\Assert; /** @@ -506,7 +507,8 @@ class Language { if ( is_null( $this->namespaceNames ) ) { global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces; - $validNamespaces = MWNamespace::getCanonicalNamespaces(); + $validNamespaces = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalNamespaces(); $this->namespaceNames = $wgExtraNamespaces + self::$dataCache->getItem( $this->mCode, 'namespaceNames' ); @@ -744,7 +746,8 @@ class Language { */ public function getNsIndex( $text ) { $lctext = $this->lc( $text ); - $ns = MWNamespace::getCanonicalIndex( $lctext ); + $ns = MediaWikiServices::getInstance()->getNamespaceInfo()-> + getCanonicalIndex( $lctext ); if ( $ns !== null ) { return $ns; } @@ -811,7 +814,8 @@ class Language { * @return array */ public function getExtraUserToggles() { - return (array)self::$dataCache->getItem( $this->mCode, 'extraUserToggles' ); + wfDeprecated( __METHOD__, '1.34' ); + return []; } /** @@ -1977,7 +1981,11 @@ class Language { $gy_offset = '元'; } $gy_offset = '昭和' . $gy_offset; - } else { + } elseif ( + ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd >= 8 ) ) || + ( ( $gy > 1989 ) && ( $gy < 2019 ) ) || + ( ( $gy == 2019 ) && ( $gm < 5 ) ) + ) { # Heisei period $gy_gannen = $gy - 1989 + 1; $gy_offset = $gy_gannen; @@ -1985,6 +1993,14 @@ class Language { $gy_offset = '元'; } $gy_offset = '平成' . $gy_offset; + } else { + # Reiwa period + $gy_gannen = $gy - 2019 + 1; + $gy_offset = $gy_gannen; + if ( $gy_gannen == 1 ) { + $gy_offset = '元'; + } + $gy_offset = '令和' . $gy_offset; } } else { $gy_offset = $gy; @@ -2713,7 +2729,7 @@ class Language { public function uc( $str, $first = false ) { if ( $first ) { if ( $this->isMultibyte( $str ) ) { - return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 ); + return $this->mbUpperChar( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 ); } else { return ucfirst( $str ); } @@ -2722,6 +2738,28 @@ class Language { } } + /** + * Convert character to uppercase, allowing overrides of the default mb_upper + * behaviour, which is buggy in many ways. Having a conversion table can be + * useful during transitions between PHP versions where unicode changes happen. + * This can make some resources unreachable on-wiki, see discussion at T219279. + * Providing such a conversion table can allow to manage the transition period. + * + * @since 1.34 + * + * @param string $char + * + * @return string + */ + protected function mbUpperChar( $char ) { + global $wgOverrideUcfirstCharacters; + if ( array_key_exists( $char, $wgOverrideUcfirstCharacters ) ) { + return $wgOverrideUcfirstCharacters[$char]; + } else { + return mb_strtoupper( $char ); + } + } + /** * @param string $str * @return mixed|string @@ -2996,34 +3034,6 @@ class Language { } } - /** - * @deprecated No-op since 1.28 - */ - function initEncoding() { - wfDeprecated( __METHOD__, '1.28' ); - // No-op. - } - - /** - * @param string $s - * @return string - * @deprecated No-op since 1.28 - */ - function recodeForEdit( $s ) { - wfDeprecated( __METHOD__, '1.28' ); - return $s; - } - - /** - * @param string $s - * @return string - * @deprecated No-op since 1.28 - */ - function recodeInput( $s ) { - wfDeprecated( __METHOD__, '1.28' ); - return $s; - } - /** * Convert a UTF-8 string to normal form C. In Malayalam and Arabic, this * also cleans up certain backwards-compatible sequences, converting them @@ -4649,6 +4659,7 @@ class Language { * * @param int|float $seconds * @param array $format An optional argument that formats the returned string in different ways: + * If $format['avoid'] === 'avoidhours': don't show hours, just show days * If $format['avoid'] === 'avoidseconds': don't show seconds if $seconds >= 1 hour, * If $format['avoid'] === 'avoidminutes': don't show seconds/minutes if $seconds > 48 hours, * If $format['noabbrevs'] is true: use 'seconds' and friends instead of 'seconds-abbrev' @@ -4707,12 +4718,19 @@ class Language { $s = $hoursMsg->params( $this->formatNum( $hours ) )->text(); $s .= ' '; $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text(); - if ( !in_array( $format['avoid'], [ 'avoidseconds', 'avoidminutes' ] ) ) { + if ( !in_array( $format['avoid'], [ 'avoidseconds', 'avoidminutes', 'avoidhours' ] ) ) { $s .= ' ' . $secondsMsg->params( $this->formatNum( $secondsPart ) )->text(); } } else { $days = floor( $seconds / 86400 ); - if ( $format['avoid'] === 'avoidminutes' ) { + if ( $format['avoid'] === 'avoidhours' ) { + $hours = round( ( $seconds - $days * 86400 ) / 3600 ); + if ( $hours == 24 ) { + $hours = 0; + $days++; + } + $s = $daysMsg->params( $this->formatNum( $days ) )->text(); + } elseif ( $format['avoid'] === 'avoidminutes' ) { $hours = round( ( $seconds - $days * 86400 ) / 3600 ); if ( $hours == 24 ) { $hours = 0; @@ -4839,7 +4857,7 @@ class Language { * @param array $query Optional URL query parameter string * @param bool $atend Optional param for specified if this is the last page * @return string - * @deprecated since 1.33, use SpecialPage::viewPrevNext() + * @deprecated since 1.34, use PrevNextNavigationRenderer::buildPrevNextNavigation() * instead. */ public function viewPrevNext( Title $title, $offset, $limit,