mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-11 07:16:08 +00:00
c4667fd133
As there are an unmanageable amount of synchronous checks of mw.popups.enabled, convert mw.popups.experiment.isUserInCondition to a synchronous method. Follow on I4959749. Bug: T132604 Change-Id: Ide07e62868c77bfcd78af58dcec7303a35a72157
91 lines
2.1 KiB
JavaScript
91 lines
2.1 KiB
JavaScript
( function ( mw, $ ) {
|
|
|
|
/**
|
|
* @ignore
|
|
*/
|
|
function getToken() {
|
|
var key = 'PopupsExperimentID',
|
|
id = mw.storage.get( key );
|
|
|
|
if ( !id ) {
|
|
id = mw.user.generateRandomSessionId();
|
|
|
|
mw.storage.set( key, id );
|
|
}
|
|
|
|
return id;
|
|
}
|
|
|
|
/**
|
|
* Has the user previously enabled Popups by clicking "Enable previews" in the
|
|
* footer menu?
|
|
*
|
|
* @return {boolean}
|
|
* @ignore
|
|
*/
|
|
function hasUserEnabledFeature() {
|
|
var value = $.jStorage.get( 'mwe-popups-enabled' );
|
|
|
|
return Boolean( value ) && value !== 'false';
|
|
}
|
|
|
|
/**
|
|
* Has the user previously disabled Popups by clicking "Disable previews" in the settings
|
|
* overlay?
|
|
*
|
|
* @return {boolean}
|
|
* @ignore
|
|
*/
|
|
function hasUserDisabledFeature() {
|
|
return $.jStorage.get( 'mwe-popups-enabled' ) === 'false';
|
|
}
|
|
|
|
/**
|
|
* @class mw.popups.experiment
|
|
* @singleton
|
|
*/
|
|
mw.popups.experiment = {};
|
|
|
|
/**
|
|
* Gets whether or not the user has Popups enabled, i.e. whether they are in the experiment
|
|
* condition.
|
|
*
|
|
* The user is in the experiment condition if:
|
|
* * they've enabled Popups by click "Enable previews" in the footer menu, or
|
|
* * they've enabled Popups as a beta feature, or
|
|
* * they aren't in the control bucket of the experiment
|
|
*
|
|
* N.B. that the user isn't entered into the experiment, i.e. they aren't assigned or a bucket,
|
|
* if the experiment isn't configured.
|
|
*
|
|
* @return {boolean}
|
|
*/
|
|
mw.popups.experiment.isUserInCondition = function isUserInCondition() {
|
|
var config = mw.config.get( 'wgPopupsExperimentConfig' );
|
|
|
|
// The first two tests deal with whether the user has /explicitly/ enable or disabled via its
|
|
// settings.
|
|
if ( hasUserEnabledFeature() ) {
|
|
return true;
|
|
}
|
|
|
|
if ( hasUserDisabledFeature() ) {
|
|
return false;
|
|
}
|
|
|
|
// Users with the beta feature enabled are already in the experimental condition.
|
|
if ( mw.config.get( 'wgPopupsExperimentIsBetaFeatureEnabled', false ) ) {
|
|
return true;
|
|
}
|
|
|
|
if ( !config ) {
|
|
return false;
|
|
}
|
|
|
|
// FIXME: mw.experiments should expose the CONTROL_BUCKET constant, e.g.
|
|
// `mw.experiments.CONTROL_BUCKET`.
|
|
return mw.experiments.getBucket( config, getToken() ) !== 'control';
|
|
};
|
|
|
|
}( mediaWiki, jQuery ) );
|