Merge "Simplify HTMLTitleTextField::validate"
[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 function __construct( $config ) {
13 parent::__construct( $config );
14
15 // All tidy modes other than remex are deprecated.
16 wfDeprecated( __METHOD__, '1.32' );
17 }
18
19 /**
20 * Generic interface for wrapping and unwrapping HTML for Dave Raggett's tidy.
21 *
22 * @param string $text Hideous HTML input
23 * @return string Corrected HTML output
24 */
25 public function tidy( $text ) {
26 $wrapper = new RaggettWrapper;
27 $wrappedtext = $wrapper->getWrapped( $text );
28
29 $retVal = null;
30 $correctedtext = $this->cleanWrapped( $wrappedtext, false, $retVal );
31
32 if ( $retVal < 0 ) {
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";
38 }
39
40 $correctedtext = $wrapper->postprocess( $correctedtext ); // restore any hidden tokens
41
42 return $correctedtext;
43 }
44
45 public function validate( $text, &$errorStr ) {
46 $retval = 0;
47 $errorStr = $this->cleanWrapped( $text, true, $retval );
48 return ( $retval < 0 && $errorStr == '' ) || $retval == 0;
49 }
50
51 /**
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)
56 * @return null|string
57 * @throws MWException
58 */
59 abstract protected function cleanWrapped( $text, $stderr = false, &$retval = null );
60 }