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\"" );
}
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;
$length -= $eLength;
$string = substr( $string, 0, $length ); // xyz...
$string = $this->removeBadCharLast( $string );
+ $string = rtrim( $string );
$string = $string . $ellipsis;
} else {
$length += $eLength;
$string = substr( $string, $length ); // ...xyz
$string = $this->removeBadCharFirst( $string );
+ $string = ltrim( $string );
$string = $ellipsis . $string;
}
}
*/
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.
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\"" );
}