mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-11 23:36:07 +00:00
9611d3b2db
Supporting changes: * Add mw.popups.processLinks. * Extract the existing unit tests for mw.popups.selectPopupElements and mw.popups.getTitle. * Fix Grunt QUnit timeout. Change-Id: I325bcb15abc6e0b745d78b7308a346a034ab2988
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
( function ( mw ) {
|
|
|
|
/**
|
|
* Given the global state of the application, creates a function which that
|
|
* whether or not the user should have Link Previews enabled, i.e. whether
|
|
* they are in the experiment condition.
|
|
*
|
|
* The user is in the experiment condition if:
|
|
* * They've enabled by Link Previews by clicking "Enable previews" in the
|
|
* footer menu.
|
|
* * They've enabled Link Previews as a beta feature.
|
|
* * 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
|
|
* `ext.popups.createUserSettings`, from which the user's token will be
|
|
* 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 ) );
|