diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index 1b9ff6ca74..1183f3a85a 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -339,22 +339,17 @@ class VisualEditorHooks { $wgVisualEditorTabMessages, $wgVisualEditorBrowserBlacklist, $wgVisualEditorSupportedSkins, - $wgVisualEditorShowBetaWelcome; + $wgVisualEditorShowBetaWelcome, + $wgVisualEditorPreferenceModules; $vars['wgVisualEditorConfig'] = array( 'disableForAnons' => $wgVisualEditorDisableForAnons, - 'enableExperimentalCode' => $wgVisualEditorEnableExperimentalCode, + 'preferenceModules' => $wgVisualEditorPreferenceModules, 'namespaces' => $wgVisualEditorNamespaces, 'pluginModules' => $wgVisualEditorPluginModules, 'defaultUserOptions' => array( 'betatempdisable' => $wgDefaultUserOptions['visualeditor-betatempdisable'], 'enable' => $wgDefaultUserOptions['visualeditor-enable'], - 'enable-experimental' => $wgDefaultUserOptions['visualeditor-enable-experimental'], -// 'enable-language' => $wgDefaultUserOptions['visualeditor-enable-language'], -// 'enable-mwalienextension' => $wgDefaultUserOptions['visualeditor-enable-mwalienextension'], - 'enable-mwmath' => $wgDefaultUserOptions['visualeditor-enable-mwmath'], -// 'enable-mwhiero' => $wgDefaultUserOptions['visualeditor-enable-mwhiero'], -// 'enable-mwsyntaxHighlight' => $wgDefaultUserOptions['visualeditor-enable-mwsyntaxHighlight'], ), 'blacklist' => $wgVisualEditorBrowserBlacklist, 'skins' => $wgVisualEditorSupportedSkins, @@ -363,6 +358,11 @@ class VisualEditorHooks { 'showBetaWelcome' => $wgVisualEditorShowBetaWelcome, ); + foreach ( $wgVisualEditorPreferenceModules as $pref => $module ) { + $vars['wgVisualEditorConfig']['defaultUserOptions'][$pref] = + $wgDefaultUserOptions[$pref]; + } + return true; } diff --git a/VisualEditor.php b/VisualEditor.php index 21d1c63ffd..26d0ab8f1a 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -871,6 +871,17 @@ $wgResourceModules += array( // loaded. Other extensions that extend VisualEditor should add to this array. $wgVisualEditorPluginModules = array(); +// Array of modules to load based on a preference. Keys are preference names, values are +// ResourceLoader module names. +$wgVisualEditorPreferenceModules = array( + 'visualeditor-enable-experimental' => 'ext.visualEditor.experimental', + //'visualeditor-enable-language' => 'ext.visualEditor.language', + //'visualeditor-enable-mwalienextension' => 'ext.visualEditor.mwalienextension', + 'visualeditor-enable-mwmath' => 'ext.visualEditor.mwmath', + //'visualeditor-enable-mwhiero' => 'ext.visualEditor.mwhiero', + //'visualeditor-enable-mwsyntaxhighlight' => 'ext.visualEditor.mwsyntaxhighlight' +); + // URL to the Parsoid instance // MUST NOT end in a slash due to Parsoid bug $wgVisualEditorParsoidURL = 'http://localhost:8000'; diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js index d448d0415c..a4031b6760 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js @@ -16,21 +16,11 @@ * @constructor */ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() { - var i, - len, - prefName, + var prefName, prefValue, browserWhitelisted, currentUri = new mw.Uri(), - conf = mw.config.get( 'wgVisualEditorConfig' ), - // language, mwalienextension and mwhiero are commented out in VisualEditorHooks::onGetBetaPreferences() - extraModules = [ - 'experimental', - // 'language', - // 'mwalienextension', - // 'mwhiero', - 'mwmath' - ]; + conf = mw.config.get( 'wgVisualEditorConfig' ); // Parent constructor ve.init.mw.Target.call( @@ -74,14 +64,13 @@ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() { */ this.sanityCheckPromise = null; - // Load additional modules - for ( i = 0, len = extraModules.length; i < len; i++ ) { - prefName = 'visualeditor-enable-' + extraModules[i]; + // Load preference modules + for ( prefName in conf.preferenceModules ) { prefValue = mw.config.get( 'wgUserName' ) === null ? conf.defaultUserOptions[prefName] : mw.user.options.get( prefName, conf.defaultUserOptions[prefName] ); if ( prefValue && prefValue !== '0' ) { - this.modules.push( 'ext.visualEditor.' + extraModules[i] ); + this.modules.push( conf.preferenceModules[prefName] ); } }