mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeEditor
synced 2024-12-02 10:46:32 +00:00
47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
class CodeEditorHooks {
|
|
static function getPageLanguage( $title ) {
|
|
// Try CSS/JS
|
|
if( $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;
|
|
}
|
|
}
|