2011-06-09 21:50:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CodeEditorHooks {
|
2014-10-07 19:56:16 +00:00
|
|
|
static function getPageLanguage( Title $title ) {
|
2012-08-14 05:04:20 +00:00
|
|
|
global $wgCodeEditorEnableCore;
|
|
|
|
|
2014-10-07 19:56:16 +00:00
|
|
|
if ( $wgCodeEditorEnableCore && method_exists( $title, "hasContentModel" ) ) {
|
|
|
|
if ( $title->hasContentModel( CONTENT_MODEL_JAVASCRIPT ) ) {
|
2013-12-31 10:20:35 +00:00
|
|
|
return 'javascript';
|
2014-10-07 19:56:16 +00:00
|
|
|
} elseif ( $title->hasContentModel( CONTENT_MODEL_CSS ) ) {
|
2013-12-31 10:20:35 +00:00
|
|
|
return 'css';
|
2014-10-07 19:56:16 +00:00
|
|
|
} elseif ( $title->hasContentModel( CONTENT_MODEL_JSON ) ) {
|
|
|
|
return 'json';
|
2013-12-31 10:20:35 +00:00
|
|
|
}
|
2014-10-07 19:56:16 +00:00
|
|
|
} elseif ( $wgCodeEditorEnableCore && ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) ) {
|
2013-12-31 10:20:35 +00:00
|
|
|
// 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';
|
|
|
|
}
|
2014-10-29 17:22:42 +00:00
|
|
|
|
2012-02-06 21:59:13 +00:00
|
|
|
// Give extensions a chance
|
|
|
|
$lang = null;
|
|
|
|
wfRunHooks( 'CodeEditorGetPageLanguage', array( $title, &$lang ) );
|
2014-10-29 17:22:42 +00:00
|
|
|
|
2012-02-06 21:59:13 +00:00
|
|
|
return $lang;
|
|
|
|
}
|
2014-04-28 13:31:57 +00:00
|
|
|
|
|
|
|
public static function getPreferences( $user, &$defaultPreferences ) {
|
|
|
|
$defaultPreferences['usecodeeditor'] = array(
|
|
|
|
'type' => 'api',
|
|
|
|
'default' => '1',
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-29 17:22:42 +00:00
|
|
|
|
2014-02-05 18:30:22 +00:00
|
|
|
public static function editPageShowEditFormInitial( $editpage, $output ) {
|
|
|
|
$lang = self::getPageLanguage( $editpage->getContextTitle() );
|
2014-04-28 13:31:57 +00:00
|
|
|
if ( $lang && $output->getUser()->getOption( 'usebetatoolbar' ) ) {
|
2014-02-05 18:30:22 +00:00
|
|
|
$output->addModules( 'ext.codeEditor' );
|
2011-06-09 21:50:45 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-06 21:59:13 +00:00
|
|
|
|
|
|
|
public static function onMakeGlobalVariablesScript( &$vars, $output ) {
|
2014-02-05 18:30:22 +00:00
|
|
|
$lang = self::getPageLanguage( $output->getTitle() );
|
2012-02-06 21:59:13 +00:00
|
|
|
if( $lang ) {
|
|
|
|
$vars['wgCodeEditorCurrentLanguage'] = $lang;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-29 17:22:42 +00:00
|
|
|
|
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
|
|
|
}
|