MediaWiki REL1_34
CodeEditorHooks.php
Go to the documentation of this file.
1<?php
2
10 public static function getPageLanguage( Title $title, $model, $format ) {
11 if ( $model === CONTENT_MODEL_JAVASCRIPT ) {
12 return 'javascript';
13 } elseif ( $model === CONTENT_MODEL_CSS ) {
14 return 'css';
15 } elseif ( $model === CONTENT_MODEL_JSON ) {
16 return 'json';
17 }
18
19 // Give extensions a chance
20 // Note: $model and $format were added around the time of MediaWiki 1.28.
21 $lang = null;
22 Hooks::run( 'CodeEditorGetPageLanguage', [ $title, &$lang, $model, $format ] );
23
24 return $lang;
25 }
26
31 public static function getPreferences( User $user, &$defaultPreferences ) {
32 $defaultPreferences['usecodeeditor'] = [
33 'type' => 'api',
34 'default' => '1',
35 ];
36 }
37
43 public static function editPageShowEditFormInitial( EditPage $editpage, OutputPage $output ) {
44 global $wgTitle;
45
46 $model = $editpage->contentModel;
47 $format = $editpage->contentFormat;
48
49 $lang = self::getPageLanguage( $wgTitle, $model, $format );
50 if ( $lang && $output->getUser()->getOption( 'usebetatoolbar' ) ) {
51 $output->addModules( 'ext.codeEditor' );
52 $output->addJsConfigVars( 'wgCodeEditorCurrentLanguage', $lang );
53 } elseif ( !ExtensionRegistry::getInstance()->isLoaded( "WikiEditor" ) ) {
54 throw new ErrorPageError( "codeeditor-error-title", "codeeditor-error-message" );
55 }
56 }
57}
if(! $wgRequest->checkUrlExtension()) if(isset( $_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !='') $wgTitle
Definition api.php:58
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:46
An error page which can definitely be safely rendered using the OutputPage.
This is one of the Core classes and should be read at least once by any new developers.
addJsConfigVars( $keys, $value=null)
Add one or more variables to be set in mw.config in JavaScript.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
const CONTENT_MODEL_CSS
Definition Defines.php:226
const CONTENT_MODEL_JSON
Definition Defines.php:228
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:225
if(!isset( $args[0])) $lang