Add option to disable CodeMirror frontend

So CodeMirror only provides it's libraries to use in other code.

Change-Id: I6832f4d82ae0497b92ba210ac7960052e4e12143
This commit is contained in:
Florian 2015-03-26 18:25:15 +01:00
parent c911e6d003
commit 6bd068ca90
2 changed files with 21 additions and 8 deletions

View file

@ -66,13 +66,16 @@ class CodeMirrorHooks {
* @return boolean
*/
private static function isCodeMirrorEnabled( IContextSource $context ) {
global $wgCodeMirrorEnableFrontend;
// Check, if we already checked, if page action is editing, if not, do it now
if ( is_null( self::$isEnabled ) ) {
// edit can be 'edit' and 'submit'
self::$isEnabled = in_array(
Action::getActionName( $context ),
array( 'edit', 'submit' )
);
self::$isEnabled = $wgCodeMirrorEnableFrontend &&
in_array(
Action::getActionName( $context ),
array( 'edit', 'submit' )
);
}
return self::$isEnabled;
@ -176,10 +179,12 @@ class CodeMirrorHooks {
* @return bool Always true
*/
public static function onGetPreferences( User $user, &$defaultPreferences ) {
$defaultPreferences['usecodemirror'] = array(
'type' => 'api',
'default' => '1',
);
if ( self::isCodeMirrorEnabled( RequestContext::getMain() ) ) {
$defaultPreferences['usecodemirror'] = array(
'type' => 'api',
'default' => '1',
);
}
return true;
}
}

View file

@ -71,3 +71,11 @@ $wgResourceModules['ext.CodeMirror.lib'] = $wgCodeMirrorResourceTemplate + array
'group' => 'ext.CodeMirror',
'targets' => array( 'mobile', 'desktop' ),
);
// Configuration options
/**
* Specify, if CodeMirror extension should integrate CodeMirror in MediaWiki's editor (or WikiEditor), or if
* it should work as a library provider for other extensions.
*/
$wgCodeMirrorEnableFrontend = true;