Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
JCChartContentView | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
valueToHtml | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
6 | |||
getDefault | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Chart; |
4 | |
5 | use JsonConfig\JCContent; |
6 | use JsonConfig\JCContentView; |
7 | use MediaWiki\Context\RequestContext; |
8 | use MediaWiki\Languages\LanguageFactory; |
9 | use MediaWiki\Logger\LoggerFactory; |
10 | use MediaWiki\MediaWikiServices; |
11 | use MediaWiki\Page\PageReference; |
12 | use MediaWiki\Parser\ParserOptions; |
13 | use MediaWiki\Parser\ParserOutput; |
14 | use MediaWiki\Title\Title; |
15 | |
16 | class JCChartContentView extends JCContentView { |
17 | |
18 | private ChartRenderer $chartRenderer; |
19 | |
20 | private LanguageFactory $languageFactory; |
21 | |
22 | public function __construct( ChartRenderer $chartRenderer, LanguageFactory $languageFactory ) { |
23 | $this->chartRenderer = $chartRenderer; |
24 | $this->languageFactory = $languageFactory; |
25 | } |
26 | |
27 | /** |
28 | * @param JCContent $content |
29 | * @param PageReference $page |
30 | * @param int|null $revId |
31 | * @param ParserOptions $options |
32 | * @param bool $generateHtml |
33 | * @param ParserOutput &$output |
34 | * @return string |
35 | */ |
36 | public function valueToHtml( |
37 | JCContent $content, |
38 | PageReference $page, |
39 | $revId, |
40 | ParserOptions $options, |
41 | $generateHtml, |
42 | ParserOutput &$output |
43 | ): string { |
44 | $logger = LoggerFactory::getInstance( 'Chart' ); |
45 | $chartArgumentsParser = MediaWikiServices::getInstance()->getService( 'Chart.ChartArgumentsParser' ); |
46 | $dataPageResolver = MediaWikiServices::getInstance()->getService( 'Chart.DataPageResolver' ); |
47 | |
48 | '@phan-var JCChartContent $content'; |
49 | $lang = $this->languageFactory->getLanguage( $output->getLanguage() ?? |
50 | Title::newFromPageReference( $page )->getPageLanguage() |
51 | ); |
52 | $context = new RequestContext(); |
53 | $context->setLanguage( $lang ); |
54 | $statusFormatter = MediaWikiServices::getInstance()->getFormatterFactory() |
55 | ->getStatusFormatter( $context ); |
56 | |
57 | $parserFunction = new ParserFunction( |
58 | $this->chartRenderer, |
59 | $lang, |
60 | $chartArgumentsParser, |
61 | $dataPageResolver, |
62 | $logger, |
63 | $statusFormatter, |
64 | $page |
65 | ); |
66 | |
67 | $status = $parserFunction->renderChartForDefinitionContent( $output, $content ); |
68 | if ( $status->isOK() ) { |
69 | return $status->getValue(); |
70 | } else { |
71 | return $parserFunction->renderStatus( $status ); |
72 | } |
73 | } |
74 | |
75 | /** |
76 | * @inheritDoc |
77 | */ |
78 | public function getDefault( $modelId ): string { |
79 | $licenseIntro = JCContentView::getLicenseIntro(); |
80 | return <<<JSON |
81 | { |
82 | // !!!!! All comments will be automatically deleted on save !!!!! |
83 | "version": 1, |
84 | |
85 | $licenseIntro, |
86 | |
87 | // Name of a tabular data page to use as the data source. Can be overridden on each page that uses the chart. |
88 | "source": "Example.tab", |
89 | |
90 | // Chart type. Available types are: line |
91 | "type": "line", |
92 | |
93 | // Axis labels and other axis settings |
94 | "xAxis": { |
95 | "title": { |
96 | "en": "X axis label" |
97 | } |
98 | }, |
99 | "yAxis": { |
100 | "title": { |
101 | "en": "Y axis label" |
102 | } |
103 | } |
104 | |
105 | // Other chart parameters, these are specific to each chart type |
106 | } |
107 | JSON; |
108 | } |
109 | } |