diff --git a/includes/Constants.php b/includes/Constants.php index a394fda5b..b8a37a669 100644 --- a/includes/Constants.php +++ b/includes/Constants.php @@ -79,6 +79,11 @@ final class Constants { */ public const CONFIG_SEARCH_IN_HEADER = 'VectorIsSearchInHeader'; + /** + * @var string + */ + public const REQUIREMENT_SEARCH_IN_HEADER = 'VectorIsSearchInHeaderIsEnabled'; + /** * @var string */ @@ -111,6 +116,11 @@ final class Constants { */ public const FEATURE_LATEST_SKIN = 'LatestSkin'; + /** + * @var string + */ + public const FEATURE_SEARCH_IN_HEADER = 'TemporarySearchInHeader'; + /** * @var string */ diff --git a/includes/FeatureManagement/Requirements/SearchInHeaderRequirement.php b/includes/FeatureManagement/Requirements/SearchInHeaderRequirement.php new file mode 100644 index 000000000..71cfb7c5e --- /dev/null +++ b/includes/FeatureManagement/Requirements/SearchInHeaderRequirement.php @@ -0,0 +1,70 @@ +config = $config; + } + + /** + * @inheritDoc + */ + public function getName() : string { + return Constants::REQUIREMENT_SEARCH_IN_HEADER; + } + + /** + * @inheritDoc + * @throws \ConfigException + */ + public function isMet() : bool { + return (bool)$this->config->get( Constants::CONFIG_SEARCH_IN_HEADER ); + } +} diff --git a/includes/Hooks.php b/includes/Hooks.php index b4cc915cc..b078c3ca4 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -274,7 +274,9 @@ class Hooks { // // See https://codesearch.wmcloud.org/deployed/?q=skin-vector-search- for an up-to-date // list. - if ( self::getConfig( Constants::CONFIG_SEARCH_IN_HEADER ) ) { + + $featureManager = VectorServices::getFeatureManager(); + if ( $featureManager->isFeatureEnabled( Constants::FEATURE_SEARCH_IN_HEADER ) ) { $bodyAttrs['class'] .= ' skin-vector-search-header'; } else { $bodyAttrs['class'] .= ' skin-vector-search-header-legacy'; diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index cddcf54c9..3fcc0ad83 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -27,6 +27,7 @@ use Vector\Constants; use Vector\FeatureManagement\FeatureManager; use Vector\FeatureManagement\Requirements\DynamicConfigRequirement; use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement; +use Vector\FeatureManagement\Requirements\SearchInHeaderRequirement; use Vector\SkinVersionLookup; return [ @@ -66,6 +67,23 @@ return [ ] ); + // Feature (temporary): search in header + // ======================================== + $featureManager->registerRequirement( + new SearchInHeaderRequirement( + $services->getMainConfig() + ) + ); + + $featureManager->registerFeature( + Constants::FEATURE_SEARCH_IN_HEADER, + // Requirements + [ + Constants::REQUIREMENT_FULLY_INITIALISED, + Constants::REQUIREMENT_SEARCH_IN_HEADER + ] + ); + return $featureManager; } ]; diff --git a/includes/SkinVector.php b/includes/SkinVector.php index 8d5e5cd35..2ea88674c 100644 --- a/includes/SkinVector.php +++ b/includes/SkinVector.php @@ -24,6 +24,7 @@ use MediaWiki\MediaWikiServices; use Vector\Constants; +use Vector\VectorServices; /** * Skin subclass for Vector @@ -99,6 +100,8 @@ class SkinVector extends SkinMustache { $out = $skin->getOutput(); $title = $out->getTitle(); + $featureManager = VectorServices::getFeatureManager(); + // Naming conventions for Mustache parameters. // // Value type (first segment): @@ -130,7 +133,7 @@ class SkinVector extends SkinMustache { 'html-categories' => $skin->getCategories(), 'data-footer' => $this->getFooterData(), - 'is-search-in-header' => $this->getConfig()->get( Constants::CONFIG_SEARCH_IN_HEADER ), + 'is-search-in-header' => $featureManager->isFeatureEnabled( Constants::FEATURE_SEARCH_IN_HEADER ), // Header 'data-logos' => ResourceLoaderSkinModule::getAvailableLogos( $this->getConfig() ),