diff --git a/includes/Hooks.php b/includes/Hooks.php index d025350a..723718f7 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -164,10 +164,17 @@ class Hooks implements * @todo Remove check for cm6enable flag after migration is complete */ private function shouldUseV6( OutputPage $out ): bool { - return $this->useV6 || $out->getRequest()->getRawVal( 'cm6enable' ) || ( - ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) && - BetaFeatures::isFeatureEnabled( $out->getUser(), 'codemirror-beta-feature-enable' ) - ); + return $this->useV6 || $out->getRequest()->getBool( 'cm6enable' ) || + $this->isBetaFeatureEnabled( $out->getUser() ); + } + + /** + * @param User $user + * @return bool + */ + private function isBetaFeatureEnabled( User $user ): bool { + return ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) && + BetaFeatures::isFeatureEnabled( $user, 'codemirror-beta-feature-enable' ); } /** @@ -194,7 +201,7 @@ class Hooks implements * @return bool|void True or no return value to continue or false to abort */ public function onGetPreferences( $user, &$defaultPreferences ) { - if ( !$this->useV6 ) { + if ( !$this->useV6 && !$this->isBetaFeatureEnabled( $user ) ) { $defaultPreferences['usecodemirror'] = [ 'type' => 'api', ]; diff --git a/resources/ve-cm/ve.ui.CodeMirror.init.js b/resources/ve-cm/ve.ui.CodeMirror.init.js index 0e6fd479..cff23cde 100644 --- a/resources/ve-cm/ve.ui.CodeMirror.init.js +++ b/resources/ve-cm/ve.ui.CodeMirror.init.js @@ -7,9 +7,12 @@ require( '../ext.CodeMirror.data.js' ); // TODO: Change the PluginModules in extension.json when fully migrated to v6 and drop this. mw.hook( 've.loadModules' ).add( ( addPlugin ) => { const urlParams = new URLSearchParams( window.location.search ); + const shouldUseV6 = mw.config.get( 'extCodeMirrorConfig' ).useV6 || + urlParams.get( 'cm6enable' ) || + mw.user.options.get( 'codemirror-beta-feature-enable' ) === '1'; // VE would wait for plugin callbacks to resolve before initialisation. - if ( mw.config.get( 'extCodeMirrorConfig' ).useV6 || urlParams.get( 'cm6enable' ) ) { + if ( shouldUseV6 ) { addPlugin( () => mw.loader.using( 'ext.CodeMirror.v6.visualEditor' ) ); } else { addPlugin( () => mw.loader.using( 'ext.CodeMirror.visualEditor' ) );