Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ParserFunction | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
render | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Chart; |
4 | |
5 | use MediaWiki\Html\Html; |
6 | use MediaWiki\Parser\Parser; |
7 | use MediaWiki\Shell\Shell; |
8 | |
9 | class ParserFunction { |
10 | /** |
11 | * Entry point for the `{{#chart:}}` parser function. |
12 | * |
13 | * @param Parser $parser |
14 | * @return array |
15 | */ |
16 | public function render( Parser $parser ) { |
17 | if ( Shell::isDisabled() ) { |
18 | // TODO i18n |
19 | $error = Html::errorBox( 'Charts cannot be rendered because shell execution is disabled' ); |
20 | return [ $error, 'noparse' => true, 'isHTML' => true ]; |
21 | } |
22 | $dir = dirname( __DIR__ ) . '/cli'; |
23 | $result = Shell::command( |
24 | 'node', |
25 | './dist/index.js', |
26 | 'line', |
27 | // TODO provide input file (or stdin) |
28 | 'data.json', |
29 | '-' |
30 | ) |
31 | ->workingDirectory( dirname( __DIR__ ) . '/cli' ) |
32 | ->execute(); |
33 | // TODO check exit status for error |
34 | $svg = $result->getStdout(); |
35 | // HACK work around a parser bug that inserts <p> tags even though we said not to parse |
36 | $svg = str_replace( ">\n", '>', $svg ); |
37 | // Phan complains that we're outputting HTML that came from a shell command -- but we trust |
38 | // our own shell script |
39 | // @phan-suppress-next-line SecurityCheck-XSS |
40 | return [ "<div class=\"mw-chart\">$svg</div>", 'noparse' => true, 'isHTML' => true ]; |
41 | } |
42 | } |