Merge "No need to call parseTitle() directly in MediaWiki::__construct()."
[lhc/web/wiklou.git] / languages / Language.php
index 3ee959e..616f1ea 100644 (file)
@@ -246,7 +246,11 @@ class Language {
         */
        public static function isValidCode( $code ) {
                return
-                       strcspn( $code, ":/\\\000" ) === strlen( $code )
+                       // People think language codes are html safe, so enforce it.
+                       // Ideally we should only allow a-zA-Z0-9-
+                       // but, .+ and other chars are often used for {{int:}} hacks
+                       // see bugs 37564, 37587, 36938
+                       strcspn( $code, ":/\\\000&<>'\"" ) === strlen( $code )
                        && !preg_match( Title::getTitleInvalidRegex(), $code );
        }
 
@@ -1268,7 +1272,7 @@ class Language {
                                        $s .= $num;
                                        $raw = false;
                                } elseif ( $roman ) {
-                                       $s .= self::romanNumeral( $num );
+                                       $s .= Language::romanNumeral( $num );
                                        $roman = false;
                                } elseif ( $hebrewNum ) {
                                        $s .= self::hebrewNumeral( $num );
@@ -1657,7 +1661,7 @@ class Language {
        }
 
        /**
-        * Roman number formatting up to 3000
+        * Roman number formatting up to 10000
         *
         * @param $num int
         *
@@ -1668,11 +1672,11 @@ class Language {
                        array( '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ),
                        array( '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' ),
                        array( '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M' ),
-                       array( '', 'M', 'MM', 'MMM' )
+                       array( '', 'M', 'MM', 'MMM', 'MMMM', 'MMMMM', 'MMMMMM', 'MMMMMMM', 'MMMMMMMM', 'MMMMMMMMM', 'MMMMMMMMMM' )
                );
 
                $num = intval( $num );
-               if ( $num > 3000 || $num <= 0 ) {
+               if ( $num > 10000 || $num <= 0 ) {
                        return $num;
                }
 
@@ -2992,6 +2996,7 @@ 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 $l Array
         * @return string
@@ -2999,7 +3004,10 @@ class Language {
        function listToText( array $l ) {
                $s = '';
                $m = count( $l ) - 1;
-               if ( $m == 1 ) {
+               
+               if ( $m === 0 ) {
+                       return $l[0];
+               } elseif ( $m === 1 ) {
                        return $l[0] . $this->getMessageFromDB( 'and' ) . $this->getMessageFromDB( 'word-separator' ) . $l[1];
                } else {
                        for ( $i = $m; $i >= 0; $i-- ) {
@@ -3913,6 +3921,7 @@ class Language {
         * @param $format Bool|Int true to process using language functions, or TS_ constant
         *     to return the expiry in a given timestamp
         * @return String
+        * @since 1.18
         */
        public function formatExpiry( $expiry, $format = true ) {
                static $infinity, $infinityMsg;