2011-06-09 21:50:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CodeEditorHooks {
|
2012-02-06 21:59:13 +00:00
|
|
|
static function getPageLanguage( $title ) {
|
|
|
|
// Try CSS/JS
|
|
|
|
if( $title->isCssOrJsPage() ) {
|
|
|
|
if( preg_match( '/\.js$/', $title->getText() ) )
|
|
|
|
return 'javascript';
|
2012-03-09 11:16:23 +00:00
|
|
|
if( preg_match( '/\.css$/', $title->getText() ) )
|
2012-02-06 21:59:13 +00:00
|
|
|
return 'css';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give extensions a chance
|
|
|
|
$lang = null;
|
|
|
|
wfRunHooks( 'CodeEditorGetPageLanguage', array( $title, &$lang ) );
|
|
|
|
|
|
|
|
return $lang;
|
|
|
|
}
|
|
|
|
|
2011-06-09 21:50:45 +00:00
|
|
|
public static function editPageShowEditFormInitial( &$toolbar ) {
|
|
|
|
global $wgOut, $wgTitle;
|
2012-02-06 21:59:13 +00:00
|
|
|
$lang = self::getPageLanguage( $wgTitle );
|
|
|
|
if ( $lang ) {
|
2011-06-09 21:50:45 +00:00
|
|
|
$wgOut->addModules( 'ext.codeEditor' );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-06 21:59:13 +00:00
|
|
|
|
|
|
|
public static function onMakeGlobalVariablesScript( &$vars, $output ) {
|
|
|
|
global $wgTitle;
|
|
|
|
|
|
|
|
$lang = self::getPageLanguage( $wgTitle );
|
|
|
|
if( $lang ) {
|
|
|
|
$vars['wgCodeEditorCurrentLanguage'] = $lang;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-04 22:33:59 +00:00
|
|
|
|
|
|
|
public static function onBeforePageDisplay( $out, $skin ) {
|
|
|
|
global $wgCodeEditorGeshiIntegration;
|
|
|
|
if ( $wgCodeEditorGeshiIntegration ) {
|
|
|
|
$out->addModules( 'ext.codeEditor.geshi' );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-09 21:50:45 +00:00
|
|
|
}
|