Merge "Hooks: ensure GetPreferences hook and 2017 editor respect beta feature"

This commit is contained in:
jenkins-bot 2024-12-10 11:56:17 +00:00 committed by Gerrit Code Review
commit 30d17a62a6
2 changed files with 16 additions and 6 deletions

View file

@ -164,10 +164,17 @@ class Hooks implements
* @todo Remove check for cm6enable flag after migration is complete * @todo Remove check for cm6enable flag after migration is complete
*/ */
private function shouldUseV6( OutputPage $out ): bool { private function shouldUseV6( OutputPage $out ): bool {
return $this->useV6 || $out->getRequest()->getRawVal( 'cm6enable' ) || ( return $this->useV6 || $out->getRequest()->getBool( 'cm6enable' ) ||
ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) && $this->isBetaFeatureEnabled( $out->getUser() );
BetaFeatures::isFeatureEnabled( $out->getUser(), 'codemirror-beta-feature-enable' ) }
);
/**
* @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 * @return bool|void True or no return value to continue or false to abort
*/ */
public function onGetPreferences( $user, &$defaultPreferences ) { public function onGetPreferences( $user, &$defaultPreferences ) {
if ( !$this->useV6 ) { if ( !$this->useV6 && !$this->isBetaFeatureEnabled( $user ) ) {
$defaultPreferences['usecodemirror'] = [ $defaultPreferences['usecodemirror'] = [
'type' => 'api', 'type' => 'api',
]; ];

View file

@ -7,9 +7,12 @@ require( '../ext.CodeMirror.data.js' );
// TODO: Change the PluginModules in extension.json when fully migrated to v6 and drop this. // TODO: Change the PluginModules in extension.json when fully migrated to v6 and drop this.
mw.hook( 've.loadModules' ).add( ( addPlugin ) => { mw.hook( 've.loadModules' ).add( ( addPlugin ) => {
const urlParams = new URLSearchParams( window.location.search ); 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. // 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' ) ); addPlugin( () => mw.loader.using( 'ext.CodeMirror.v6.visualEditor' ) );
} else { } else {
addPlugin( () => mw.loader.using( 'ext.CodeMirror.visualEditor' ) ); addPlugin( () => mw.loader.using( 'ext.CodeMirror.visualEditor' ) );