Move Wvui Search A/B Logic to FeatureManager
FeatureManager allows the logic to be centralized and allows clients to ask about its state. For instance, SkinVector will make use of it in I70277c1082a504fbd5f6023e9873e8071de7e35d. Also: * Adds WvuiSearchTreatmentRequirementTest to test A/B logic WvuiSearchTreatmentRequirement/Test logic are adapted from I878239a85ffbecb5e78d73aed5568c56dbd7d659. Bug: T270202 Change-Id: Ia02349a7b41c7caf26fbd728e0be7d47488b97e5
This commit is contained in:
parent
2789e27a29
commit
8c76a17e43
|
@ -128,6 +128,21 @@ final class Constants {
|
||||||
*/
|
*/
|
||||||
public const QUERY_PARAM_SKIN_VERSION = 'useskinversion';
|
public const QUERY_PARAM_SKIN_VERSION = 'useskinversion';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public const FEATURE_USE_WVUI_SEARCH = 'UseWvuiSearch';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public const CONFIG_KEY_USE_WVUI_SEARCH = 'VectorUseWvuiSearch';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public const REQUIREMENT_USE_WVUI_SEARCH = 'VectorUseWvuiSearch';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `mediawiki.searchSuggest` protocol piece of the SearchSatisfaction instrumention reads
|
* The `mediawiki.searchSuggest` protocol piece of the SearchSatisfaction instrumention reads
|
||||||
* the value of an element with the "data-search-loc" attribute and set the event's
|
* the value of an element with the "data-search-loc" attribute and set the event's
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
<?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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether or not WVUI search should be used.
|
||||||
|
*
|
||||||
|
* @unstable
|
||||||
|
*
|
||||||
|
* @package Vector\FeatureManagement\Requirements
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class WvuiSearchTreatmentRequirement implements Requirement {
|
||||||
|
/**
|
||||||
|
* @var Config
|
||||||
|
*/
|
||||||
|
private $config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \User
|
||||||
|
*/
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor accepts all dependencies needed to determine
|
||||||
|
* whether wvui search is enabled for current user and config.
|
||||||
|
*
|
||||||
|
* @param \Config $config
|
||||||
|
* @param \User $user
|
||||||
|
*/
|
||||||
|
public function __construct( \Config $config, \User $user ) {
|
||||||
|
$this->config = $config;
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getName() : string {
|
||||||
|
return Constants::REQUIREMENT_USE_WVUI_SEARCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If A/B test is enabled check whether the user is logged in and bucketed.
|
||||||
|
* Fallback to `VectorUseWvuiSearch` config value.
|
||||||
|
*
|
||||||
|
* @inheritDoc
|
||||||
|
* @throws \ConfigException
|
||||||
|
*/
|
||||||
|
public function isMet() : bool {
|
||||||
|
// Determine the search widget treatment to send to the user
|
||||||
|
$shouldUseWvuiSearch = (bool)$this->config->get( Constants::CONFIG_KEY_USE_WVUI_SEARCH );
|
||||||
|
|
||||||
|
if ( (bool)$this->config->get( Constants::CONFIG_SEARCH_TREATMENT_AB_TEST ) && $this->user->isRegistered() ) {
|
||||||
|
$shouldUseWvuiSearch = $this->user->getID() % 2 === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $shouldUseWvuiSearch;
|
||||||
|
}
|
||||||
|
}
|
|
@ -274,25 +274,16 @@ class Hooks {
|
||||||
// list.
|
// list.
|
||||||
if ( self::isSkinVersionLegacy() ) {
|
if ( self::isSkinVersionLegacy() ) {
|
||||||
$bodyAttrs['class'] .= ' skin-vector-legacy';
|
$bodyAttrs['class'] .= ' skin-vector-legacy';
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the search widget treatment to send to the user
|
// Determine the search widget treatment to send to the user
|
||||||
$config = $sk->getConfig();
|
if ( VectorServices::getFeatureManager()->isFeatureEnabled( Constants::FEATURE_USE_WVUI_SEARCH ) ) {
|
||||||
$user = $sk->getUser();
|
|
||||||
$shouldUseWvuiSearch = $config->get( 'VectorUseWvuiSearch' );
|
|
||||||
|
|
||||||
if ( $config->get( 'VectorSearchTreatmentABTest' ) && $user->isRegistered() ) {
|
|
||||||
$shouldUseWvuiSearch = $user->getID() % 2 === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $shouldUseWvuiSearch ) {
|
|
||||||
$bodyAttrs['class'] .= ' skin-vector-search-vue';
|
$bodyAttrs['class'] .= ' skin-vector-search-vue';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$config = $sk->getConfig();
|
||||||
// Should we disable the max-width styling?
|
// Should we disable the max-width styling?
|
||||||
if ( $sk->getTitle() && self::shouldDisableMaxWidth(
|
if ( !self::isSkinVersionLegacy() && $sk->getTitle() && self::shouldDisableMaxWidth(
|
||||||
$config->get( 'VectorMaxWidthOptions' ),
|
$config->get( 'VectorMaxWidthOptions' ),
|
||||||
$sk->getTitle(),
|
$sk->getTitle(),
|
||||||
$out->getRequest()->getValues()
|
$out->getRequest()->getValues()
|
||||||
|
|
|
@ -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\WvuiSearchTreatmentRequirement;
|
||||||
use Vector\SkinVersionLookup;
|
use Vector\SkinVersionLookup;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -85,6 +86,24 @@ return [
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Feature: Use Wvui Search
|
||||||
|
// ================================
|
||||||
|
$featureManager->registerRequirement(
|
||||||
|
new WvuiSearchTreatmentRequirement(
|
||||||
|
$services->getMainConfig(),
|
||||||
|
$context->getUser()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$featureManager->registerFeature(
|
||||||
|
Constants::FEATURE_USE_WVUI_SEARCH,
|
||||||
|
[
|
||||||
|
Constants::REQUIREMENT_FULLY_INITIALISED,
|
||||||
|
Constants::REQUIREMENT_LATEST_SKIN_VERSION,
|
||||||
|
Constants::REQUIREMENT_USE_WVUI_SEARCH
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
return $featureManager;
|
return $featureManager;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
<?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
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Vector\Constants;
|
||||||
|
use Vector\FeatureManagement\Requirements\WvuiSearchTreatmentRequirement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group Vector
|
||||||
|
* @coversDefaultClass \Vector\FeatureManagement\Requirements\WvuiSearchTreatmentRequirement
|
||||||
|
*/
|
||||||
|
class WvuiSearchTreatmentRequirementTest extends \MediaWikiTestCase {
|
||||||
|
|
||||||
|
public function providerWvuiSearchTreatmentRequirement() {
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
// Is wvui search enabled
|
||||||
|
false,
|
||||||
|
// is A-B test enabled
|
||||||
|
false,
|
||||||
|
// note 0 = anon user
|
||||||
|
0,
|
||||||
|
false,
|
||||||
|
'If nothing enabled nobody gets wvui search'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// Is wvui search enabled
|
||||||
|
true,
|
||||||
|
// is A-B test enabled
|
||||||
|
false,
|
||||||
|
// note 0 = anon user
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
'Anon users should get wvui search if enabled when A/B test disabled'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// Is wvui search enabled
|
||||||
|
true,
|
||||||
|
// is A-B test enabled
|
||||||
|
false,
|
||||||
|
2,
|
||||||
|
true,
|
||||||
|
'Logged in users should get wvui search if enabled when A/B test disabled'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// Is wvui search enabled
|
||||||
|
true,
|
||||||
|
// is A-B test enabled
|
||||||
|
false,
|
||||||
|
1,
|
||||||
|
true,
|
||||||
|
'All odd logged in users should get wvui search when A/B test disabled'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// Is wvui search enabled
|
||||||
|
true,
|
||||||
|
// is A-B test enabled
|
||||||
|
true,
|
||||||
|
// note 0 = anon user
|
||||||
|
0,
|
||||||
|
true,
|
||||||
|
'Anon users with a/b test enabled should see wvui search when search config enabled'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// Is wvui search enabled
|
||||||
|
true,
|
||||||
|
// is A-B test enabled
|
||||||
|
true,
|
||||||
|
2,
|
||||||
|
true,
|
||||||
|
'Even logged in users get wvui search when A/B test enabled'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// Is wvui search enabled
|
||||||
|
true,
|
||||||
|
// is A-B test enabled
|
||||||
|
true,
|
||||||
|
1,
|
||||||
|
false,
|
||||||
|
'Odd logged in users do not wvui search when A/B test enabled'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::isMet
|
||||||
|
* @dataProvider providerWvuiSearchTreatmentRequirement
|
||||||
|
* @param bool $wvuiSearchConfigValue
|
||||||
|
* @param bool $abValue
|
||||||
|
* @param int $userId
|
||||||
|
* @param bool $expected
|
||||||
|
* @param string $msg
|
||||||
|
*/
|
||||||
|
public function testWvuiSearchTreatmentRequirement(
|
||||||
|
$wvuiSearchConfigValue, $abValue, $userId, $expected, $msg
|
||||||
|
) {
|
||||||
|
$config = new HashConfig( [
|
||||||
|
Constants::CONFIG_KEY_USE_WVUI_SEARCH => $wvuiSearchConfigValue,
|
||||||
|
Constants::CONFIG_SEARCH_TREATMENT_AB_TEST => $abValue,
|
||||||
|
] );
|
||||||
|
$user = $this->getTestUser()->getUser();
|
||||||
|
$user->setId( $userId );
|
||||||
|
|
||||||
|
$requirement = new WvuiSearchTreatmentRequirement(
|
||||||
|
$config, $user
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame( $requirement->isMet(), $expected, $msg );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue