diff --git a/includes/FeatureManagement/FeatureManager.php b/includes/FeatureManagement/FeatureManager.php index cbcb508cc..497fbeefd 100644 --- a/includes/FeatureManagement/FeatureManager.php +++ b/includes/FeatureManagement/FeatureManager.php @@ -126,6 +126,21 @@ final class FeatureManager { $this->features[$feature] = $requirements; } + /** + * Return a list of classes that should be added to the body tag + * + * @return array + */ + public function getFeatureBodyClass() { + $featureManager = $this; + return array_map( static function ( $featureName ) use ( $featureManager ) { + // switch to lower case and switch from camel case to hyphens + $featureClass = ltrim( strtolower( preg_replace( '/[A-Z]([A-Z](?![a-z]))*/', '-$0', $featureName ) ), '-' ); + $prefix = 'vector-feature-' . $featureClass . '-'; + return $featureManager->isFeatureEnabled( $featureName ) ? $prefix . 'enabled' : $prefix . 'disabled'; + }, array_keys( $this->features ) ); + } + /** * Gets whether the feature's requirements are met. * diff --git a/includes/Hooks.php b/includes/Hooks.php index 32b518539..1e3db76c5 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -650,9 +650,8 @@ class Hooks implements } $featureManager = VectorServices::getFeatureManager(); - if ( $featureManager->isFeatureEnabled( Constants::FEATURE_LANGUAGE_IN_MAIN_PAGE_HEADER ) ) { - $bodyAttrs['class'] .= ' vector-language-in-header-enabled'; - } + $bodyAttrs['class'] .= ' ' . implode( ' ', $featureManager->getFeatureBodyClass() ); + $bodyAttrs['class'] = trim( $bodyAttrs['class'] ); } /** diff --git a/resources/skins.vector.styles/components/LanguageButton.less b/resources/skins.vector.styles/components/LanguageButton.less index cd03a03f1..c2234c327 100644 --- a/resources/skins.vector.styles/components/LanguageButton.less +++ b/resources/skins.vector.styles/components/LanguageButton.less @@ -2,7 +2,7 @@ @import '../../common/variables.less'; @import 'mediawiki.mixins.less'; -// Note vector-language-in-header-enabled class is not used here as that class +// Note vector-feature-language-in-header-enabled class is not used here as that class // only applies to main page. // This must be limited to mw-body-header as the mw-portlet-lang class is shared with // the language portlet that can display in the sidebar. diff --git a/tests/phpunit/unit/FeatureManagement/FeatureManagerTest.php b/tests/phpunit/unit/FeatureManagement/FeatureManagerTest.php index 73de2fe2d..5f7309ee9 100644 --- a/tests/phpunit/unit/FeatureManagement/FeatureManagerTest.php +++ b/tests/phpunit/unit/FeatureManagement/FeatureManagerTest.php @@ -61,6 +61,26 @@ class FeatureManagerTest extends \MediaWikiUnitTestCase { ]; } + /** + * @covers ::getFeatureBodyClass + */ + public function testGetFeatureBodyClass() { + $featureManager = new FeatureManager(); + $featureManager->registerSimpleRequirement( 'requirement', true ); + $featureManager->registerSimpleRequirement( 'disabled', false ); + $featureManager->registerFeature( 'sticky-header', [ 'requirement' ] ); + $featureManager->registerFeature( 'TableOfContents', [ 'requirement' ] ); + $featureManager->registerFeature( 'Test', [ 'disabled' ] ); + $this->assertEquals( + [ + 'vector-feature-sticky-header-enabled', + 'vector-feature-table-of-contents-enabled', + 'vector-feature-test-disabled' + ], + $featureManager->getFeatureBodyClass() + ); + } + /** * @dataProvider provideInvalidFeatureConfig * @covers ::registerFeature