Merge "Drop zh-tw message "saveprefs""
[lhc/web/wiklou.git] / includes / tidy / RaggettBase.php
1 <?php
2
3 namespace MediaWiki\Tidy;
4
5 abstract class RaggettBase extends TidyDriverBase {
6 /**
7 * Generic interface for wrapping and unwrapping HTML for Dave Raggett's tidy.
8 *
9 * @param string $text Hideous HTML input
10 * @return string Corrected HTML output
11 */
12 public function tidy( $text ) {
13 $wrapper = new RaggettWrapper;
14 $wrappedtext = $wrapper->getWrapped( $text );
15
16 $retVal = null;
17 $correctedtext = $this->cleanWrapped( $wrappedtext, false, $retVal );
18
19 if ( $retVal < 0 ) {
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";
25 }
26
27 $correctedtext = $wrapper->postprocess( $correctedtext ); // restore any hidden tokens
28
29 return $correctedtext;
30 }
31
32 public function validate( $text, &$errorStr ) {
33 $retval = 0;
34 $errorStr = $this->cleanWrapped( $text, true, $retval );
35 return ( $retval < 0 && $errorStr == '' ) || $retval == 0;
36 }
37
38 /**
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)
43 * @return null|string
44 * @throws MWException
45 */
46 abstract protected function cleanWrapped( $text, $stderr = false, &$retval = null );
47 }