summaryrefslogtreecommitdiff
path: root/includes/OutputHandler.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2008-03-21 11:49:34 +0100
committerPierre Schmitz <pierre@archlinux.de>2008-03-21 11:49:34 +0100
commit086ae52d12011746a75f5588e877347bc0457352 (patch)
treee73263c7a29d0f94fafb874562610e16eb292ba8 /includes/OutputHandler.php
parent749e7fb2bae7bbda855de3c9e319435b9f698ff7 (diff)
Update auf MediaWiki 1.12.0
Diffstat (limited to 'includes/OutputHandler.php')
-rw-r--r--includes/OutputHandler.php84
1 files changed, 78 insertions, 6 deletions
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 = <<<EOT
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+<head>
+<title>HTML validation error</title>
+<style>
+.highlight { background-color: #ffc }
+li { white-space: pre }
+</style>
+</head>
+<body>
+<h1>HTML validation error</h1>
+<ul>
+EOT;
+
+ $error = strtok( $tidy->errorBuffer, "\n" );
+ $badLines = array();
+ while ( $error !== false ) {
+ if ( preg_match( '/^line (\d+)/', $error, $m ) ) {
+ $lineNum = intval( $m[1] );
+ $badLines[$lineNum] = true;
+ $out .= "<li><a href=\"#line-{$lineNum}\">" . htmlspecialchars( $error ) . "</a></li>\n";
+ }
+ $error = strtok( "\n" );
+ }
+
+ $out .= '<pre>' . htmlspecialchars( $tidy->errorBuffer ) . '</pre>';
+ $out .= '<ol>';
+ $line = strtok( $s, "\n" );
+ $i = 1;
+ while ( $line !== false ) {
+ if ( isset( $badLines[$i] ) ) {
+ $out .= "<li class=\"highlight\" id=\"line-$i\">";
+ } else {
+ $out .= '<li>';
+ }
+ $out .= htmlspecialchars( $line ) . '</li>';
+ $line = strtok( "\n" );
+ $i++;
+ }
+ $out .= '</ol></body></html>';
+ return $out;
+}