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\Scribunto; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | use MediaWiki\Extension\CodeEditor\Hooks\CodeEditorGetPageLanguageHook; |
7 | use MediaWiki\Title\Title; |
8 | |
9 | /** |
10 | * Hooks from CodeEditor extension, |
11 | * which is optional to use with this extension. |
12 | */ |
13 | class CodeEditorHooks implements CodeEditorGetPageLanguageHook { |
14 | |
15 | private bool $useCodeEditor; |
16 | |
17 | public function __construct( |
18 | Config $config |
19 | ) { |
20 | $this->useCodeEditor = $config->get( 'ScribuntoUseCodeEditor' ); |
21 | } |
22 | |
23 | /** |
24 | * @param Title $title |
25 | * @param string|null &$languageCode |
26 | * @param string $model |
27 | * @param string $format |
28 | * @return bool |
29 | */ |
30 | public function onCodeEditorGetPageLanguage( Title $title, ?string &$languageCode, string $model, string $format ) { |
31 | if ( $this->useCodeEditor && $title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) { |
32 | $engine = Scribunto::newDefaultEngine(); |
33 | if ( $engine->getCodeEditorLanguage() ) { |
34 | $languageCode = $engine->getCodeEditorLanguage(); |
35 | return false; |
36 | } |
37 | } |
38 | |
39 | return true; |
40 | } |
41 | |
42 | } |