Debian Codegraph @

extensions/Scribunto/includes/CodeEditorHooks.php

raw symbols SCIP
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 }