2011-06-09 21:50:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CodeEditorHooks {
|
2012-02-06 21:59:13 +00:00
|
|
|
static function getPageLanguage( $title ) {
|
2012-08-14 05:04:20 +00:00
|
|
|
global $wgCodeEditorEnableCore;
|
|
|
|
|
2013-12-31 10:20:35 +00:00
|
|
|
if ( $wgCodeEditorEnableCore && method_exists( $title, "getContentModel" ) ) {
|
|
|
|
if ( $title->getContentModel() === CONTENT_MODEL_JAVASCRIPT ) {
|
|
|
|
return 'javascript';
|
|
|
|
} else if ( $title->getContentModel() === CONTENT_MODEL_CSS ) {
|
|
|
|
return 'css';
|
|
|
|
}
|
|
|
|
} elseif( $wgCodeEditorEnableCore && ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) ) {
|
|
|
|
// This block is deprecated. Remove after 1.23 release
|
2012-02-06 21:59:13 +00:00
|
|
|
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
|
|
|
}
|