Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
JCContentView | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
valueToHtml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
0 | |||
getDefault | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getLicenseIntro | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace JsonConfig; |
4 | |
5 | use MediaWiki\MediaWikiServices; |
6 | use MediaWiki\Page\PageReference; |
7 | use MediaWiki\Parser\ParserOutput; |
8 | use ParserOptions; |
9 | |
10 | /** |
11 | * This class is used as a way to specify how to edit/view JCContent object |
12 | * To use it, set $wgJsonConfigModels[$modelId]['view'] = 'MyJCContentViewClass'; |
13 | * @package JsonConfig |
14 | */ |
15 | abstract class JCContentView { |
16 | |
17 | /** |
18 | * Render JCContent object as HTML |
19 | * Called from an override of AbstractContent::fillParserOutput() |
20 | * |
21 | * Render JCContent object as HTML - replaces valueToHtml() |
22 | * @param JCContent $content |
23 | * @param PageReference $page Context title 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 | abstract public function valueToHtml( |
31 | JCContent $content, PageReference $page, $revId, ParserOptions $options, $generateHtml, |
32 | ParserOutput &$output ); |
33 | |
34 | /** |
35 | * Returns default content for this object. |
36 | * The returned valued does not have to be valid JSON |
37 | * @param string $modelId |
38 | * @return string |
39 | */ |
40 | abstract public function getDefault( $modelId ); |
41 | |
42 | /** |
43 | * Returns default content for licenses introduction |
44 | * The returned valued does not have to be valid JSON |
45 | * @return string |
46 | */ |
47 | public static function getLicenseIntro() { |
48 | $allowedLicenses = ''; |
49 | $supLicenses = MediaWikiServices::getInstance()->getMainConfig()->get( 'JsonConfigAllowedLicenses' ); |
50 | foreach ( $supLicenses as $supLicense ) { |
51 | $licenseName = wfMessage( 'jsonconfig-license-name-' . $supLicense )->plain(); |
52 | $allowedLicenses .= ' // "license": "' . $supLicense . '", // ' . $licenseName . PHP_EOL; |
53 | } |
54 | |
55 | return <<<EOT |
56 | // Mandatory "license" field. |
57 | // Recommended license: CC0-1.0. |
58 | // Please uncomment one of the licenses: |
59 | $allowedLicenses |
60 | EOT; |
61 | } |
62 | } |