2016-05-13 20:15:36 +00:00
|
|
|
( function ( mw ) {
|
2016-05-13 12:25:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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() {
|
2016-05-13 20:15:36 +00:00
|
|
|
var value = mw.storage.get( 'mwe-popups-enabled' );
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-13 20:15:36 +00:00
|
|
|
return Boolean( value ) && value !== '0';
|
2016-05-13 12:25:39 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 18:04:53 +00:00
|
|
|
/**
|
|
|
|
* Has the user previously disabled Popups by clicking "Disable previews" in the settings
|
|
|
|
* overlay?
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function hasUserDisabledFeature() {
|
2016-05-13 20:15:36 +00:00
|
|
|
return mw.storage.get( 'mwe-popups-enabled' ) === '0';
|
2016-05-19 18:04:53 +00:00
|
|
|
}
|
|
|
|
|
2016-05-13 12:25:39 +00:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*
|
2016-05-19 20:04:14 +00:00
|
|
|
* @return {boolean}
|
2016-05-13 12:25:39 +00:00
|
|
|
*/
|
|
|
|
mw.popups.experiment.isUserInCondition = function isUserInCondition() {
|
2016-05-19 20:04:14 +00:00
|
|
|
var config = mw.config.get( 'wgPopupsExperimentConfig' );
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 18:04:53 +00:00
|
|
|
// The first two tests deal with whether the user has /explicitly/ enable or disabled via its
|
|
|
|
// settings.
|
|
|
|
if ( hasUserEnabledFeature() ) {
|
2016-05-19 20:04:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
if ( hasUserDisabledFeature() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Users with the beta feature enabled are already in the experimental condition.
|
|
|
|
if ( mw.config.get( 'wgPopupsExperimentIsBetaFeatureEnabled', false ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-13 12:25:39 +00:00
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
if ( !config ) {
|
|
|
|
return false;
|
2016-05-13 12:25:39 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 20:04:14 +00:00
|
|
|
// FIXME: mw.experiments should expose the CONTROL_BUCKET constant, e.g.
|
|
|
|
// `mw.experiments.CONTROL_BUCKET`.
|
|
|
|
return mw.experiments.getBucket( config, getToken() ) !== 'control';
|
2016-05-13 12:25:39 +00:00
|
|
|
};
|
|
|
|
|
2016-05-13 20:15:36 +00:00
|
|
|
}( mediaWiki ) );
|