MediaWiki  1.32.5
RaggettExternal.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Tidy;
4 
8 class RaggettExternal extends RaggettBase {
18  protected function cleanWrapped( $text, $stderr = false, &$retval = null ) {
19  $cleansource = '';
20  $opts = ' -utf8';
21 
22  if ( $stderr ) {
23  $descriptorspec = [
24  0 => [ 'pipe', 'r' ],
25  1 => [ 'file', wfGetNull(), 'a' ],
26  2 => [ 'pipe', 'w' ]
27  ];
28  } else {
29  $descriptorspec = [
30  0 => [ 'pipe', 'r' ],
31  1 => [ 'pipe', 'w' ],
32  2 => [ 'file', wfGetNull(), 'a' ]
33  ];
34  }
35 
36  $readpipe = $stderr ? 2 : 1;
37  $pipes = [];
38 
39  $process = proc_open(
40  "{$this->config['tidyBin']} -config {$this->config['tidyConfigFile']} " .
41  $this->config['tidyCommandLine'] . $opts, $descriptorspec, $pipes );
42 
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.
45 
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 );
53  fclose( $pipes[0] );
54  while ( !feof( $pipes[$readpipe] ) ) {
55  $cleansource .= fgets( $pipes[$readpipe], 1024 );
56  }
57  fclose( $pipes[$readpipe] );
58  $retval = proc_close( $process );
59  } else {
60  wfWarn( "Unable to start external tidy process" );
61  $retval = -1;
62  }
63 
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.
67  $cleansource = null;
68  }
69 
70  return $cleansource;
71  }
72 
73  public function supportsValidate() {
74  return true;
75  }
76 }
MediaWiki\Tidy\RaggettBase
Definition: RaggettBase.php:10
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Tidy\RaggettExternal
Definition: RaggettExternal.php:8
$retval
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 account incomplete not yet checked for validity & $retval
Definition: hooks.txt:244
wfGetNull
wfGetNull()
Get a platform-independent path to the null file, e.g.
Definition: GlobalFunctions.php:2821
MediaWiki\Tidy\RaggettExternal\supportsValidate
supportsValidate()
Return true if validate() can be used.
Definition: RaggettExternal.php:73
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1132
MediaWiki\Tidy
Definition: RaggettBase.php:3
MediaWiki\Tidy\RaggettExternal\cleanWrapped
cleanWrapped( $text, $stderr=false, &$retval=null)
Spawn an external HTML tidy process and get corrected markup back from it.
Definition: RaggettExternal.php:18