Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DashikiView | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| valueToHtml | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| renderHeader | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| startsWith | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Dashiki; |
| 4 | |
| 5 | use MediaWiki\Extension\JsonConfig\JCContent; |
| 6 | use MediaWiki\Extension\JsonConfig\JCDefaultContentView; |
| 7 | use MediaWiki\Html\Html; |
| 8 | use MediaWiki\Page\PageReference; |
| 9 | use MediaWiki\Parser\ParserOptions; |
| 10 | use MediaWiki\Parser\ParserOutput; |
| 11 | use MediaWiki\Shell\Shell; |
| 12 | |
| 13 | /** |
| 14 | * Used to render Dashiki JSON configuration pages to HTML |
| 15 | * @package Dashiki |
| 16 | */ |
| 17 | class DashikiView extends JCDefaultContentView { |
| 18 | |
| 19 | /** |
| 20 | * Customizes valueToHtml() for Dashiki |
| 21 | * |
| 22 | * @param JCContent $content |
| 23 | * @param PageReference $page Context page for parsing |
| 24 | * @param int|null $revId Revision ID (for {{REVISIONID}}) |
| 25 | * @param ParserOptions $options Parser options |
| 26 | * @param bool $generateHtml Whether or not to generate HTML |
| 27 | * @param ParserOutput &$output The output object to fill (reference). |
| 28 | * @return string |
| 29 | */ |
| 30 | public function valueToHtml( |
| 31 | JCContent $content, PageReference $page, $revId, ParserOptions $options, $generateHtml, |
| 32 | ParserOutput &$output |
| 33 | ) { |
| 34 | $header = $this->renderHeader( $page->getDBKey() ); |
| 35 | $tableDisplay = parent::valueToHtml( |
| 36 | $content, $page, $revId, $options, $generateHtml, $output |
| 37 | ); |
| 38 | return $header . $tableDisplay; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @param string $dbkey |
| 43 | * @return string HTML |
| 44 | */ |
| 45 | public function renderHeader( $dbkey ) { |
| 46 | $docsLink = Html::element( 'a', [ |
| 47 | 'href' => 'https://wikitech.wikimedia.org/wiki/Analytics/Systems/Dashiki/Configuration' |
| 48 | ], wfMessage( 'parentheses', wfMessage( 'dashiki-configuration-doc-link-text' ) )->text() ); |
| 49 | |
| 50 | if ( $this->startsWith( $dbkey, 'Dashiki:Annotations/' ) ) { |
| 51 | $message = wfMessage( 'dashiki-annotate' )->text(); |
| 52 | $br = Html::element( 'br' ); |
| 53 | $suffix = $br . $br; |
| 54 | } else { |
| 55 | $message = wfMessage( 'dashiki-build' )->text(); |
| 56 | $suffix = Html::element( 'pre', [], |
| 57 | 'gulp --config ' . Shell::escape( $dbkey ) . ' --layout /*...*/' ); |
| 58 | } |
| 59 | |
| 60 | $span = Html::element( 'span', [], $message . ' ' ); |
| 61 | |
| 62 | return $span . $docsLink . $suffix; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @param string $text |
| 67 | * @param string $query |
| 68 | * |
| 69 | * @return bool |
| 70 | */ |
| 71 | private function startsWith( $text, $query ) { |
| 72 | $length = strlen( $query ); |
| 73 | return ( substr( $text, 0, $length ) === $query ); |
| 74 | } |
| 75 | } |