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