From 7596165a5d0fa84e253f44ea1f9f2e3b439f53d3 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Fri, 24 Nov 2023 12:51:41 +0100 Subject: [PATCH] Fix confusing constant names in PHP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The …AFTER_BETA constant is the one we want to keep after we removed all BetaFeature code. The naming scheme is just confusing. Safe to rename. Not used anywhere else: https://codesearch.wmcloud.org/search/?q=REFERENCE_PREVIEWS_PREFERENCE_NAME We also decided to keep the $wgPopupsReferencePreviews feature flag. Update the documentation accordingly. This is split from I1556b2f to make it easier to review. Bug: T351708 Change-Id: Ifbb41156f2a5a4d8a81e79f613754869c5c89690 --- extension.json | 2 +- includes/PopupsContext.php | 9 ++++----- includes/PopupsHooks.php | 8 ++++---- tests/phpunit/PopupsHooksTest.php | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/extension.json b/extension.json index 205d8d44b..e1b40a9c7 100644 --- a/extension.json +++ b/extension.json @@ -83,7 +83,7 @@ "value": "/api/rest_v1/page/summary/" }, "PopupsReferencePreviews": { - "description": "Temporary feature flag to disable reference previews during developement.", + "description": "Feature flag to enable or disable the separate popup type for references created via the Cite extension's tag.", "value": true }, "PopupsReferencePreviewsBetaFeature": { diff --git a/includes/PopupsContext.php b/includes/PopupsContext.php index 72c21be24..ab7688e59 100644 --- a/includes/PopupsContext.php +++ b/includes/PopupsContext.php @@ -61,12 +61,12 @@ class PopupsContext { * 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'; + public const REFERENCE_PREVIEWS_PREFERENCE_NAME = 'popups-reference-previews'; /** * User preference key to enable/disable Reference Previews */ - public const REFERENCE_PREVIEWS_PREFERENCE_NAME = 'popupsreferencepreviews'; + public const REFERENCE_PREVIEWS_BETA_PREFERENCE_NAME = 'popupsreferencepreviews'; /** * Flags passed on to JS representing preferences @@ -159,7 +159,6 @@ class PopupsContext { * @return bool whether or not to show reference previews */ public function isReferencePreviewsEnabled( \User $user ) { - // TODO: Remove when the feature flag is not needed any more if ( !$this->config->get( 'PopupsReferencePreviews' ) ) { return false; } @@ -168,12 +167,12 @@ class PopupsContext { if ( $this->isReferencePreviewsInBeta() ) { return BetaFeatures::isFeatureEnabled( $user, - self::REFERENCE_PREVIEWS_PREFERENCE_NAME + self::REFERENCE_PREVIEWS_BETA_PREFERENCE_NAME ); } return !$user->isNamed() || $this->userOptionsLookup->getBoolOption( - $user, self::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA + $user, self::REFERENCE_PREVIEWS_PREFERENCE_NAME ); } diff --git a/includes/PopupsHooks.php b/includes/PopupsHooks.php index 2a3f47007..06ecfe4d5 100644 --- a/includes/PopupsHooks.php +++ b/includes/PopupsHooks.php @@ -171,7 +171,7 @@ class PopupsHooks implements } return [ - PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA => $option + PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME => $option ]; } @@ -263,7 +263,7 @@ class PopupsHooks implements if ( $config->get( 'PopupsReferencePreviews' ) && !$config->get( 'PopupsReferencePreviewsBetaFeature' ) ) { - $defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA] = '1'; + $defaultOptions[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = '1'; } } @@ -290,7 +290,7 @@ class PopupsHooks implements ) { $this->userOptionsManager->setOption( $user, - PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME_AFTER_BETA, + PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME, $default ); } @@ -310,7 +310,7 @@ class PopupsHooks implements if ( $config->get( 'PopupsReferencePreviewsBetaFeature' ) && $config->get( 'PopupsReferencePreviews' ) ) { - $prefs[PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME] = [ + $prefs[PopupsContext::REFERENCE_PREVIEWS_BETA_PREFERENCE_NAME] = [ 'label-message' => 'popups-refpreview-beta-feature-message', 'desc-message' => 'popups-refpreview-beta-feature-description', 'screenshot' => [ diff --git a/tests/phpunit/PopupsHooksTest.php b/tests/phpunit/PopupsHooksTest.php index bd0adde44..3efaeacca 100644 --- a/tests/phpunit/PopupsHooksTest.php +++ b/tests/phpunit/PopupsHooksTest.php @@ -304,7 +304,7 @@ class PopupsHooksTest extends MediaWikiIntegrationTestCase { $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_AFTER_BETA ] ); + $this->assertSame( '1', $userOptions[ PopupsContext::REFERENCE_PREVIEWS_PREFERENCE_NAME ] ); } }