From 086ae52d12011746a75f5588e877347bc0457352 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 21 Mar 2008 11:49:34 +0100 Subject: Update auf MediaWiki 1.12.0 --- includes/OutputHandler.php | 84 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 6 deletions(-) (limited to 'includes/OutputHandler.php') diff --git a/includes/OutputHandler.php b/includes/OutputHandler.php index d8ac12b5..107553fc 100644 --- a/includes/OutputHandler.php +++ b/includes/OutputHandler.php @@ -4,8 +4,21 @@ * Standard output handler for use with ob_start */ function wfOutputHandler( $s ) { - global $wgDisableOutputCompression; - $s = wfMangleFlashPolicy( $s ); + global $wgDisableOutputCompression, $wgValidateAllHtml; + $s = wfMangleFlashPolicy( $s ); + if ( $wgValidateAllHtml ) { + $headers = apache_response_headers(); + $isHTML = true; + foreach ( $headers as $name => $value ) { + if ( strtolower( $name ) == 'content-type' && strpos( $value, 'text/html' ) === false ) { + $isHTML = false; + break; + } + } + if ( $isHTML ) { + $s = wfHtmlValidationHandler( $s ); + } + } if ( !$wgDisableOutputCompression && !ini_get( 'zlib.output_compression' ) ) { if ( !defined( 'MW_NO_OUTPUT_COMPRESSION' ) ) { $s = wfGzipHandler( $s ); @@ -61,10 +74,12 @@ function wfGzipHandler( $s ) { return $s; } - $tokens = preg_split( '/[,; ]/', $_SERVER['HTTP_ACCEPT_ENCODING'] ); - if ( in_array( 'gzip', $tokens ) ) { - header( 'Content-Encoding: gzip' ); - $s = gzencode( $s, 3 ); + if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { + $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 @@ -78,6 +93,7 @@ function wfGzipHandler( $s ) { } if ( !$foundVary ) { header( 'Vary: Accept-Encoding' ); + header( 'X-Vary-Options: Accept-Encoding;list-contains=gzip' ); } return $s; } @@ -98,4 +114,60 @@ function wfDoContentLength( $length ) { } } +/** + * Replace the output with an error if the HTML is not valid + */ +function wfHtmlValidationHandler( $s ) { + global $IP; + $tidy = new tidy; + $tidy->parseString( $s, "$IP/includes/tidy.conf", 'utf8' ); + if ( $tidy->getStatus() == 0 ) { + return $s; + } + + header( 'Cache-Control: no-cache' ); + + $out = << + + +HTML validation error + + + +

HTML validation error

+