mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-04 12:09:30 +00:00
eb597645c3
- Include temporary feature requirement for TOC A/B test. - Assumes 100% of logged-in users with even/odd user ids being assigned to treatment/control buckets respectively. - Sampling rates passed in by config are not considered during bucketing. - Update hook for adding needed TOC A/B test body classes. - Add test for temp feature. Note: the temporary feature requirement and associated hooks should be removed once the 2nd TOC A/B test concludes. Bug: T313435 Change-Id: If9c75235614af289cd50182baab29bec3155eb81
85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Skins\Vector\FeatureManagement\Requirements;
|
|
|
|
use CentralIdLookup;
|
|
use Config;
|
|
use MediaWiki\Skins\Vector\Constants;
|
|
use MediaWiki\Skins\Vector\FeatureManagement\Requirement;
|
|
use User;
|
|
|
|
/**
|
|
* Checks whether or not sticky Table of Contents should be shown.
|
|
*
|
|
* @unstable
|
|
*
|
|
* @package Vector\FeatureManagement\Requirements
|
|
* @internal
|
|
*/
|
|
final class TableOfContentsTreatmentRequirement implements Requirement {
|
|
/**
|
|
* @var Config
|
|
*/
|
|
private $config;
|
|
|
|
/**
|
|
* @var User
|
|
*/
|
|
private $user;
|
|
|
|
/**
|
|
* @var CentralIdLookup
|
|
*/
|
|
private $centralIdLookup;
|
|
|
|
/**
|
|
* @param Config $config
|
|
* @param User $user
|
|
* @param CentralIdLookup|null $centralIdLookup
|
|
*/
|
|
public function __construct(
|
|
Config $config,
|
|
User $user,
|
|
?CentralIdLookup $centralIdLookup
|
|
) {
|
|
$this->config = $config;
|
|
$this->user = $user;
|
|
$this->centralIdLookup = $centralIdLookup;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getName(): string {
|
|
return Constants::REQUIREMENT_TABLE_OF_CONTENTS;
|
|
}
|
|
|
|
/**
|
|
* If A/B test is enabled check whether the user is logged in and bucketed.
|
|
*
|
|
* @inheritDoc
|
|
* @throws \ConfigException
|
|
*/
|
|
public function isMet(): bool {
|
|
$currentAbTest = $this->config->get( Constants::CONFIG_WEB_AB_TEST_ENROLLMENT );
|
|
if ( $currentAbTest['enabled'] && $this->user->isRegistered() ) {
|
|
$id = null;
|
|
if ( $this->centralIdLookup ) {
|
|
$id = $this->centralIdLookup->centralIdFromLocalUser( $this->user );
|
|
}
|
|
|
|
// $id will be 0 if the central ID lookup failed.
|
|
if ( !$id ) {
|
|
$id = $this->user->getId();
|
|
}
|
|
|
|
// This assume 100% sampling of logged-in users with roughly half
|
|
// in control or treatment buckets based on even or odd user ids.
|
|
// This does not cover unsampled users nor does it consider the
|
|
// sampling rates of any given bucket passed in via config.
|
|
return $id % 2 === 0;
|
|
}
|
|
return false;
|
|
}
|
|
}
|