2014-08-20 17:03:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
class CodeMirrorHooks {
|
|
|
|
|
2014-08-29 04:05:50 +00:00
|
|
|
static $globalVariableScript = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @global Parser $wgParser
|
2014-09-04 03:37:11 +00:00
|
|
|
* @global Language $wgContLang
|
2014-08-29 04:05:50 +00:00
|
|
|
* @param EditPage $editPage
|
|
|
|
* @param OutputPage $output
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2014-08-20 17:03:46 +00:00
|
|
|
public static function onEditPageShowEditFormInitial( EditPage $editPage, OutputPage $output ) {
|
2014-09-04 03:37:11 +00:00
|
|
|
global $wgParser, $wgContLang;
|
2014-10-23 06:09:10 +00:00
|
|
|
|
|
|
|
self::$globalVariableScript['ExtMode'] = array(
|
|
|
|
'tag' => array(
|
|
|
|
'pre' => 'mw-tag-pre',
|
|
|
|
'nowiki' => 'mw-tag-nowiki',
|
|
|
|
),
|
|
|
|
'func' => array(),
|
|
|
|
'data' => array()
|
|
|
|
);
|
|
|
|
\wfRunHooks( 'CodeMirrorGetExtensionMode', array( &self::$globalVariableScript['ExtMode'], &$module, &$output ) );
|
|
|
|
|
2014-08-29 04:05:50 +00:00
|
|
|
if ( false === isset( $wgParser->mFunctionSynonyms ) ) {
|
2014-09-04 03:37:11 +00:00
|
|
|
$wgParser->initialiseVariables();
|
2014-08-29 04:05:50 +00:00
|
|
|
$wgParser->firstCallInit();
|
|
|
|
}
|
2014-10-23 06:09:10 +00:00
|
|
|
self::$globalVariableScript['Tags'] = array_fill_keys( $wgParser->getTags(), true );
|
2014-09-04 03:37:11 +00:00
|
|
|
|
|
|
|
$mw = $wgContLang->getMagicWords();
|
2014-09-04 04:23:05 +00:00
|
|
|
self::$globalVariableScript['DoubleUnderscore'] = array( array(), array() );
|
|
|
|
foreach ( MagicWord::getDoubleUnderscoreArray()->names as $name ) {
|
|
|
|
if ( isset( $mw[$name] ) ) {
|
|
|
|
$caseSensitive = array_shift( $mw[$name] ) == 0 ? 0 : 1;
|
|
|
|
foreach ( $mw[$name] as $n ) {
|
|
|
|
self::$globalVariableScript['DoubleUnderscore'][$caseSensitive][ $caseSensitive ? $n : $wgContLang->lc( $n ) ] = $name;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self::$globalVariableScript['DoubleUnderscore'][0][] = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-04 03:37:11 +00:00
|
|
|
self::$globalVariableScript['FunctionSynonyms'] = $wgParser->mFunctionSynonyms;
|
|
|
|
foreach ( MagicWord::getVariableIDs() as $name ) {
|
|
|
|
if ( isset( $mw[$name] ) ) {
|
|
|
|
$caseSensitive = array_shift( $mw[$name] ) == 0 ? 0 : 1;
|
|
|
|
foreach ( $mw[$name] as $n ) {
|
|
|
|
self::$globalVariableScript['FunctionSynonyms'][$caseSensitive][ $caseSensitive ? $n : $wgContLang->lc( $n ) ] = $name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-10 10:09:49 +00:00
|
|
|
self::$globalVariableScript['UrlProtocols'] = $wgParser->mUrlProtocols;// wfUrlProtocolsWithoutProtRel();
|
2014-09-04 04:23:05 +00:00
|
|
|
// self::$globalVariableScript['LinkTrailCharacters'] = $wgContLang->linkTrail();
|
2014-10-23 06:09:10 +00:00
|
|
|
$output->addModules( 'ext.CodeMirror.init' );
|
2014-08-20 17:03:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-03 05:04:56 +00:00
|
|
|
public static function onMakeGlobalVariablesScript( array &$vars ) {
|
2014-08-29 04:05:50 +00:00
|
|
|
foreach ( self::$globalVariableScript as $key=> $value ) {
|
|
|
|
$vars["extCodeMirror$key"] = $value;
|
|
|
|
}
|
|
|
|
}
|
2014-10-23 06:09:10 +00:00
|
|
|
|
|
|
|
public static function getPreferences( $user, &$defaultPreferences ) {
|
|
|
|
$defaultPreferences['usecodemirror'] = array(
|
|
|
|
'type' => 'api',
|
|
|
|
'default' => '1',
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
2014-08-20 17:03:46 +00:00
|
|
|
}
|