3 namespace MediaWiki\Tidy
;
6 * @deprecated since 1.32, use RemexDriver
8 class RaggettExternal
extends RaggettBase
{
10 * Spawn an external HTML tidy process and get corrected markup back from it.
11 * Also called in OutputHandler.php for full page validation
13 * @param string $text HTML to check
14 * @param bool $stderr Whether to read result from STDERR rather than STDOUT
15 * @param int|null &$retval Exit code (-1 on internal error)
18 protected function cleanWrapped( $text, $stderr = false, &$retval = null ) {
25 1 => [ 'file', wfGetNull(), 'a' ],
32 2 => [ 'file', wfGetNull(), 'a' ]
36 $readpipe = $stderr ?
2 : 1;
40 "{$this->config['tidyBin']} -config {$this->config['tidyConfigFile']} " .
41 $this->config
['tidyCommandLine'] . $opts, $descriptorspec, $pipes );
43 // NOTE: At least on linux, the process will be created even if tidy is not installed.
44 // This means that missing tidy will be treated as a validation failure.
46 if ( is_resource( $process ) ) {
47 // Theoretically, this style of communication could cause a deadlock
48 // here. If the stdout buffer fills up, then writes to stdin could
49 // block. This doesn't appear to happen with tidy, because tidy only
50 // writes to stdout after it's finished reading from stdin. Search
51 // for tidyParseStdin and tidySaveStdout in console/tidy.c
52 fwrite( $pipes[0], $text );
54 while ( !feof( $pipes[$readpipe] ) ) {
55 $cleansource .= fgets( $pipes[$readpipe], 1024 );
57 fclose( $pipes[$readpipe] );
58 $retval = proc_close( $process );
60 wfWarn( "Unable to start external tidy process" );
64 if ( !$stderr && $cleansource == '' && $text != '' ) {
65 // Some kind of error happened, so we couldn't get the corrected text.
66 // Just give up; we'll use the source text and append a warning.
73 public function supportsValidate() {