Revert r37281 "Split Compatibility functions to own file"
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 7 Jul 2008 20:15:16 +0000 (20:15 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 7 Jul 2008 20:15:16 +0000 (20:15 +0000)
This would make maintenance harder by duplicating information between GlobalFunctions.php and CompatibilityFunctions.php. If you forget to add a function to the list, the compat functions might not get loaded and you'll run into surprise errors.

includes/CompatibilityFunctions.php [deleted file]
includes/GlobalFunctions.php

diff --git a/includes/CompatibilityFunctions.php b/includes/CompatibilityFunctions.php
deleted file mode 100644 (file)
index 252a5fb..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-
-/**
- * Compatibility functions
- *
- * We more or less support PHP 5.0.x and up.
- * Re-implementations of newer functions or functions in non-standard
- * PHP extensions may be included here.
- */
-if( !function_exists('iconv') ) {
-       # iconv support is not in the default configuration and so may not be present.
-       # Assume will only ever use utf-8 and iso-8859-1.
-       # This will *not* work in all circumstances.
-       function iconv( $from, $to, $string ) {
-               if(strcasecmp( $from, $to ) == 0) return $string;
-               if(strcasecmp( $from, 'utf-8' ) == 0) return utf8_decode( $string );
-               if(strcasecmp( $to, 'utf-8' ) == 0) return utf8_encode( $string );
-               return $string;
-       }
-}
-
-# UTF-8 substr function based on a PHP manual comment
-if ( !function_exists( 'mb_substr' ) ) {
-       function mb_substr( $str, $start ) {
-               $ar = array();
-               preg_match_all( '/./us', $str, $ar );
-
-               if( func_num_args() >= 3 ) {
-                       $end = func_get_arg( 2 );
-                       return join( '', array_slice( $ar[0], $start, $end ) );
-               } else {
-                       return join( '', array_slice( $ar[0], $start ) );
-               }
-       }
-}
-
-if ( !function_exists( 'mb_strlen' ) ) {
-       /**
-        * Fallback implementation of mb_strlen, hardcoded to UTF-8.
-        * @param string $str
-        * @param string $enc optional encoding; ignored
-        * @return int
-        */
-       function mb_strlen( $str, $enc="" ) {
-               $counts = count_chars( $str );
-               $total = 0;
-
-               // Count ASCII bytes
-               for( $i = 0; $i < 0x80; $i++ ) {
-                       $total += $counts[$i];
-               }
-
-               // Count multibyte sequence heads
-               for( $i = 0xc0; $i < 0xff; $i++ ) {
-                       $total += $counts[$i];
-               }
-               return $total;
-       }
-}
-
-if ( !function_exists( 'array_diff_key' ) ) {
-       /**
-        * Exists in PHP 5.1.0+
-        * Not quite compatible, two-argument version only
-        * Null values will cause problems due to this use of isset()
-        */
-       function array_diff_key( $left, $right ) {
-               $result = $left;
-               foreach ( $left as $key => $unused ) {
-                       if ( isset( $right[$key] ) ) {
-                               unset( $result[$key] );
-                       }
-               }
-               return $result;
-       }
-}
index ff6fac0..4e60bd4 100644 (file)
@@ -12,12 +12,78 @@ require_once dirname(__FILE__) . '/LogPage.php';
 require_once dirname(__FILE__) . '/normal/UtfNormalUtil.php';
 require_once dirname(__FILE__) . '/XmlFunctions.php';
 
-$compatibilityFunctions = array( 'iconv', 'mb_substr', 'mb_strlen', 'array_diff_key' );
-foreach ( $compatibilityFunctions as $function ) {
-       if ( !function_exists($function) ) {
-               wfDebug( "Compatibility functions in use\n" );
-               require_once dirname(__FILE__) . '/CompatibilityFunctions.php';
-               break;
+/**
+ * Compatibility functions
+ *
+ * We more or less support PHP 5.0.x and up.
+ * Re-implementations of newer functions or functions in non-standard
+ * PHP extensions may be included here.
+ */
+if( !function_exists('iconv') ) {
+       # iconv support is not in the default configuration and so may not be present.
+       # Assume will only ever use utf-8 and iso-8859-1.
+       # This will *not* work in all circumstances.
+       function iconv( $from, $to, $string ) {
+               if(strcasecmp( $from, $to ) == 0) return $string;
+               if(strcasecmp( $from, 'utf-8' ) == 0) return utf8_decode( $string );
+               if(strcasecmp( $to, 'utf-8' ) == 0) return utf8_encode( $string );
+               return $string;
+       }
+}
+
+# UTF-8 substr function based on a PHP manual comment
+if ( !function_exists( 'mb_substr' ) ) {
+       function mb_substr( $str, $start ) {
+               $ar = array();
+               preg_match_all( '/./us', $str, $ar );
+
+               if( func_num_args() >= 3 ) {
+                       $end = func_get_arg( 2 );
+                       return join( '', array_slice( $ar[0], $start, $end ) );
+               } else {
+                       return join( '', array_slice( $ar[0], $start ) );
+               }
+       }
+}
+
+if ( !function_exists( 'mb_strlen' ) ) {
+       /**
+        * Fallback implementation of mb_strlen, hardcoded to UTF-8.
+        * @param string $str
+        * @param string $enc optional encoding; ignored
+        * @return int
+        */
+       function mb_strlen( $str, $enc="" ) {
+               $counts = count_chars( $str );
+               $total = 0;
+
+               // Count ASCII bytes
+               for( $i = 0; $i < 0x80; $i++ ) {
+                       $total += $counts[$i];
+               }
+
+               // Count multibyte sequence heads
+               for( $i = 0xc0; $i < 0xff; $i++ ) {
+                       $total += $counts[$i];
+               }
+               return $total;
+       }
+}
+
+if ( !function_exists( 'array_diff_key' ) ) {
+       /**
+        * Exists in PHP 5.1.0+
+        * Not quite compatible, two-argument version only
+        * Null values will cause problems due to this use of isset()
+        */
+       function array_diff_key( $left, $right ) {
+               $result = $left;
+               foreach ( $left as $key => $unused ) {
+                       if ( isset( $right[$key] ) ) {
+                               unset( $result[$key] );
+                       }
+               }
+               return $result;
        }
 }