mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-27 15:40:00 +00:00
925775778a
Add new temporary ext.CodeMirror.visualEditor.init RL module which selects the temporary ext.CodeMirror.visualEditor.v6 or non-v6 based on $wgCodeMirrorV6. This will allow us to deploy CM6 further. As a result of this work, the core CodeMirror class now has knowledge of ve.ui.Surface. Other changes: * Add Compartment for specialCharsExtension so it can be disabled in VE. * Add option to mediaWikiLang() to disable template folding. * Add support for RTL wikis where $wgCodeMirrorRTL is enabled. * Make CodeMirror.logUsage() and setCodeMirrorPreference() static. * Fix unit and linting tests. Some code courtesy of Fandom, GPLv2-or-later; see: https://github.com/Wikia/mediawiki-extensions-CodeMirror/commit/ef297c48c Bug: T357482 Change-Id: I15453b33e77e1c1b4d5e5183e41e53d56ff14c3e
101 lines
3.4 KiB
PHP
101 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* ResourceLoader callback for ext.CodeMirror.data module
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
namespace MediaWiki\Extension\CodeMirror;
|
|
|
|
use ExtensionRegistry;
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\ResourceLoader as RL;
|
|
use MediaWiki\ResourceLoader\ResourceLoader;
|
|
|
|
/**
|
|
* ResourceLoader callback for ext.CodeMirror.data
|
|
*/
|
|
class DataScript {
|
|
/**
|
|
* @param RL\Context $context
|
|
* @return string
|
|
*/
|
|
public static function makeScript( RL\Context $context ) {
|
|
return ResourceLoader::makeConfigSetScript(
|
|
[ 'extCodeMirrorConfig' => self::getFrontendConfiguraton() ]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns an array of variables for CodeMirror to work (tags and so on)
|
|
*
|
|
* @return array
|
|
*/
|
|
private static function getFrontendConfiguraton() {
|
|
// Use the content language, not the user language. (See T170130.)
|
|
$lang = MediaWikiServices::getInstance()->getContentLanguage();
|
|
$registry = ExtensionRegistry::getInstance();
|
|
$parser = MediaWikiServices::getInstance()->getParser();
|
|
$mwConfig = MediaWikiServices::getInstance()->getMainConfig();
|
|
|
|
$tagModes = $registry->getAttribute( 'CodeMirrorTagModes' );
|
|
$tagNames = array_merge( $parser->getTags(), array_keys( $tagModes ) );
|
|
|
|
// initialize configuration
|
|
$config = [
|
|
'useV6' => $mwConfig->get( 'CodeMirrorV6' ),
|
|
'lineNumberingNamespaces' => $mwConfig->get( 'CodeMirrorLineNumberingNamespaces' ),
|
|
'templateFoldingNamespaces' => $mwConfig->get( 'CodeMirrorTemplateFoldingNamespaces' ),
|
|
'isSupportedRtlWiki' => $mwConfig->get( 'CodeMirrorRTL' ),
|
|
'pluginModules' => $registry->getAttribute( 'CodeMirrorPluginModules' ),
|
|
'tagModes' => $tagModes,
|
|
'tags' => array_fill_keys( $tagNames, true ),
|
|
'doubleUnderscore' => [ [], [] ],
|
|
'functionSynonyms' => $parser->getFunctionSynonyms(),
|
|
'urlProtocols' => $parser->getUrlProtocols(),
|
|
'linkTrailCharacters' => $lang->linkTrail(),
|
|
];
|
|
|
|
$mw = $lang->getMagicWords();
|
|
$magicWordFactory = $parser->getMagicWordFactory();
|
|
foreach ( $magicWordFactory->getDoubleUnderscoreArray()->getNames() as $name ) {
|
|
if ( isset( $mw[$name] ) ) {
|
|
$caseSensitive = array_shift( $mw[$name] ) == 0 ? 0 : 1;
|
|
foreach ( $mw[$name] as $n ) {
|
|
$n = $caseSensitive ? $n : $lang->lc( $n );
|
|
$config['doubleUnderscore'][$caseSensitive][$n] = $name;
|
|
}
|
|
} else {
|
|
$config['doubleUnderscore'][0][] = $name;
|
|
}
|
|
}
|
|
|
|
foreach ( $magicWordFactory->getVariableIDs() as $name ) {
|
|
if ( isset( $mw[$name] ) ) {
|
|
$caseSensitive = array_shift( $mw[$name] ) == 0 ? 0 : 1;
|
|
foreach ( $mw[$name] as $n ) {
|
|
$n = $caseSensitive ? $n : $lang->lc( $n );
|
|
$config['functionSynonyms'][$caseSensitive][$n] = $name;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $config;
|
|
}
|
|
}
|