Merge "Use feature management for search in header"

This commit is contained in:
jenkins-bot 2020-09-14 12:50:16 +00:00 committed by Gerrit Code Review
commit d72b0daa24
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() ),