blob: da83e39eaefedc4a5149152cafd9b701a6704c8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?php
namespace Mediawiki\Api\Service;
use GuzzleHttp\Promise\PromiseInterface;
use Mediawiki\Api\SimpleRequest;
use Mediawiki\DataModel\PageIdentifier;
/**
* @access private
*
* @author Addshore
*/
class Parser extends Service {
/**
* @param PageIdentifier $pageIdentifier
*
* @return array the parse result (raw from the api)
*/
public function parsePage( PageIdentifier $pageIdentifier ) {
return $this->parsePageAsync( $pageIdentifier )->wait();
}
/**
* @param PageIdentifier $pageIdentifier
*
* @return PromiseInterface of array the parse result (raw from the api)
*/
public function parsePageAsync( PageIdentifier $pageIdentifier ) {
$params = [];
if ( $pageIdentifier->getId() !== null ) {
$params['pageid'] = $pageIdentifier->getId();
} elseif ( $pageIdentifier->getTitle() !== null ) {
$params['page'] = $pageIdentifier->getTitle()->getText();
} else {
throw new \RuntimeException( 'No way to identify page' );
}
$promise = $this->api->getRequestAsync( new SimpleRequest( 'parse', $params ) );
return $promise->then( function ( $result ) {
return $result['parse'];
} );
}
}
|