mediawiki-extensions-CodeEd.../CodeEditor.hooks.php
Tim Starling 1787861005 Allow core functionality of CodeEditor to be disabled.
Scribunto requires that the CodeEditor extension be installed, but I
haven't reviewed CodeEditor for its primary use case, i.e. CSS and
JS. The automatic brace close feature in JS mode might be annoying for
some. I'm ready to deploy Scribunto but the CodeEditor core
functionality will need to be deployed separately.

Change-Id: I0d423563cc13f9f8ec00590c8e16273d10f1dbce
2012-08-14 15:04:20 +10:00

49 lines
1.1 KiB
PHP

<?php
class CodeEditorHooks {
static function getPageLanguage( $title ) {
global $wgCodeEditorEnableCore;
// Try CSS/JS
if( $wgCodeEditorEnableCore && $title->isCssOrJsPage() ) {
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;
}
}