* Replace the output with an error if the HTML is not valid
*/
function wfHtmlValidationHandler( $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;
- }
+ $errors = '';
+ if ( MWTidy::checkErrors( $s, $errors ) ) {
+ return $s;
}
header( 'Cache-Control: no-cache' );
$out .= '</ul>';
$out .= '<pre>' . htmlspecialchars( $errors ) . '</pre>';
- $out .= '<ol>';
+ $out .= "<ol>\n";
$line = strtok( $s, "\n" );
$i = 1;
while ( $line !== false ) {
} else {
$out .= '<li>';
}
- $out .= htmlspecialchars( $line ) . '</li>';
+ $out .= htmlspecialchars( $line ) . "</li>\n";
$line = strtok( "\n" );
$i++;
}