mediawiki-extensions-CodeEd.../CodeEditor.hooks.php
Brad Jorsch ce1cfd6a0e Use CodeEditor for user css/js subpages
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
2013-05-20 20:56:50 +00:00

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;
}
}