- if ( function_exists( 'gzencode' ) && !headers_sent() ) {
- $tokens = preg_split( '/[,; ]/', $_SERVER['HTTP_ACCEPT_ENCODING'] );
- if ( in_array( 'gzip', $tokens ) ) {
- header( 'Content-Encoding: gzip' );
- $s = gzencode( $s, 3 );
-
- # Set vary header if it hasn't been set already
- $headers = headers_list();
- $foundVary = false;
- foreach ( $headers as $header ) {
- if ( substr( $header, 0, 5 ) == 'Vary:' ) {
- $foundVary = true;
- break;
- }
- }
- if ( !$foundVary ) {
- header( 'Vary: Accept-Encoding' );
- }
+ if( !function_exists( 'gzencode' ) || headers_sent() ) {
+ return $s;
+ }
+
+ $ext = wfRequestExtension();
+ if( $ext == '.gz' || $ext == '.tgz' ) {
+ // Don't do gzip compression if the URL path ends in .gz or .tgz
+ // This confuses Safari and triggers a download of the page,
+ // even though it's pretty clearly labeled as viewable HTML.
+ // Bad Safari! Bad!
+ return $s;
+ }
+
+ $tokens = preg_split( '/[,; ]/', $_SERVER['HTTP_ACCEPT_ENCODING'] );
+ if ( in_array( 'gzip', $tokens ) ) {
+ header( 'Content-Encoding: gzip' );
+ $s = gzencode( $s, 3 );
+ }
+
+ // Set vary header if it hasn't been set already
+ $headers = headers_list();
+ $foundVary = false;
+ foreach ( $headers as $header ) {
+ if ( substr( $header, 0, 5 ) == 'Vary:' ) {
+ $foundVary = true;
+ break;