MediaWiki REL1_31
CodeEditorHooks.php
Go to the documentation of this file.
1<?php
2
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}
static getPageLanguage(Title $title, $model, $format)
static editPageShowEditFormInitial( $editpage, $output)
static getPreferences( $user, &$defaultPreferences)
An error page which can definitely be safely rendered using the OutputPage.
Represents a title within MediaWiki.
Definition Title.php:39
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
const CONTENT_MODEL_CSS
Definition Defines.php:247
const CONTENT_MODEL_JSON
Definition Defines.php:249
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:246
if(!isset( $args[0])) $lang