Update a/b test code for visual enhancements a/b test

Strip it out from applying to logged out users and make the test work
for multiple features

Bug: T333715
Change-Id: Id15a8a99c2ea8e6fc14fc83baf2ed6ebaaf754c8
This commit is contained in:
David Lynch 2023-05-08 01:30:21 -05:00
parent 12164c1606
commit 71d2e76d7f
3 changed files with 10 additions and 24 deletions

View file

@ -540,7 +540,7 @@
},
"DiscussionToolsABTest": {
"value": false,
"description": "A/B test DiscussionTools features for logged in users. false, 'replytool', 'newtopictool', or 'mobile'"
"description": "A/B test DiscussionTools features for logged in users. false, any valid feature string for an option below, or an array thereof"
},
"DiscussionToolsEnableMobile": {
"value": true,

View file

@ -300,28 +300,19 @@ class HookUtils {
*/
public static function determineUserABTestBucket( UserIdentity $user, ?string $feature = null ): string {
$services = MediaWikiServices::getInstance();
$optionsManager = $services->getUserOptionsManager();
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
$abtest = $dtConfig->get( 'DiscussionToolsABTest' );
if ( !$abtest ) {
return '';
}
if ( $feature ? ( $abtest == $feature ) : (bool)$abtest ) {
if ( $user->isRegistered() ) {
if (
( $feature ? in_array( $feature, (array)$abtest ) : (bool)$abtest ) &&
$user->isRegistered()
) {
return $user->getId() % 2 == 0 ? 'test' : 'control';
}
// logged out
$req = RequestContext::getMain()->getRequest();
$cookie = $req->getCookie( 'DTAB', '' );
if ( $cookie ) {
return $cookie;
}
// we just want to remember this across all calls in this request
static $bucket = false;
if ( !$bucket ) {
$bucket = rand( 0, 1 ) <= 0.5 ? 'test' : 'control';
}
return $bucket;
}
return '';
}

View file

@ -109,12 +109,7 @@ class PageHooks implements
}
// Load modules if any DT feature is enabled for this user
if (
HookUtils::isFeatureEnabledForOutput( $output ) ||
// If there's an a/b test we need to include the JS for unregistered users just so
// we can make sure we store the bucket
( $this->config->get( 'DiscussionToolsABTest' ) && !$user->isRegistered() )
) {
if ( HookUtils::isFeatureEnabledForOutput( $output ) ) {
$output->addModules( [
'ext.discussionTools.init'
] );