Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryDefaultContentForPage | |
0.00% |
0 / 22 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
20 | |||
getAllowedParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace ProofreadPage\Api; |
4 | |
5 | use ApiQueryBase; |
6 | use MediaWiki\MediaWikiServices; |
7 | use MediaWiki\Title\Title; |
8 | use ProofreadPage\Context; |
9 | use ProofreadPage\Page\PageContentBuilder; |
10 | use ProofreadPage\Page\PageContentHandler; |
11 | |
12 | class ApiQueryDefaultContentForPage extends ApiQueryBase { |
13 | /** |
14 | * @var Context |
15 | */ |
16 | private $context; |
17 | |
18 | /** |
19 | * @var PageContentBuilder |
20 | */ |
21 | private $pageContentBuilder; |
22 | |
23 | /** |
24 | * @var PageContentHandler |
25 | */ |
26 | private $pageContentHandler; |
27 | |
28 | /** @var string API module prefix */ |
29 | private static $prefix = 'prppdefaultcontent'; |
30 | |
31 | /** |
32 | * @param \ApiQuery $query |
33 | * @param string $moduleName |
34 | */ |
35 | public function __construct( $query, $moduleName ) { |
36 | parent::__construct( $query, $moduleName, static::$prefix ); |
37 | $this->context = $this->context = Context::getDefaultContext(); |
38 | $this->pageContentBuilder = new PageContentBuilder( $this, $this->context ); |
39 | $this->pageContentHandler = MediaWikiServices::getInstance() |
40 | ->getContentHandlerFactory() |
41 | ->getContentHandler( CONTENT_MODEL_PROOFREAD_PAGE ); |
42 | } |
43 | |
44 | /** |
45 | * @inheritDoc |
46 | */ |
47 | public function execute() { |
48 | $pageSet = $this->getPageSet()->getGoodAndMissingPages(); |
49 | $result = $this->getResult(); |
50 | |
51 | foreach ( $pageSet as $pageID => $page ) { |
52 | |
53 | if ( $page->getNamespace() !== $this->context->getPageNamespaceId() ) { |
54 | continue; |
55 | } |
56 | |
57 | $title = Title::castFromPageIdentity( $page ); |
58 | |
59 | if ( !$title ) { |
60 | continue; |
61 | } |
62 | |
63 | $result->addValue( [ 'query', 'pages', $pageID ], 'defaultcontentforpage', |
64 | $this->pageContentHandler->serializeContent( |
65 | $this->pageContentBuilder->buildDefaultContentForPageTitle( $title ), |
66 | CONTENT_FORMAT_WIKITEXT |
67 | ) |
68 | ); |
69 | } |
70 | } |
71 | |
72 | /** |
73 | * @inheritDoc |
74 | */ |
75 | protected function getAllowedParams() { |
76 | return []; |
77 | } |
78 | |
79 | /** |
80 | * @inheritDoc |
81 | */ |
82 | public function isInternal() { |
83 | return true; |
84 | } |
85 | } |