function getParsedTitle() { return ''; }
function markNoConversion( $text, $noParse = false ) { return $text; }
function convertCategoryKey( $key ) { return $key; }
- function convertLinkToAllVariants( $text ) { return $this->autoConvertToAllVariants( $text ); }
/** @deprecated since 1.22 is no longer used */
function armourMath( $text ) { return $text; }
function validateVariant( $variant = null ) { return $variant === $this->mLang->getCode() ? $variant : null; }
protected static function newFromCode( $code ) {
// Protect against path traversal below
if ( !Language::isValidCode( $code )
- || strcspn( $code, ":/\\\000" ) !== strlen( $code ) )
- {
+ || strcspn( $code, ":/\\\000" ) !== strlen( $code )
+ ) {
throw new MWException( "Invalid language code \"$code\"" );
}
* @since 1.20
*/
public static function fetchLanguageName( $code, $inLanguage = null, $include = 'all' ) {
+ $code = strtolower( $code );
$array = self::fetchLanguageNames( $inLanguage, $include );
return !array_key_exists( $code, $array ) ? '' : $array[$code];
}
if (
( $zy > 1582 ) || ( ( $zy == 1582 ) && ( $zm > 10 ) ) ||
( ( $zy == 1582 ) && ( $zm == 10 ) && ( $zd > 14 ) )
- )
- {
+ ) {
$zjd = (int)( ( 1461 * ( $zy + 4800 + (int)( ( $zm - 14 ) / 12 ) ) ) / 4 ) +
(int)( ( 367 * ( $zm - 2 - 12 * ( (int)( ( $zm - 14 ) / 12 ) ) ) ) / 12 ) -
(int)( ( 3 * (int)( ( ( $zy + 4900 + (int)( ( $zm - 14 ) / 12 ) ) / 100 ) ) ) / 4 ) +
( ( $gy > 1912 ) && ( $gy < 1926 ) ) ||
( ( $gy == 1926 ) && ( $gm < 12 ) ) ||
( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd < 26 ) )
- )
- {
+ ) {
# Taishō period
$gy_gannen = $gy - 1912 + 1;
$gy_offset = $gy_gannen;
( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd >= 26 ) ) ||
( ( $gy > 1926 ) && ( $gy < 1989 ) ) ||
( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd < 8 ) )
- )
- {
+ ) {
# Shōwa period
$gy_gannen = $gy - 1926 + 1;
$gy_offset = $gy_gannen;
*/
function convertPlural( $count, $forms ) {
// Handle explicit n=pluralform cases
- foreach ( $forms as $index => $form ) {
- if ( preg_match( '/^\d+=/i', $form ) ) {
- $pos = strpos( $form, '=' );
- if ( substr( $form, 0, $pos ) === (string)$count ) {
- return substr( $form, $pos + 1 );
- }
- unset( $forms[$index] );
- }
+ $forms = $this->handleExplicitPluralForms( $count, $forms );
+ if ( is_string( $forms ) ) {
+ return $forms;
}
-
- $forms = array_values( $forms );
if ( !count( $forms ) ) {
return '';
}
return $forms[$pluralForm];
}
+ /**
+ * Handles explicit plural forms for Language::convertPlural()
+ *
+ * In {{PLURAL:$1|0=nothing|one|many}}, 0=nothing will be returned if $1 equals zero.
+ * If an explicitly defined plural form matches the $count, then
+ * string value returned, otherwise array returned for further consideration
+ * by CLDR rules or overridden convertPlural().
+ *
+ * @since 1.23
+ *
+ * @param int $count non-localized number
+ * @param array $forms different plural forms
+ *
+ * @return array|string
+ */
+ protected function handleExplicitPluralForms( $count, array $forms ) {
+ foreach ( $forms as $index => $form ) {
+ if ( preg_match( '/\d+=/i', $form ) ) {
+ $pos = strpos( $form, '=' );
+ if ( substr( $form, 0, $pos ) === (string) $count ) {
+ return substr( $form, $pos + 1 );
+ }
+ unset( $forms[$index] );
+ }
+ }
+ return array_values( $forms );
+ }
+
/**
* Checks that convertPlural was given an array and pads it to requested
* amount of forms by copying the last one.
$this->mConverter->findVariantLink( $link, $nt, $ignoreOtherCond );
}
- /**
- * If a language supports multiple variants, converts text
- * into an array of all possible variants of the text:
- * 'variant' => text in that variant
- *
- * @deprecated since 1.17 Use autoConvertToAllVariants()
- *
- * @param $text string
- *
- * @return string
- */
- public function convertLinkToAllVariants( $text ) {
- return $this->mConverter->convertLinkToAllVariants( $text );
- }
-
/**
* returns language specific options used by User::getPageRenderHash()
* for example, the preferred language variant
public static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
// Protect against path traversal
if ( !Language::isValidCode( $code )
- || strcspn( $code, ":/\\\000" ) !== strlen( $code ) )
- {
+ || strcspn( $code, ":/\\\000" ) !== strlen( $code )
+ ) {
throw new MWException( "Invalid language code \"$code\"" );
}