Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
CodeEditorHooks | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
onCodeEditorGetPageLanguage | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Gadgets; |
4 | |
5 | use MediaWiki\Extension\CodeEditor\Hooks\CodeEditorGetPageLanguageHook; |
6 | use MediaWiki\Title\Title; |
7 | |
8 | /** |
9 | * Hooks for optional integration with the CodeEditor extension. |
10 | */ |
11 | class CodeEditorHooks implements CodeEditorGetPageLanguageHook { |
12 | |
13 | /** |
14 | * Set the CodeEditor language for GadgetDefinition pages. |
15 | * |
16 | * The CodeEditor extension sets the default syntax highlight language based |
17 | * on the content model (not page title), so while gadget definitions have ".json" |
18 | * page titles, the fact that we use a more specific subclass as content model, |
19 | * means we must explicitly opt-in to JSON syntax highlighting. |
20 | * |
21 | * @param Title $title |
22 | * @param string|null &$lang |
23 | * @param string $model |
24 | * @param string $format |
25 | * @return bool |
26 | */ |
27 | public function onCodeEditorGetPageLanguage( Title $title, ?string &$lang, string $model, string $format ) { |
28 | if ( $title->hasContentModel( 'GadgetDefinition' ) ) { |
29 | $lang = 'json'; |
30 | return false; |
31 | } |
32 | |
33 | return true; |
34 | } |
35 | |
36 | } |