PHPSessionHandler: Implement SessionHandlerInterface
[mediawiki.git] / includes / tidy / Html5Depurate.php
blobe2187f071ac926c0fae5c0da507f6c33fecd0168
1 <?php
3 namespace MediaWiki\Tidy;
5 use MWHttpRequest;
6 use Exception;
8 class Html5Depurate extends TidyDriverBase {
9 public function __construct( array $config ) {
10 parent::__construct( $config + array(
11 'url' => 'http://localhost:4339/document',
12 'timeout' => 10,
13 'connectTimeout' => 0.5,
14 ) );
17 public function tidy( $text ) {
18 $wrappedtext = '<!DOCTYPE html><html>' .
19 '<body>' . $text . '</body></html>';
21 $req = MWHttpRequest::factory( $this->config['url'],
22 array(
23 'method' => 'POST',
24 'timeout' => $this->config['timeout'],
25 'connectTimeout' => $this->config['connectTimeout'],
26 'postData' => array(
27 'text' => $wrappedtext
29 ) );
30 $status = $req->execute();
31 if ( !$status->isOK() ) {
32 throw new Exception( "Error contacting depurate service: " . $status->getWikiText() );
33 } elseif ( $req->getStatus() !== 200 ) {
34 throw new Exception( "Depurate returned error: " . $status->getWikiText() );
36 $result = $req->getContent();
37 $startBody = strpos( $result, "<body>" );
38 $endBody = strrpos( $result, "</body>" );
39 if ( $startBody !== false && $endBody !== false && $endBody > $startBody ) {
40 $startBody += strlen( "<body>" );
41 return substr( $result, $startBody, $endBody - $startBody );
42 } else {
43 return $text . "\n<!-- Html5Depurate returned an invalid result -->";