Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
CampaignContentHandler | |
0.00% |
0 / 19 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getContentClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
makeEmptyContent | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
fillParserOutput | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
generateHtml | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\UploadWizard; |
4 | |
5 | use Content; |
6 | use JsonContentHandler; |
7 | use MediaWiki\Content\Renderer\ContentParseParams; |
8 | use MediaWiki\Parser\ParserOutput; |
9 | use MediaWiki\Title\Title; |
10 | use UnexpectedValueException; |
11 | |
12 | /** |
13 | * JSON Schema Content Handler |
14 | * |
15 | * @file |
16 | * @ingroup Extensions |
17 | * @ingroup UploadWizard |
18 | * |
19 | * @author Ori Livneh <ori@wikimedia.org> |
20 | * @author Yuvi Panda <yuvipanda@gmail.com> |
21 | */ |
22 | |
23 | class CampaignContentHandler extends JsonContentHandler { |
24 | |
25 | /** |
26 | * @param string $modelId |
27 | */ |
28 | public function __construct( $modelId = 'Campaign' ) { |
29 | parent::__construct( $modelId ); |
30 | } |
31 | |
32 | /** |
33 | * @return class-string<CampaignContent> |
34 | */ |
35 | protected function getContentClass() { |
36 | return CampaignContent::class; |
37 | } |
38 | |
39 | /** |
40 | * @return CampaignContent |
41 | */ |
42 | public function makeEmptyContent() { |
43 | $class = $this->getContentClass(); |
44 | return new $class( '{"enabled":false}' ); |
45 | } |
46 | |
47 | /** |
48 | * @inheritDoc |
49 | */ |
50 | protected function fillParserOutput( |
51 | Content $content, |
52 | ContentParseParams $cpoParams, |
53 | ParserOutput &$parserOutput |
54 | ) { |
55 | '@phan-var CampaignContent $content'; |
56 | $title = Title::castFromPageReference( $cpoParams->getPage() ); |
57 | if ( $title === null ) { |
58 | throw new UnexpectedValueException( '$title shouldn\'t be NULL' ); |
59 | } |
60 | |
61 | $campaign = new Campaign( $title, $content->getJsonData() ); |
62 | |
63 | if ( $cpoParams->getGenerateHtml() ) { |
64 | $html = $this->generateHtml( $campaign ); |
65 | $parserOutput->setText( $html ); |
66 | } |
67 | |
68 | // Register template usage |
69 | // FIXME: should we be registering other stuff?? |
70 | foreach ( $campaign->getTemplates() as $ns => $templates ) { |
71 | foreach ( $templates as $dbk => $ids ) { |
72 | $title = Title::makeTitle( $ns, $dbk ); |
73 | $parserOutput->addTemplate( $title, $ids[0], $ids[1] ); |
74 | } |
75 | } |
76 | |
77 | $parserOutput->addModuleStyles( [ 'ext.uploadWizard.uploadCampaign.display' ] ); |
78 | } |
79 | |
80 | /** |
81 | * @param Campaign $campaign |
82 | * |
83 | * @return string |
84 | */ |
85 | private function generateHtml( $campaign ) { |
86 | $formatter = new CampaignPageFormatter( $campaign ); |
87 | |
88 | return $formatter->generateReadHtml(); |
89 | } |
90 | } |