MediaWiki  1.34.0
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 }
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:219
CodeEditorHooks\getPreferences
static getPreferences(User $user, &$defaultPreferences)
Definition: CodeEditorHooks.php:31
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:217
$wgTitle
if(! $wgRequest->checkUrlExtension()) if(isset( $_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] !='') $wgTitle
Definition: api.php:58
ExtensionRegistry\getInstance
static getInstance()
Definition: ExtensionRegistry.php:106
CodeEditorHooks\getPageLanguage
static getPageLanguage(Title $title, $model, $format)
Definition: CodeEditorHooks.php:10
$title
$title
Definition: testCompression.php:34
$output
$output
Definition: SyntaxHighlight.php:335
CodeEditorHooks\editPageShowEditFormInitial
static editPageShowEditFormInitial(EditPage $editpage, OutputPage $output)
Definition: CodeEditorHooks.php:43
EditPage
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:46
Title
Represents a title within MediaWiki.
Definition: Title.php:42
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:216
ErrorPageError
An error page which can definitely be safely rendered using the OutputPage.
Definition: ErrorPageError.php:27
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
CodeEditorHooks
Definition: CodeEditorHooks.php:3