Use feature management for search in header

This will allow us to add the A/B testing requirement for logged in
users.

In preparation for the new A/B test requirement, a custom requirement
is added as the feature management system does not
support OR operations and the desired effect is the case where:

* the SearchInHeader feature flag has been enabled
* OR the SearchInHeaderABTest feature flag has been enabled and the user is bucketed

Bug: T259250
Change-Id: If948603bd598e1b5597345f4268736417f4c3a24
This commit is contained in:
jdlrobson 2020-09-01 12:31:15 -07:00 committed by Jdlrobson
parent 43e9776142
commit c8642b2fbe
5 changed files with 105 additions and 2 deletions

View file

@ -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
*/

View file

@ -0,0 +1,70 @@
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @since 1.36
*/
namespace Vector\FeatureManagement\Requirements;
use Config;
use Vector\Constants;
use Vector\FeatureManagement\Requirement;
/**
* Check whether the search should be part of the header or part of
* the tabs (as in the old design).
* The search in header is enabled if:
* - the associated feature flag has been enabled
*
* @unstable
*
* @package Vector\FeatureManagement\Requirements
* @internal
*/
final class SearchInHeaderRequirement implements Requirement {
/**
* @var Config
*/
private $config;
/**
* This constructor accepts all dependencies needed to determine
* whether search in header is enabled for current user and config.
*
* @param \Config $config
*/
public function __construct( Config $config ) {
$this->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 );
}
}

View file

@ -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';

View file

@ -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;
}
];

View file

@ -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() ),