mediawiki-extensions-CodeMi.../CodeMirror.hooks.php
Pavel Astakhov 30a3ae4319 add highlighting double underscore Magic words (v 1.12.0)
Change-Id: I4eceaa790ca053de49f5d0983bdd8ae288ba985f
2014-09-04 10:23:05 +06:00

58 lines
1.8 KiB
PHP

<?php
class CodeMirrorHooks {
static $globalVariableScript = array();
/**
*
* @global Parser $wgParser
* @global Language $wgContLang
* @param EditPage $editPage
* @param OutputPage $output
* @return boolean
*/
public static function onEditPageShowEditFormInitial( EditPage $editPage, OutputPage $output ) {
global $wgParser, $wgContLang;
if ( false === isset( $wgParser->mFunctionSynonyms ) ) {
$wgParser->initialiseVariables();
$wgParser->firstCallInit();
}
self::$globalVariableScript['Tags'] = $wgParser->getTags();
$mw = $wgContLang->getMagicWords();
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;
}
}
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;
}
}
}
// self::$globalVariableScript['LinkTrailCharacters'] = $wgContLang->linkTrail();
$output->addModules( 'ext.CodeMirror' );
return true;
}
public static function onMakeGlobalVariablesScript( array &$vars ) {
foreach ( self::$globalVariableScript as $key=> $value ) {
$vars["extCodeMirror$key"] = $value;
}
}
}