2023-08-15 11:42:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\Scribunto;
|
|
|
|
|
2024-03-10 13:34:21 +00:00
|
|
|
use MediaWiki\Config\Config;
|
2023-08-15 11:42:58 +00:00
|
|
|
use MediaWiki\Extension\CodeEditor\Hooks\CodeEditorGetPageLanguageHook;
|
|
|
|
use MediaWiki\Title\Title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hooks from CodeEditor extension,
|
|
|
|
* which is optional to use with this extension.
|
|
|
|
*/
|
|
|
|
class CodeEditorHooks implements CodeEditorGetPageLanguageHook {
|
|
|
|
|
2024-03-10 13:34:21 +00:00
|
|
|
private bool $useCodeEditor;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
Config $config
|
|
|
|
) {
|
|
|
|
$this->useCodeEditor = $config->get( 'ScribuntoUseCodeEditor' );
|
|
|
|
}
|
|
|
|
|
2023-08-15 11:42:58 +00:00
|
|
|
/**
|
|
|
|
* @param Title $title
|
|
|
|
* @param string|null &$languageCode
|
|
|
|
* @param string $model
|
|
|
|
* @param string $format
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function onCodeEditorGetPageLanguage( Title $title, ?string &$languageCode, string $model, string $format ) {
|
2024-03-10 13:34:21 +00:00
|
|
|
if ( $this->useCodeEditor && $title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
2023-08-15 11:42:58 +00:00
|
|
|
$engine = Scribunto::newDefaultEngine();
|
|
|
|
if ( $engine->getCodeEditorLanguage() ) {
|
|
|
|
$languageCode = $engine->getCodeEditorLanguage();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|