From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/Fallback.php | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 includes/Fallback.php (limited to 'includes/Fallback.php') diff --git a/includes/Fallback.php b/includes/Fallback.php new file mode 100644 index 00000000..2cca1e81 --- /dev/null +++ b/includes/Fallback.php @@ -0,0 +1,200 @@ + 0 ) { + if( $splitPos > 256 ) { + // Optimize large string offsets by skipping ahead N bytes. + // This will cut out most of our slow time on Latin-based text, + // and 1/2 to 1/3 on East European and Asian scripts. + $bytePos = $splitPos; + while ( $bytePos < $byteLen && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) { + ++$bytePos; + } + $charPos = mb_strlen( substr( $str, 0, $bytePos ) ); + } else { + $charPos = 0; + $bytePos = 0; + } + + while( $charPos++ < $splitPos ) { + ++$bytePos; + // Move past any tail bytes + while ( $bytePos < $byteLen && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) { + ++$bytePos; + } + } + } else { + $splitPosX = $splitPos + 1; + $charPos = 0; // relative to end of string; we don't care about the actual char position here + $bytePos = $byteLen; + while( $bytePos > 0 && $charPos-- >= $splitPosX ) { + --$bytePos; + // Move past any tail bytes + while ( $bytePos > 0 && $str[$bytePos] >= "\x80" && $str[$bytePos] < "\xc0" ) { + --$bytePos; + } + } + } + + return $bytePos; + } + + /** + * Fallback implementation of mb_strlen, hardcoded to UTF-8. + * @param string $str + * @param string $enc optional encoding; ignored + * @return int + */ + public static 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; + } + + + /** + * Fallback implementation of mb_strpos, hardcoded to UTF-8. + * @param $haystack String + * @param $needle String + * @param $offset String: optional start position + * @param $encoding String: optional encoding; ignored + * @return int + */ + public static function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) { + $needle = preg_quote( $needle, '/' ); + + $ar = array(); + preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); + + if( isset( $ar[0][1] ) ) { + return $ar[0][1]; + } else { + return false; + } + } + + /** + * Fallback implementation of mb_strrpos, hardcoded to UTF-8. + * @param $haystack String + * @param $needle String + * @param $offset String: optional start position + * @param $encoding String: optional encoding; ignored + * @return int + */ + public static function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) { + $needle = preg_quote( $needle, '/' ); + + $ar = array(); + preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); + + if( isset( $ar[0] ) && count( $ar[0] ) > 0 && + isset( $ar[0][count( $ar[0] ) - 1][1] ) ) { + return $ar[0][count( $ar[0] ) - 1][1]; + } else { + return false; + } + } + + /** + * Fallback implementation of stream_resolve_include_path() + * Native stream_resolve_include_path is available for PHP 5 >= 5.3.2 + * @param $filename String + * @return String + */ + public static function stream_resolve_include_path( $filename ) { + $pathArray = explode( PATH_SEPARATOR, get_include_path() ); + foreach ( $pathArray as $path ) { + $fullFilename = $path . DIRECTORY_SEPARATOR . $filename; + if ( file_exists( $fullFilename ) ) { + return $fullFilename; + } + } + return false; + } + +} -- cgit v1.2.2