From 89c250c18e2848b0a0328ff949d5af5f3e1b4ec0 Mon Sep 17 00:00:00 2001 From: Jan Drewniak Date: Mon, 6 May 2024 12:13:00 -0400 Subject: [PATCH] Add exclusion notice for "width" option in Appearance menu Adds the notice "This page is always wide" and disables the inputs for the "width" options in the Appearance menu when pages are excluded via configuration ( `$wgVectorMaxWidthOptions`). Bug: T364015 Change-Id: Ie99b41c9130f496ab23b60c95e551a9ea602d5a0 --- i18n/en.json | 1 + i18n/qqq.json | 1 + includes/FeatureManagement/FeatureManager.php | 11 +++++++++-- skin.json | 1 + .../FeatureManagement/FeatureManagerTest.php | 19 ++++++++++++++----- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/i18n/en.json b/i18n/en.json index 95f6be5e9..98ac35824 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -70,6 +70,7 @@ "vector-limited-width-toggle": "Toggle limited content width", "vector-limited-width-toggle-on-popup": "You have switched your layout to full width. To go back to limited width, press this button.", "vector-limited-width-toggle-off-popup": "You can toggle between a limited width and full width by clicking this button.", + "vector-feature-limited-width-exclusion-notice": "This page is always wide", "vector-page-tools-label": "Tools", "vector-page-tools-general-label": "General", "vector-page-tools-actions-label": "Actions", diff --git a/i18n/qqq.json b/i18n/qqq.json index e633eabc1..8583f146e 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -56,6 +56,7 @@ "vector-feature-custom-font-size-name": "Heading label for font size", "vector-feature-limited-width-0-label": "Label for option to disable limited width. An adjective that describes width ({{msg-mw|Vector-feature-limited-width-name}}).", "vector-feature-limited-width-1-label": "Label for option to enable limited width. An adjective that describes width ({{msg-mw|Vector-feature-limited-width-name}}).", + "vector-feature-limited-width-exclusion-notice": "Notice when limited width option is disabled.", "vector-feature-custom-font-size-0-label": "Label for small (legacy) font size. An adjective that describes \"text\" ({{msg-mw|Vector-feature-custom-font-size-name}}).", "vector-feature-custom-font-size-1-label": "Label for standard font size. An adjective that describes \"text\" ({{msg-mw|Vector-feature-custom-font-size-name}}).", "vector-feature-custom-font-size-2-label": "Label for large font size. An adjective that describes \"text\" ({{msg-mw|Vector-feature-custom-font-size-name}}).", diff --git a/includes/FeatureManagement/FeatureManager.php b/includes/FeatureManagement/FeatureManager.php index 3644ca88f..9fd98b726 100644 --- a/includes/FeatureManagement/FeatureManager.php +++ b/includes/FeatureManagement/FeatureManager.php @@ -188,10 +188,9 @@ class FeatureManager { if ( ConfigHelper::shouldDisable( $config->get( 'VectorNightModeOptions' ), $request, $title ) ) { // The additional "-" prefix, makes this an invalid client preference for anonymous users. return 'skin-theme-clientpref--excluded'; - } else { - $prefix = ''; } + $prefix = ''; $valueRequest = $request->getText( 'vectornightmode' ); // If night mode query string is used, hardcode pref value to the night mode value // NOTE: The query string parameter only works for logged in users. @@ -205,6 +204,14 @@ class FeatureManager { $prefix .= 'skin-theme-'; break; case CONSTANTS::FEATURE_LIMITED_WIDTH: + if ( ConfigHelper::shouldDisable( $config->get( 'VectorMaxWidthOptions' ), $request, $title ) ) { + return 'vector-feature-limited-width-clientpref--excluded'; + } + + $suffixEnabled = 'clientpref-1'; + $suffixDisabled = 'clientpref-0'; + + break; case CONSTANTS::FEATURE_TOC_PINNED: case CONSTANTS::FEATURE_APPEARANCE_PINNED: $suffixEnabled = 'clientpref-1'; diff --git a/skin.json b/skin.json index a8fb2f580..1979ae7ed 100644 --- a/skin.json +++ b/skin.json @@ -389,6 +389,7 @@ "vector-feature-limited-width-name", "vector-feature-limited-width-0-label", "vector-feature-limited-width-1-label", + "vector-feature-limited-width-exclusion-notice", "vector-feature-custom-font-size-name", "vector-feature-custom-font-size-0-label", "vector-feature-custom-font-size-1-label", diff --git a/tests/phpunit/integration/FeatureManagement/FeatureManagerTest.php b/tests/phpunit/integration/FeatureManagement/FeatureManagerTest.php index e665165a8..10b769510 100644 --- a/tests/phpunit/integration/FeatureManagement/FeatureManagerTest.php +++ b/tests/phpunit/integration/FeatureManagement/FeatureManagerTest.php @@ -34,7 +34,10 @@ class FeatureManagerTest extends \MediaWikiIntegrationTestCase { $featureManager = $this->newFeatureManager(); $featureManager->registerSimpleRequirement( 'requirement', $enabled ); $featureManager->registerFeature( $feature, [ 'requirement' ] ); - + // Title is required for checking whether or not the feature is excluded + // based on page title. + $context = RequestContext::getMain(); + $context->setTitle( Title::makeTitle( NS_MAIN, 'Main Page' ) ); $this->assertSame( [ $expected ], $featureManager->getFeatureBodyClass() ); } @@ -88,26 +91,32 @@ class FeatureManagerTest extends \MediaWikiIntegrationTestCase { } /** ensure the class is present when disabled and absent when not */ - public static function provideGetFeatureBodyClassNightModeDisabled() { + public static function provideGetFeatureBodyClassExcluded() { return [ [ true ], [ false ] ]; } /** - * @dataProvider provideGetFeatureBodyClassNightModeDisabled + * @dataProvider provideGetFeatureBodyClassExcluded * @covers ::getFeatureBodyClass pref night mode specifics - disabled pages */ - public function testGetFeatureBodyClassNightModeDisabled( $disabled ) { + public function testGetFeatureBodyClassExcluded( $disabled ) { $featureManager = $this->newFeatureManager(); $featureManager->registerFeature( CONSTANTS::PREF_NIGHT_MODE, [] ); + $featureManager->registerFeature( CONSTANTS::FEATURE_LIMITED_WIDTH, [] ); $context = RequestContext::getMain(); $context->setTitle( Title::makeTitle( NS_MAIN, 'Main Page' ) ); $this->overrideConfigValues( [ 'VectorNightModeOptions' => [ 'exclude' => [ 'mainpage' => $disabled ] ] ] ); + $this->overrideConfigValues( [ 'VectorMaxWidthOptions' => [ 'exclude' => [ 'mainpage' => $disabled ] ] ] ); + + $bodyClasses = $featureManager->getFeatureBodyClass(); + $this->assertEquals( - in_array( 'skin-theme-clientpref--excluded', $featureManager->getFeatureBodyClass() ), + in_array( 'skin-theme-clientpref--excluded', $bodyClasses ) && + in_array( 'vector-feature-limited-width-clientpref--excluded', $bodyClasses ), $disabled ); }