2011-06-09 21:50:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CodeEditorHooks {
|
2016-12-13 18:01:34 +00:00
|
|
|
/**
|
|
|
|
* @param Title $title
|
2017-10-11 19:01:37 +00:00
|
|
|
* @param string $model
|
|
|
|
* @param string $format
|
2016-12-13 18:01:34 +00:00
|
|
|
* @return null|string
|
|
|
|
*/
|
2018-04-14 01:24:49 +00:00
|
|
|
public static function getPageLanguage( Title $title, $model, $format ) {
|
2019-07-12 17:58:50 +00:00
|
|
|
if ( $model === CONTENT_MODEL_JAVASCRIPT ) {
|
|
|
|
return 'javascript';
|
|
|
|
} elseif ( $model === CONTENT_MODEL_CSS ) {
|
|
|
|
return 'css';
|
|
|
|
} elseif ( $model === CONTENT_MODEL_JSON ) {
|
|
|
|
return 'json';
|
2012-02-06 21:59:13 +00:00
|
|
|
}
|
2014-10-29 17:22:42 +00:00
|
|
|
|
2012-02-06 21:59:13 +00:00
|
|
|
// Give extensions a chance
|
2016-07-17 05:34:15 +00:00
|
|
|
// Note: $model and $format were added around the time of MediaWiki 1.28.
|
2012-02-06 21:59:13 +00:00
|
|
|
$lang = null;
|
2016-07-17 05:34:15 +00:00
|
|
|
Hooks::run( 'CodeEditorGetPageLanguage', [ $title, &$lang, $model, $format ] );
|
2014-10-29 17:22:42 +00:00
|
|
|
|
2012-02-06 21:59:13 +00:00
|
|
|
return $lang;
|
|
|
|
}
|
2014-04-28 13:31:57 +00:00
|
|
|
|
2016-12-13 18:01:34 +00:00
|
|
|
/**
|
2017-10-11 19:01:37 +00:00
|
|
|
* @param User $user
|
|
|
|
* @param array &$defaultPreferences
|
2016-12-13 18:01:34 +00:00
|
|
|
*/
|
2018-12-16 11:04:49 +00:00
|
|
|
public static function getPreferences( User $user, &$defaultPreferences ) {
|
2016-05-09 23:37:08 +00:00
|
|
|
$defaultPreferences['usecodeeditor'] = [
|
2014-04-28 13:31:57 +00:00
|
|
|
'type' => 'api',
|
|
|
|
'default' => '1',
|
2016-05-09 23:37:08 +00:00
|
|
|
];
|
2014-04-28 13:31:57 +00:00
|
|
|
}
|
2014-10-29 17:22:42 +00:00
|
|
|
|
2016-12-13 18:01:34 +00:00
|
|
|
/**
|
|
|
|
* @param EditPage $editpage
|
|
|
|
* @param OutputPage $output
|
2019-02-02 09:05:09 +00:00
|
|
|
* @throws ErrorPageError
|
2016-12-13 18:01:34 +00:00
|
|
|
*/
|
2018-12-16 11:04:49 +00:00
|
|
|
public static function editPageShowEditFormInitial( EditPage $editpage, OutputPage $output ) {
|
2019-09-30 17:29:06 +00:00
|
|
|
global $wgTitle;
|
|
|
|
|
2016-07-17 05:34:15 +00:00
|
|
|
$model = $editpage->contentModel;
|
|
|
|
$format = $editpage->contentFormat;
|
|
|
|
|
2019-09-30 17:29:06 +00:00
|
|
|
$lang = self::getPageLanguage( $wgTitle, $model, $format );
|
2014-04-28 13:31:57 +00:00
|
|
|
if ( $lang && $output->getUser()->getOption( 'usebetatoolbar' ) ) {
|
2014-02-05 18:30:22 +00:00
|
|
|
$output->addModules( 'ext.codeEditor' );
|
2016-07-17 05:34:15 +00:00
|
|
|
$output->addJsConfigVars( 'wgCodeEditorCurrentLanguage', $lang );
|
2017-02-04 21:35:13 +00:00
|
|
|
} elseif ( !ExtensionRegistry::getInstance()->isLoaded( "WikiEditor" ) ) {
|
|
|
|
throw new ErrorPageError( "codeeditor-error-title", "codeeditor-error-message" );
|
2012-02-06 21:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-09 21:50:45 +00:00
|
|
|
}
|