MediaWiki  1.32.5
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 }
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:239
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
CONTENT_MODEL_CSS
const CONTENT_MODEL_CSS
Definition: Defines.php:237
CodeEditorHooks\getPreferences
static getPreferences( $user, &$defaultPreferences)
Definition: CodeEditorHooks.php:36
CodeEditorHooks\editPageShowEditFormInitial
static editPageShowEditFormInitial( $editpage, $output)
Definition: CodeEditorHooks.php:49
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:88
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:964
$output
$output
Definition: SyntaxHighlight.php:334
Title
Represents a title within MediaWiki.
Definition: Title.php:39
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
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