MediaWiki REL1_32
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 e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2317
const CONTENT_MODEL_CSS
Definition Defines.php:237
const CONTENT_MODEL_JSON
Definition Defines.php:239
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:236
if(!isset( $args[0])) $lang