Partly disable title conversion if variant == main language code
[lhc/web/wiklou.git] / languages / Language.php
index 7ec37a1..84e7f37 100644 (file)
@@ -326,13 +326,19 @@ class Language {
         * @return bool
         */
        public static function isValidCode( $code ) {
-               return
-                       // 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
+               static $cache = array();
+               if( isset( $cache[$code] ) ) {
+                       return $cache[$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
+               $return =
                        strcspn( $code, ":/\\\000&<>'\"" ) === strlen( $code )
                        && !preg_match( Title::getTitleInvalidRegex(), $code );
+               $cache[ $code ] = $return;
+               return $return;
        }
 
        /**
@@ -1832,7 +1838,7 @@ class Language {
                }
                $start = substr( $str, 0, strlen( $str ) - 2 );
                $end = substr( $str, strlen( $str ) - 2 );
-               switch( $end ) {
+               switch ( $end ) {
                        case 'כ':
                                $str = $start . 'ך';
                                break;