MediaWiki REL1_33
CodeEditorHooks.php
Go to the documentation of this file.
1<?php
2
10 public static function getPageLanguage( Title $title, $model, $format ) {
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
35 public static function getPreferences( User $user, &$defaultPreferences ) {
36 $defaultPreferences['usecodeeditor'] = [
37 'type' => 'api',
38 'default' => '1',
39 ];
40 }
41
47 public static function editPageShowEditFormInitial( EditPage $editpage, OutputPage $output ) {
48 $title = $editpage->getContextTitle();
49 $model = $editpage->contentModel;
50 $format = $editpage->contentFormat;
51
52 $lang = self::getPageLanguage( $title, $model, $format );
53 if ( $lang && $output->getUser()->getOption( 'usebetatoolbar' ) ) {
54 $output->addModules( 'ext.codeEditor' );
55 $output->addJsConfigVars( 'wgCodeEditorCurrentLanguage', $lang );
56 } elseif ( !ExtensionRegistry::getInstance()->isLoaded( "WikiEditor" ) ) {
57 throw new ErrorPageError( "codeeditor-error-title", "codeeditor-error-message" );
58 }
59 }
60}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
static getPageLanguage(Title $title, $model, $format)
static editPageShowEditFormInitial(EditPage $editpage, OutputPage $output)
static getPreferences(User $user, &$defaultPreferences)
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition EditPage.php:44
An error page which can definitely be safely rendered using the OutputPage.
This class should be covered by a general architecture document which does not exist as of January 20...
Represents a title within MediaWiki.
Definition Title.php:40
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
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:2272
const CONTENT_MODEL_CSS
Definition Defines.php:246
const CONTENT_MODEL_JSON
Definition Defines.php:248
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:245
if(!isset( $args[0])) $lang