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