MediaWiki  1.33.0
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 
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 }
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:239
CodeEditorHooks\getPreferences
static getPreferences(User $user, &$defaultPreferences)
Definition: CodeEditorHooks.php:35
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:237
EditPage\getContextTitle
getContextTitle()
Get the context title object.
Definition: EditPage.php:536
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ExtensionRegistry\getInstance
static getInstance()
Definition: ExtensionRegistry.php:98
CodeEditorHooks\getPageLanguage
static getPageLanguage(Title $title, $model, $format)
Definition: CodeEditorHooks.php:10
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
$output
$output
Definition: SyntaxHighlight.php:334
CodeEditorHooks\editPageShowEditFormInitial
static editPageShowEditFormInitial(EditPage $editpage, OutputPage $output)
Definition: CodeEditorHooks.php:47
EditPage
The edit page/HTML interface (split from Article) The actual database and text munging is still in Ar...
Definition: EditPage.php:44
Title
Represents a title within MediaWiki.
Definition: Title.php:40
CONTENT_MODEL_JAVASCRIPT
const CONTENT_MODEL_JAVASCRIPT
Definition: Defines.php:236
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:48
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