Revision: 46145
Author:   ialex
Date:     2009-01-24 16:26:05 +0000 (Sat, 24 Jan 2009)

Log Message:
-----------
Tweaks for the "Whole HTML Validation" feature:
* Allow to use external tidy
* Accept application/xhtml+xml mime type
* Fix XHTML errors on errors reports :)

Modified Paths:
--------------
    trunk/phase3/includes/OutputHandler.php

Modified: trunk/phase3/includes/OutputHandler.php
===================================================================
--- trunk/phase3/includes/OutputHandler.php     2009-01-24 15:17:20 UTC (rev 
46144)
+++ trunk/phase3/includes/OutputHandler.php     2009-01-24 16:26:05 UTC (rev 
46145)
@@ -10,7 +10,7 @@
                $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 @@
  * 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 = <<<EOT
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
-<html>
+<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en" dir="ltr">
 <head>
 <title>HTML validation error</title>
 <style>
@@ -147,7 +184,7 @@
 <ul>
 EOT;
 
-       $error = strtok( $tidy->errorBuffer, "\n" );
+       $error = strtok( $errors, "\n" );
        $badLines = array();
        while ( $error !== false ) {
                if ( preg_match( '/^line (\d+)/', $error, $m ) ) {
@@ -158,7 +195,8 @@
                $error = strtok( "\n" );
        }
 
-       $out .= '<pre>' . htmlspecialchars( $tidy->errorBuffer ) . '</pre>';
+       $out .= '</ul>';
+       $out .= '<pre>' . htmlspecialchars( $errors ) . '</pre>';
        $out .= '<ol>';
        $line = strtok( $s, "\n" );
        $i = 1;



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to