mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeEditor
synced 2024-11-28 09:00:24 +00:00
64b286d04e
Change-Id: Icccee7461ecff22cbc5076df9f3803b6c2e29f28
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
class CodeEditorHooks {
|
|
static function getPageLanguage( Title $title ) {
|
|
global $wgCodeEditorEnableCore;
|
|
|
|
if ( $wgCodeEditorEnableCore && method_exists( $title, "hasContentModel" ) ) {
|
|
if ( $title->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ) {
|
|
return 'javascript';
|
|
} elseif ( $title->hasContentModel( CONTENT_MODEL_CSS ) ) {
|
|
return 'css';
|
|
} elseif ( $title->hasContentModel( CONTENT_MODEL_JSON ) ) {
|
|
return 'json';
|
|
}
|
|
} elseif ( $wgCodeEditorEnableCore && ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) ) {
|
|
// This block is deprecated. Remove after 1.23 release
|
|
if( preg_match( '/\.js$/', $title->getText() ) )
|
|
return 'javascript';
|
|
if( preg_match( '/\.css$/', $title->getText() ) )
|
|
return 'css';
|
|
}
|
|
|
|
// Give extensions a chance
|
|
$lang = null;
|
|
wfRunHooks( 'CodeEditorGetPageLanguage', array( $title, &$lang ) );
|
|
|
|
return $lang;
|
|
}
|
|
|
|
public static function getPreferences( $user, &$defaultPreferences ) {
|
|
$defaultPreferences['usecodeeditor'] = array(
|
|
'type' => 'api',
|
|
'default' => '1',
|
|
);
|
|
return true;
|
|
}
|
|
|
|
public static function editPageShowEditFormInitial( $editpage, $output ) {
|
|
$lang = self::getPageLanguage( $editpage->getContextTitle() );
|
|
if ( $lang && $output->getUser()->getOption( 'usebetatoolbar' ) ) {
|
|
$output->addModules( 'ext.codeEditor' );
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static function onMakeGlobalVariablesScript( &$vars, $output ) {
|
|
$lang = self::getPageLanguage( $output->getTitle() );
|
|
if( $lang ) {
|
|
$vars['wgCodeEditorCurrentLanguage'] = $lang;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static function onBeforePageDisplay( $out, $skin ) {
|
|
global $wgCodeEditorGeshiIntegration;
|
|
if ( $wgCodeEditorGeshiIntegration ) {
|
|
$out->addModules( 'ext.codeEditor.geshi' );
|
|
}
|
|
return true;
|
|
}
|
|
}
|