mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
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:
parent
12164c1606
commit
71d2e76d7f
|
@ -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,
|
||||
|
|
|
@ -300,27 +300,18 @@ 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() ) {
|
||||
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;
|
||||
if (
|
||||
( $feature ? in_array( $feature, (array)$abtest ) : (bool)$abtest ) &&
|
||||
$user->isRegistered()
|
||||
) {
|
||||
return $user->getId() % 2 == 0 ? 'test' : 'control';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
] );
|
||||
|
|
Loading…
Reference in a new issue