Merge "Use feature management for search in header"
This commit is contained in:
commit
d72b0daa24
|
@ -79,6 +79,11 @@ final class Constants {
|
||||||
*/
|
*/
|
||||||
public const CONFIG_SEARCH_IN_HEADER = 'VectorIsSearchInHeader';
|
public const CONFIG_SEARCH_IN_HEADER = 'VectorIsSearchInHeader';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public const REQUIREMENT_SEARCH_IN_HEADER = 'VectorIsSearchInHeaderIsEnabled';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
@ -111,6 +116,11 @@ final class Constants {
|
||||||
*/
|
*/
|
||||||
public const FEATURE_LATEST_SKIN = 'LatestSkin';
|
public const FEATURE_LATEST_SKIN = 'LatestSkin';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public const FEATURE_SEARCH_IN_HEADER = 'TemporarySearchInHeader';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
|
@ -274,7 +274,9 @@ class Hooks {
|
||||||
//
|
//
|
||||||
// See https://codesearch.wmcloud.org/deployed/?q=skin-vector-search- for an up-to-date
|
// See https://codesearch.wmcloud.org/deployed/?q=skin-vector-search- for an up-to-date
|
||||||
// list.
|
// 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';
|
$bodyAttrs['class'] .= ' skin-vector-search-header';
|
||||||
} else {
|
} else {
|
||||||
$bodyAttrs['class'] .= ' skin-vector-search-header-legacy';
|
$bodyAttrs['class'] .= ' skin-vector-search-header-legacy';
|
||||||
|
|
|
@ -27,6 +27,7 @@ use Vector\Constants;
|
||||||
use Vector\FeatureManagement\FeatureManager;
|
use Vector\FeatureManagement\FeatureManager;
|
||||||
use Vector\FeatureManagement\Requirements\DynamicConfigRequirement;
|
use Vector\FeatureManagement\Requirements\DynamicConfigRequirement;
|
||||||
use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement;
|
use Vector\FeatureManagement\Requirements\LatestSkinVersionRequirement;
|
||||||
|
use Vector\FeatureManagement\Requirements\SearchInHeaderRequirement;
|
||||||
use Vector\SkinVersionLookup;
|
use Vector\SkinVersionLookup;
|
||||||
|
|
||||||
return [
|
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;
|
return $featureManager;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
use MediaWiki\MediaWikiServices;
|
use MediaWiki\MediaWikiServices;
|
||||||
use Vector\Constants;
|
use Vector\Constants;
|
||||||
|
use Vector\VectorServices;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skin subclass for Vector
|
* Skin subclass for Vector
|
||||||
|
@ -99,6 +100,8 @@ class SkinVector extends SkinMustache {
|
||||||
$out = $skin->getOutput();
|
$out = $skin->getOutput();
|
||||||
$title = $out->getTitle();
|
$title = $out->getTitle();
|
||||||
|
|
||||||
|
$featureManager = VectorServices::getFeatureManager();
|
||||||
|
|
||||||
// Naming conventions for Mustache parameters.
|
// Naming conventions for Mustache parameters.
|
||||||
//
|
//
|
||||||
// Value type (first segment):
|
// Value type (first segment):
|
||||||
|
@ -130,7 +133,7 @@ class SkinVector extends SkinMustache {
|
||||||
|
|
||||||
'html-categories' => $skin->getCategories(),
|
'html-categories' => $skin->getCategories(),
|
||||||
'data-footer' => $this->getFooterData(),
|
'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
|
// Header
|
||||||
'data-logos' => ResourceLoaderSkinModule::getAvailableLogos( $this->getConfig() ),
|
'data-logos' => ResourceLoaderSkinModule::getAvailableLogos( $this->getConfig() ),
|
||||||
|
|
Loading…
Reference in New Issue