From: Alexandre Emsenhuber Date: Sat, 24 Jan 2009 16:26:05 +0000 (+0000) Subject: Tweaks for the "Whole HTML Validation" feature: X-Git-Tag: 1.31.0-rc.0~43276 X-Git-Url: http://git.cyclocoop.org///%22%40url%40//%22?a=commitdiff_plain;h=da85e1731621ea528cc99c48c8881a00cfd3e1ab;p=lhc%2Fweb%2Fwiklou.git Tweaks for the "Whole HTML Validation" feature: * Allow to use external tidy * Accept application/xhtml+xml mime type * Fix XHTML errors on errors reports :) --- diff --git a/includes/OutputHandler.php b/includes/OutputHandler.php index 2b3e9fae55..3d123c34ab 100644 --- a/includes/OutputHandler.php +++ b/includes/OutputHandler.php @@ -10,7 +10,7 @@ function wfOutputHandler( $s ) { $headers = apache_response_headers(); $isHTML = true; foreach ( $headers as $name => $value ) { - if ( strtolower( $name ) == 'content-type' && strpos( $value, 'text/html' ) === false ) { + if ( strtolower( $name ) == 'content-type' && strpos( $value, 'text/html' ) === false && strpos( $value, 'application/xhtml+xml' ) === false ) { $isHTML = false; break; } @@ -123,18 +123,55 @@ 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; + global $IP, $wgTidyInternal, $wgTidyConf; + if ( $wgTidyInternal ) { + $tidy = new tidy; + + $tidy->parseString( $s, $wgTidyConf, 'utf8' ); + if ( $tidy->getStatus() == 0 ) { + return $s; + } + + $errors = $tidy->errorBuffer; + } else { + // Copied from Parser::externalTidy(); + global $wgTidyBin, $wgTidyOpts; + + $cleansource = ''; + $opts = ' -utf8'; + + $descriptorspec = array( + 0 => array( 'pipe', 'r' ), + 1 => array( 'file', wfGetNull(), 'a' ), + 2 => array( 'pipe', 'w' ) + ); + $pipes = array(); + if( function_exists( 'proc_open' ) ) { + $process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts$opts", $descriptorspec, $pipes ); + if ( is_resource( $process ) ) { + fwrite( $pipes[0], $s ); + fclose( $pipes[0] ); + while( !feof( $pipes[2] ) ) { + $errors .= fgets( $pipes[2], 1024 ); + } + fclose( $pipes[2] ); + $ret = proc_close( $process ); + if( ( $ret < 0 && $errors == '' ) || $ret == 0 ) + return $s; + } else { + return $s; + } + + } else { + return $s; + } } header( 'Cache-Control: no-cache' ); $out = << - + HTML validation error