3 namespace MediaWiki\Tidy
;
8 * @deprecated since 1.32, use RemexDriver
10 abstract class RaggettBase
extends TidyDriverBase
{
12 function __construct( $config ) {
13 parent
::__construct( $config );
15 // All tidy modes other than remex are deprecated.
16 wfDeprecated( __METHOD__
, '1.32' );
20 * Generic interface for wrapping and unwrapping HTML for Dave Raggett's tidy.
22 * @param string $text Hideous HTML input
23 * @return string Corrected HTML output
25 public function tidy( $text ) {
26 $wrapper = new RaggettWrapper
;
27 $wrappedtext = $wrapper->getWrapped( $text );
30 $correctedtext = $this->cleanWrapped( $wrappedtext, false, $retVal );
33 wfDebug( "Possible tidy configuration error!\n" );
34 return $text . "\n<!-- Tidy was unable to run -->\n";
35 } elseif ( is_null( $correctedtext ) ) {
36 wfDebug( "Tidy error detected!\n" );
37 return $text . "\n<!-- Tidy found serious XHTML errors -->\n";
40 $correctedtext = $wrapper->postprocess( $correctedtext ); // restore any hidden tokens
42 return $correctedtext;
45 public function validate( $text, &$errorStr ) {
47 $errorStr = $this->cleanWrapped( $text, true, $retval );
48 return ( $retval < 0 && $errorStr == '' ) ||
$retval == 0;
52 * Perform a clean/repair operation
53 * @param string $text HTML to check
54 * @param bool $stderr Whether to read result from STDERR rather than STDOUT
55 * @param int|null &$retval Exit code (-1 on internal error)
59 abstract protected function cleanWrapped( $text, $stderr = false, &$retval = null );