Separate reference preview settings in beta & non-beta

This is the smallest possible patch for a backport.

While it seems there is zero technical reason to limit user
option keys to lowercase with dashes, it's best-practice.
Same as message keys.

Bug: T281235
Change-Id: Ia4a45cf4459543c81b23b757ae9c2cfaf9676894
This commit is contained in:
Thiemo Kreuz 2021-04-27 13:09:31 +02:00
parent 5f850befee
commit 3a00223a36
6 changed files with 18 additions and 7 deletions

View file

@ -56,6 +56,12 @@ class PopupsContext {
*/
public const PREVIEWS_OPTIN_PREFERENCE_NAME = 'popups';
/**
* User preference key to enable/disable Reference Previews. Named
* "mwe-popups-referencePreviews-enabled" in localStorage for anonymous users.
*/
public const REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA = 'popups-reference-previews';
/**
* User preference key to enable/disable Reference Previews
*/
@ -152,7 +158,7 @@ class PopupsContext {
self::REFERENCE_PREVIEWS_PREFERENCE_NAME
);
}
return $user->getBoolOption( self::REFERENCE_PREVIEWS_PREFERENCE_NAME );
return $user->getBoolOption( self::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA );
}
/**

View file

@ -131,7 +131,7 @@ class PopupsHooks {
}
return [
PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME => $option
PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA => $option
];
}
@ -224,7 +224,7 @@ class PopupsHooks {
if ( $config->get( 'PopupsReferencePreviews' ) &&
!$config->get( 'PopupsReferencePreviewsBetaFeature' )
) {
$defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = $default;
$defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA] = $default;
}
}
@ -245,7 +245,7 @@ class PopupsHooks {
if ( $config->get( 'PopupsReferencePreviews' ) &&
!$config->get( 'PopupsReferencePreviewsBetaFeature' )
) {
$user->setOption( PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME, $default );
$user->setOption( PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA, $default );
}
}

Binary file not shown.

Binary file not shown.

View file

@ -33,6 +33,11 @@ export default function isReferencePreviewsEnabled( user, userSettings, config )
return userSettings.isReferencePreviewsEnabled();
}
// TODO: Remove when not in Beta any more
if ( config.get( 'wgPopupsReferencePreviews' ) ) {
return true;
}
// Registered users never can enable popup types at run-time.
return mw.user.options.get( 'popupsreferencepreviews' ) === '1' ? true : null;
return mw.user.options.get( 'popups-reference-previews' ) === '1' ? true : null;
}

View file

@ -288,7 +288,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
$this->assertCount( 3 - $beta, $userOptions );
$this->assertSame( '1', $userOptions[ PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] );
if ( $beta === false ) {
$this->assertSame( '1', $userOptions[ PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME ] );
$this->assertSame( '1', $userOptions[ PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA ] );
}
}
@ -304,7 +304,7 @@ class PopupsHooksTest extends MediaWikiTestCase {
->method( 'setOption' )
->withConsecutive(
[ 'popups', $expectedState ],
[ 'popupsreferencepreviews', $expectedState ]
[ 'popups-reference-previews', $expectedState ]
);
$this->setMwGlobals( [