| 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 |
|
| 11 |
|
| 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 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
} |