Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CodeEditorHooks | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onCodeEditorGetPageLanguage | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\Gadgets; |
| 4 | |
| 5 | use MediaWiki\Config\Config; |
| 6 | use MediaWiki\Extension\CodeEditor\Hooks\CodeEditorGetPageLanguageHook; |
| 7 | use MediaWiki\Title\Title; |
| 8 | |
| 9 | /** |
| 10 | * Hooks for optional integration with the CodeEditor extension. |
| 11 | */ |
| 12 | class CodeEditorHooks implements CodeEditorGetPageLanguageHook { |
| 13 | |
| 14 | private readonly bool $useCodeEditor; |
| 15 | |
| 16 | public function __construct( |
| 17 | Config $config |
| 18 | ) { |
| 19 | $this->useCodeEditor = $config->get( 'GadgetsDefinitionsUseCodeEditor' ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Set the CodeEditor language for GadgetDefinition pages. |
| 24 | * |
| 25 | * The CodeEditor extension sets the default syntax highlight language based |
| 26 | * on the content model (not page title), so while gadget definitions have ".json" |
| 27 | * page titles, the fact that we use a more specific subclass as content model, |
| 28 | * means we must explicitly opt-in to JSON syntax highlighting. |
| 29 | * |
| 30 | * @param Title $title |
| 31 | * @param string|null &$lang |
| 32 | * @param string $model |
| 33 | * @param string $format |
| 34 | * @return bool |
| 35 | */ |
| 36 | public function onCodeEditorGetPageLanguage( Title $title, ?string &$lang, string $model, string $format ) { |
| 37 | if ( $title->hasContentModel( 'GadgetDefinition' ) && ( |
| 38 | $this->useCodeEditor || |
| 39 | // Temporary code while CodeMirror is still in beta (T373711#11018957). |
| 40 | // If the beta feature is disabled, we want to fallback to using CodeEditor. |
| 41 | // Temporary while CodeMirror is still in beta (T373711#11018957). |
| 42 | !( \MediaWiki\Extension\CodeEditor\Hooks::tempIsCodeMirrorEnabled() ) |
| 43 | ) |
| 44 | ) { |
| 45 | $lang = 'json'; |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | } |