From 3a00223a3637d51427ed019492e58c512651f41d Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Tue, 27 Apr 2021 13:09:31 +0200 Subject: [PATCH] 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 --- includes/PopupsContext.php | 8 +++++++- includes/PopupsHooks.php | 6 +++--- resources/dist/index.js | Bin 45111 -> 45151 bytes resources/dist/index.js.map.json | Bin 214884 -> 215031 bytes src/isReferencePreviewsEnabled.js | 7 ++++++- tests/phpunit/PopupsHooksTest.php | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/includes/PopupsContext.php b/includes/PopupsContext.php index 7a09fc907..699d406f9 100644 --- a/includes/PopupsContext.php +++ b/includes/PopupsContext.php @@ -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 ); } /** diff --git a/includes/PopupsHooks.php b/includes/PopupsHooks.php index 7a2ea10f4..f96d871b8 100644 --- a/includes/PopupsHooks.php +++ b/includes/PopupsHooks.php @@ -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 ); } } diff --git a/resources/dist/index.js b/resources/dist/index.js index b19f61c5656df8b82bf4cd54b5e7a5c5b20afb94..82e34429f6355a0e2b20774d43fed4870a9aae21 100644 GIT binary patch delta 43 zcmdn~fa(4NrVS;_m=zWCCMQP7vnXlS)J)D?s>rQdl$w@Wl$w{Es=ImKvYDI!f07XS delta 28 kcmccrfNA>!rVS;_CTA{H~^`dCsNwIhPo>&$+~;n>n5BDx>~%D=TKv q>G2ATqSJR4K_kSNp(XkO+i6&L^YFf(H;ymLP0?`Lo7={Y(i>-vC@aJ r(gC-z(gH1MmrgbVVGwdassertCount( 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( [