MediaWiki REL1_30
RaggettExternal.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Tidy;
4
15 protected function cleanWrapped( $text, $stderr = false, &$retval = null ) {
16 $cleansource = '';
17 $opts = ' -utf8';
18
19 if ( $stderr ) {
20 $descriptorspec = [
21 0 => [ 'pipe', 'r' ],
22 1 => [ 'file', wfGetNull(), 'a' ],
23 2 => [ 'pipe', 'w' ]
24 ];
25 } else {
26 $descriptorspec = [
27 0 => [ 'pipe', 'r' ],
28 1 => [ 'pipe', 'w' ],
29 2 => [ 'file', wfGetNull(), 'a' ]
30 ];
31 }
32
33 $readpipe = $stderr ? 2 : 1;
34 $pipes = [];
35
36 $process = proc_open(
37 "{$this->config['tidyBin']} -config {$this->config['tidyConfigFile']} " .
38 $this->config['tidyCommandLine'] . $opts, $descriptorspec, $pipes );
39
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.
42
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 );
50 fclose( $pipes[0] );
51 while ( !feof( $pipes[$readpipe] ) ) {
52 $cleansource .= fgets( $pipes[$readpipe], 1024 );
53 }
54 fclose( $pipes[$readpipe] );
55 $retval = proc_close( $process );
56 } else {
57 wfWarn( "Unable to start external tidy process" );
58 $retval = -1;
59 }
60
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.
64 $cleansource = null;
65 }
66
67 return $cleansource;
68 }
69
70 public function supportsValidate() {
71 return true;
72 }
73}
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfGetNull()
Get a platform-independent path to the null file, e.g.
cleanWrapped( $text, $stderr=false, &$retval=null)
Spawn an external HTML tidy process and get corrected markup back from it.
supportsValidate()
Return true if validate() can be used.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
Definition hooks.txt:266