mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeEditor
synced 2024-11-14 19:14:41 +00:00
1787861005
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
49 lines
1.1 KiB
PHP
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;
|
|
}
|
|
}
|