Merge "selenium: invoke jobs to enforce eventual consistency"
[lhc/web/wiklou.git] / includes / tidy / RaggettBase.php
1 <?php
2
3 namespace MediaWiki\Tidy;
4
5 use MWException;
6
7 /**
8 * @deprecated since 1.32, use RemexDriver
9 */
10 abstract class RaggettBase extends TidyDriverBase {
11 /**
12 * Generic interface for wrapping and unwrapping HTML for Dave Raggett's tidy.
13 *
14 * @param string $text Hideous HTML input
15 * @return string Corrected HTML output
16 */
17 public function tidy( $text ) {
18 $wrapper = new RaggettWrapper;
19 $wrappedtext = $wrapper->getWrapped( $text );
20
21 $retVal = null;
22 $correctedtext = $this->cleanWrapped( $wrappedtext, false, $retVal );
23
24 if ( $retVal < 0 ) {
25 wfDebug( "Possible tidy configuration error!\n" );
26 return $text . "\n<!-- Tidy was unable to run -->\n";
27 } elseif ( is_null( $correctedtext ) ) {
28 wfDebug( "Tidy error detected!\n" );
29 return $text . "\n<!-- Tidy found serious XHTML errors -->\n";
30 }
31
32 $correctedtext = $wrapper->postprocess( $correctedtext ); // restore any hidden tokens
33
34 return $correctedtext;
35 }
36
37 public function validate( $text, &$errorStr ) {
38 $retval = 0;
39 $errorStr = $this->cleanWrapped( $text, true, $retval );
40 return ( $retval < 0 && $errorStr == '' ) || $retval == 0;
41 }
42
43 /**
44 * Perform a clean/repair operation
45 * @param string $text HTML to check
46 * @param bool $stderr Whether to read result from STDERR rather than STDOUT
47 * @param int|null &$retval Exit code (-1 on internal error)
48 * @return null|string
49 * @throws MWException
50 */
51 abstract protected function cleanWrapped( $text, $stderr = false, &$retval = null );
52 }