3 namespace MediaWiki\Tidy
;
5 abstract class RaggettBase
extends TidyDriverBase
{
7 * Generic interface for wrapping and unwrapping HTML for Dave Raggett's tidy.
9 * @param string $text Hideous HTML input
10 * @return string Corrected HTML output
12 public function tidy( $text ) {
13 $wrapper = new RaggettWrapper
;
14 $wrappedtext = $wrapper->getWrapped( $text );
17 $correctedtext = $this->cleanWrapped( $wrappedtext, false, $retVal );
20 wfDebug( "Possible tidy configuration error!\n" );
21 return $text . "\n<!-- Tidy was unable to run -->\n";
22 } elseif ( is_null( $correctedtext ) ) {
23 wfDebug( "Tidy error detected!\n" );
24 return $text . "\n<!-- Tidy found serious XHTML errors -->\n";
27 $correctedtext = $wrapper->postprocess( $correctedtext ); // restore any hidden tokens
29 return $correctedtext;
32 public function validate( $text, &$errorStr ) {
34 $errorStr = $this->cleanWrapped( $text, true, $retval );
35 return ( $retval < 0 && $errorStr == '' ) ||
$retval == 0;
39 * Perform a clean/repair operation
40 * @param string $text HTML to check
41 * @param bool $stderr Whether to read result from STDERR rather than STDOUT
42 * @param int &$retval Exit code (-1 on internal error)
46 abstract protected function cleanWrapped( $text, $stderr = false, &$retval = null );