<?php
+/**
+ * HTML validation and correction
+ *
+ * @file
+ */
/**
* Class to interact with HTML tidy
* If tidy isn't able to correct the markup, the original will be
* returned in all its glory with a warning comment appended.
*
- * @param string $text Hideous HTML input
- * @return string Corrected HTML output
+ * @param $text String: hideous HTML input
+ * @return String: corrected HTML output
*/
public static function tidy( $text ) {
global $wgTidyInternal;
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'.
'<head><title>test</title></head><body>'.$text.'</body></html>';
- # Tidy is known to clobber tabs; convert them to entities
- $wrappedtext = str_replace( "\t", '	', $wrappedtext );
-
if( $wgTidyInternal ) {
$correctedtext = self::execInternalTidy( $wrappedtext );
} else {
return $text . "\n<!-- Tidy found serious XHTML errors -->\n";
}
- # Convert the tabs back from entities
- $correctedtext = str_replace( '	', "\t", $correctedtext );
-
return $correctedtext;
}
* @param $text String: HTML to check
* @param $stderr Boolean: Whether to read from STDERR rather than STDOUT
* @param &$retval Exit code (-1 on internal error)
- * @retrun mixed String or null
+ * @return mixed String or null
*/
private static function execExternalTidy( $text, $stderr = false, &$retval = null ) {
global $wgTidyConf, $wgTidyBin, $wgTidyOpts;
$retval = -1;
}
- wfProfileOut( __METHOD__ );
-
if( !$stderr && $cleansource == '' && $text != '' ) {
// Some kind of error happened, so we couldn't get the corrected text.
// Just give up; we'll use the source text and append a warning.
- return null;
- } else {
- return $cleansource;
+ $cleansource = null;
}
+ wfProfileOut( __METHOD__ );
+ return $cleansource;
}
/**
* 'pear install tidy' should be able to compile the extension module.
*/
private static function execInternalTidy( $text, $stderr = false, &$retval = null ) {
- global $wgTidyConf, $IP, $wgDebugTidy;
+ global $wgTidyConf, $wgDebugTidy;
wfProfileIn( __METHOD__ );
$tidy = new tidy;
if( $stderr ) {
$retval = $tidy->getStatus();
+ wfProfileOut( __METHOD__ );
return $tidy->errorBuffer;
} else {
$tidy->cleanRepair();