Merge "selenium: invoke jobs to enforce eventual consistency"
[lhc/web/wiklou.git] / includes / tidy / RaggettInternalPHP.php
1 <?php
2
3 namespace MediaWiki\Tidy;
4
5 /**
6 * @deprecated since 1.32, use RemexDriver
7 */
8 class RaggettInternalPHP extends RaggettBase {
9 /**
10 * Use the HTML tidy extension to use the tidy library in-process,
11 * saving the overhead of spawning a new process.
12 *
13 * @param string $text HTML to check
14 * @param bool $stderr Whether to read result from error status instead of output
15 * @param int|null &$retval Exit code (-1 on internal error)
16 * @return string|null
17 */
18 protected function cleanWrapped( $text, $stderr = false, &$retval = null ) {
19 if ( !class_exists( 'tidy' ) ) {
20 wfWarn( "Unable to load internal tidy class." );
21 $retval = -1;
22
23 return null;
24 }
25
26 $tidy = new \tidy;
27 $tidy->parseString( $text, $this->config['tidyConfigFile'], 'utf8' );
28
29 if ( $stderr ) {
30 $retval = $tidy->getStatus();
31 return $tidy->errorBuffer;
32 }
33
34 $tidy->cleanRepair();
35 $retval = $tidy->getStatus();
36 if ( $retval == 2 ) {
37 // 2 is magic number for fatal error
38 // https://secure.php.net/manual/en/tidy.getstatus.php
39 $cleansource = null;
40 } else {
41 $cleansource = tidy_get_output( $tidy );
42 if ( !empty( $this->config['debugComment'] ) && $retval > 0 ) {
43 $cleansource .= "<!--\nTidy reports:\n" .
44 str_replace( '-->', '--&gt;', $tidy->errorBuffer ) .
45 "\n-->";
46 }
47 }
48
49 return $cleansource;
50 }
51
52 public function supportsValidate() {
53 return true;
54 }
55 }