MediaWiki
REL1_31
CodeEditorHooks.php
Go to the documentation of this file.
1
<?php
2
3
class
CodeEditorHooks
{
10
public
static
function
getPageLanguage
(
Title
$title, $model, $format ) {
11
global $wgCodeEditorEnableCore;
12
13
if
( $wgCodeEditorEnableCore ) {
14
if
( $model ===
CONTENT_MODEL_JAVASCRIPT
) {
15
return
'javascript'
;
16
} elseif ( $model ===
CONTENT_MODEL_CSS
) {
17
return
'css'
;
18
} elseif ( $model ===
CONTENT_MODEL_JSON
) {
19
return
'json'
;
20
}
21
}
22
23
// Give extensions a chance
24
// Note: $model and $format were added around the time of MediaWiki 1.28.
25
$lang
=
null
;
26
Hooks::run(
'CodeEditorGetPageLanguage'
, [ $title, &
$lang
, $model, $format ] );
27
28
return
$lang
;
29
}
30
36
public
static
function
getPreferences
( $user, &$defaultPreferences ) {
37
$defaultPreferences[
'usecodeeditor'
] = [
38
'type'
=>
'api'
,
39
'default'
=>
'1'
,
40
];
41
return
true
;
42
}
43
49
public
static
function
editPageShowEditFormInitial
( $editpage,
$output
) {
50
$title = $editpage->getContextTitle();
51
$model = $editpage->contentModel;
52
$format = $editpage->contentFormat;
53
54
$lang
=
self::getPageLanguage
( $title, $model, $format );
55
if
(
$lang
&&
$output
->getUser()->getOption(
'usebetatoolbar'
) ) {
56
$output
->addModules(
'ext.codeEditor'
);
57
$output
->addJsConfigVars(
'wgCodeEditorCurrentLanguage'
,
$lang
);
58
} elseif ( !
ExtensionRegistry::getInstance
()->isLoaded(
"WikiEditor"
) ) {
59
throw
new
ErrorPageError
(
"codeeditor-error-title"
,
"codeeditor-error-message"
);
60
}
61
return
true
;
62
}
63
}
CodeEditorHooks
Definition
CodeEditorHooks.php:3
CodeEditorHooks\getPageLanguage
static getPageLanguage(Title $title, $model, $format)
Definition
CodeEditorHooks.php:10
CodeEditorHooks\editPageShowEditFormInitial
static editPageShowEditFormInitial( $editpage, $output)
Definition
CodeEditorHooks.php:49
CodeEditorHooks\getPreferences
static getPreferences( $user, &$defaultPreferences)
Definition
CodeEditorHooks.php:36
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition
ErrorPageError.php:27
ExtensionRegistry\getInstance
static getInstance()
Definition
ExtensionRegistry.php:88
Title
Represents a title within MediaWiki.
Definition
Title.php:39
$output
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition
hooks.txt:2255
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition
Defines.php:247
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition
Defines.php:249
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition
Defines.php:246
$lang
if(!isset( $args[0])) $lang
Definition
testCompression.php:33
extensions
CodeEditor
includes
CodeEditorHooks.php
Generated on Mon Nov 25 2024 15:34:15 for MediaWiki by
1.10.0