From 224b22a051051f6c2e494c3a2fb4adb42898e2d1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Tue, 14 Jan 2014 19:24:18 +0100 Subject: Update to MediaWiki 1.22.1 --- languages/Language.php | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'languages/Language.php') diff --git a/languages/Language.php b/languages/Language.php index c24dc180..11d91036 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3633,17 +3633,10 @@ class Language { */ 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 ''; } @@ -3653,6 +3646,34 @@ class Language { 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.22.1 + * + * @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. -- cgit v1.2.3-54-g00ecf