Extension:CodeEditor/Hooks/CodeEditorGetPageLanguage
(Redirected from Manual:Hooks/CodeEditorGetPageLanguage)
CodeEditorGetPageLanguage | |
---|---|
Available from version ??? Hook provided for extensions to extend CodeEditor by supporting additional languages |
|
Define function: | public static function onCodeEditorGetPageLanguage( MediaWiki\Title\Title $title, string &$lang, string $model, string $format ) { ... }
|
Attach hook: | $wgHooks['CodeEditorGetPageLanguage'][] = 'MyExtensionHooks::onCodeEditorGetPageLanguage';
|
Called from: | File(s): CodeEditor / CodeEditorHooks.php Function(s): getPageLanguage |
For more information about attaching hooks, see Manual:Hooks .
For examples of other extensions using this hook, see Category:CodeEditorGetPageLanguage extensions.
Details
edit- $title
- Title for the page being edited
- &$lang
- Language the code is in (eg: 'javascript', 'css', 'json')
- $model
- Content model for the page being edited
- $format
- The format used for serialization/deserialization by default by this ContentHandler. This equals EditPage's property $contentFormat, which is equal to ContentHandler::getDefaultFormat().
Example
editScribunto uses this hook as follows:
/**
* @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;
}