mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-11 17:01:00 +00:00
2a45dbb577
Also use private instead of public for internal function reportTiming. Change-Id: I52c301d11244436ddc142ec84a7c6740a4ea4d32
43 lines
1 KiB
PHP
43 lines
1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Scribunto;
|
|
|
|
use MediaWiki\Config\Config;
|
|
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 {
|
|
|
|
private bool $useCodeEditor;
|
|
|
|
public function __construct(
|
|
Config $config
|
|
) {
|
|
$this->useCodeEditor = $config->get( 'ScribuntoUseCodeEditor' );
|
|
}
|
|
|
|
/**
|
|
* @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 ) {
|
|
if ( $this->useCodeEditor && $title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
|
|
$engine = Scribunto::newDefaultEngine();
|
|
if ( $engine->getCodeEditorLanguage() ) {
|
|
$languageCode = $engine->getCodeEditorLanguage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|