Add gzdecode fallback to GlobalFunctions
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 17 Sep 2013 10:26:12 +0000 (12:26 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 17 Sep 2013 22:04:31 +0000 (00:04 +0200)
* Follows-up I6383e933b.
* Replaced existing usage of `gzinflate( substr( $data, 10, -8 ) );`
  with `gzdecode( $data )`.

Change-Id: Ie2916584f92ff72c7d7ddca73acf1c94dda38cca

includes/GlobalFunctions.php
tests/phpunit/maintenance/DumpTestCase.php

index f43393a..0c92ab6 100644 (file)
@@ -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
 
 /**
index 78a5153..163314e 100644 (file)
@@ -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'
+               );
        }
 
        /**