2016-11-08 19:42:21 +00:00
|
|
|
( function ( mw ) {
|
|
|
|
|
|
|
|
/**
|
2016-11-11 13:45:03 +00:00
|
|
|
* Given the global state of the application, creates a function that gets
|
2016-11-17 21:53:21 +00:00
|
|
|
* whether or not the user should have Page Previews enabled, i.e. whether
|
2016-11-08 19:42:21 +00:00
|
|
|
* they are in the experiment condition.
|
|
|
|
*
|
|
|
|
* The user is in the experiment condition if:
|
2016-11-30 10:59:24 +00:00
|
|
|
* * They've enabled by Page Previews via UI interactions.
|
2016-11-17 21:53:21 +00:00
|
|
|
* * They've enabled Page Previews as a beta feature.
|
2016-11-08 19:42:21 +00:00
|
|
|
* * They aren't in the control bucket of the experiment.
|
|
|
|
*
|
|
|
|
* @param {mw.Map} config
|
|
|
|
* @param {mw.user} user The `mw.user` singleton instance
|
|
|
|
* @param {Object} userSettings An object returned by
|
2016-11-30 11:13:37 +00:00
|
|
|
* `mw.popups.createUserSettings`, from which the user's token will be
|
2016-11-08 19:42:21 +00:00
|
|
|
* retrieved
|
|
|
|
*
|
|
|
|
* @return {Function}
|
|
|
|
*/
|
|
|
|
mw.popups.createExperiment = function ( config, user, userSettings ) {
|
|
|
|
return function () {
|
|
|
|
var experimentConfig = config.get( 'wgPopupsExperimentConfig' );
|
|
|
|
|
|
|
|
if ( userSettings.hasIsEnabled() ) {
|
|
|
|
return userSettings.getIsEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( config.get( 'wgPopupsExperiment', false ) === false ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( user.isAnon() ) {
|
|
|
|
if ( !experimentConfig ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: mw.experiments should expose the CONTROL_BUCKET constant, e.g.
|
|
|
|
// `mw.experiments.CONTROL_BUCKET`.
|
|
|
|
return mw.experiments.getBucket( experimentConfig, userSettings.getToken() ) !== 'control';
|
|
|
|
} else {
|
|
|
|
// Logged in users are in condition depending on the beta feature flag
|
|
|
|
// instead of bucketing
|
|
|
|
return config.get( 'wgPopupsExperimentIsBetaFeatureEnabled', false );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}( mediaWiki ) );
|