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