mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeEditor
synced 2024-11-30 18:04:27 +00:00
ce1cfd6a0e
The test for $title->isCssJsSubpage() seems to have gotten lost in the refactoring in r110794, so enabling CodeEditor for core only affects the MediaWiki namespace. This restores that test, so user css/js subpages also get CodeEditor when $wgCodeEditorEnableCore is true. Change-Id: Id02825f922a1ed0aace7c9ffd940fe8d29bb5d79
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
class CodeEditorHooks {
|
|
static function getPageLanguage( $title ) {
|
|
global $wgCodeEditorEnableCore;
|
|
|
|
// Try CSS/JS
|
|
if( $wgCodeEditorEnableCore && ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) ) {
|
|
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 editPageShowEditFormInitial( &$toolbar ) {
|
|
global $wgOut, $wgTitle;
|
|
$lang = self::getPageLanguage( $wgTitle );
|
|
if ( $lang ) {
|
|
$wgOut->addModules( 'ext.codeEditor' );
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static function onMakeGlobalVariablesScript( &$vars, $output ) {
|
|
global $wgTitle;
|
|
|
|
$lang = self::getPageLanguage( $wgTitle );
|
|
if( $lang ) {
|
|
$vars['wgCodeEditorCurrentLanguage'] = $lang;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static function onBeforePageDisplay( $out, $skin ) {
|
|
global $wgCodeEditorGeshiIntegration;
|
|
if ( $wgCodeEditorGeshiIntegration ) {
|
|
$out->addModules( 'ext.codeEditor.geshi' );
|
|
}
|
|
return true;
|
|
}
|
|
}
|