From f72117e7689a76a6b24486c1ca5cbf7059f3d413 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 17 Sep 2013 12:26:12 +0200 Subject: [PATCH] Add gzdecode fallback to GlobalFunctions * Follows-up I6383e933b. * Replaced existing usage of `gzinflate( substr( $data, 10, -8 ) );` with `gzdecode( $data )`. Change-Id: Ie2916584f92ff72c7d7ddca73acf1c94dda38cca --- includes/GlobalFunctions.php | 12 ++++++++++++ tests/phpunit/maintenance/DumpTestCase.php | 13 ++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index f43393a880..0c92ab6535 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -93,6 +93,18 @@ if ( !function_exists( 'mb_strrpos' ) ) { return Fallback::mb_strrpos( $haystack, $needle, $offset, $encoding ); } } + +// gzdecode function only exists in PHP >= 5.4.0 +// http://php.net/gzdecode +if ( !function_exists( 'gzdecode' ) ) { + /** + * @codeCoverageIgnore + * @return string + */ + function gzdecode( $data ) { + return gzinflate( substr( $data, 10, -8 ) ); + } +} /// @endcond /** diff --git a/tests/phpunit/maintenance/DumpTestCase.php b/tests/phpunit/maintenance/DumpTestCase.php index 78a51533f7..163314e4fe 100644 --- a/tests/phpunit/maintenance/DumpTestCase.php +++ b/tests/phpunit/maintenance/DumpTestCase.php @@ -60,11 +60,14 @@ abstract class DumpTestCase extends MediaWikiLangTestCase { if ( $gzipped_contents === false ) { $this->fail( "Could not get contents of $fname" ); } - // We resort to use gzinflate instead of gzdecode, as gzdecode - // need not be available - $contents = gzinflate( substr( $gzipped_contents, 10, -8 ) ); - $this->assertEquals( strlen( $contents ), - file_put_contents( $fname, $contents ), "# bytes written" ); + + $contents = gzdecode( $gzipped_contents ); + + $this->assertEquals( + strlen( $contents ), + file_put_contents( $fname, $contents ), + '# bytes written' + ); } /** -- 2.20.1