Merge "benchmarker: Implement setupEach for per-iteration setup"
[lhc/web/wiklou.git] / languages / Language.php
index 9792095..eab09a1 100644 (file)
@@ -244,6 +244,24 @@ class Language {
                throw new MWException( "Invalid fallback sequence for language '$code'" );
        }
 
+       /**
+        * Intended for tests that may change configuration in a way that invalidates caches.
+        *
+        * @since 1.32
+        */
+       public static function clearCaches() {
+               if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
+                       throw new MWException( __METHOD__ . ' must not be used outside tests' );
+               }
+               self::$dataCache = null;
+               // Reinitialize $dataCache, since it's expected to always be available
+               self::getLocalisationCache();
+               self::$mLangObjCache = [];
+               self::$fallbackLanguageCache = [];
+               self::$grammarTransformations = null;
+               self::$languageNameCache = null;
+       }
+
        /**
         * Checks whether any localisation is available for that language tag
         * in MediaWiki (MessagesXx.php exists).
@@ -532,7 +550,7 @@ class Language {
         * Get a namespace value by key
         *
         * <code>
-        * $mw_ns = $wgContLang->getNsText( NS_MEDIAWIKI );
+        * $mw_ns = $lang->getNsText( NS_MEDIAWIKI );
         * echo $mw_ns; // prints 'MediaWiki'
         * </code>
         *
@@ -550,7 +568,7 @@ class Language {
         * producing output.
         *
         * <code>
-        * $mw_ns = $wgContLang->getFormattedNsText( NS_MEDIAWIKI_TALK );
+        * $mw_ns = $lang->getFormattedNsText( NS_MEDIAWIKI_TALK );
         * echo $mw_ns; // prints 'MediaWiki talk'
         * </code>
         *
@@ -2996,7 +3014,7 @@ class Language {
         *
         * @return string
         */
-       function normalize( $s ) {
+       public function normalize( $s ) {
                global $wgAllUnicodeFixes;
                $s = UtfNormal\Validator::cleanUp( $s );
                if ( $wgAllUnicodeFixes ) {
@@ -3413,32 +3431,26 @@ class Language {
         * Take a list of strings and build a locale-friendly comma-separated
         * list, using the local comma-separator message.
         * The last two strings are chained with an "and".
-        * NOTE: This function will only work with standard numeric array keys (0, 1, 2…)
         *
-        * @param string[] $l
+        * @param string[] $list
         * @return string
         */
-       function listToText( array $l ) {
-               $m = count( $l ) - 1;
-               if ( $m < 0 ) {
+       public function listToText( array $list ) {
+               $itemCount = count( $list );
+               if ( $itemCount < 1 ) {
                        return '';
                }
-               if ( $m > 0 ) {
+               $text = array_pop( $list );
+               if ( $itemCount > 1 ) {
                        $and = $this->msg( 'and' )->escaped();
                        $space = $this->msg( 'word-separator' )->escaped();
-                       if ( $m > 1 ) {
+                       $comma = '';
+                       if ( $itemCount > 2 ) {
                                $comma = $this->msg( 'comma-separator' )->escaped();
                        }
+                       $text = implode( $comma, $list ) . $and . $space . $text;
                }
-               $s = $l[$m];
-               for ( $i = $m - 1; $i >= 0; $i-- ) {
-                       if ( $i == $m - 1 ) {
-                               $s = $l[$i] . $and . $space . $s;
-                       } else {
-                               $s = $l[$i] . $comma . $s;
-                       }
-               }
-               return $s;
+               return $text;
        }
 
        /**