mediawiki-extensions-Popups/resources/ext.popups/isEnabled.js
Sam Smith a6423fbc75 Redefine when Page Previews are enabled
The Page Previews A/B test was disabled in T144490. After the changes
for that task had been deployed we discovered that the old definition
for when previews are enabled was invalid.

Previews are enabled:
* If the beta feature is enabled and the user has enabled the beta
  feature.
* The user hasn't disabled previews via the settings modal.
* And soon, if the beta feature is disabled and the user hasn't disabled
  previews via their user preferences (see T146889).

Changes:
* mw.popups#createExperiment -> mw.popups#isEnabled
* Make mw.popups#isEnabled act like a factory to maintain backwards
  compatibility.
* Update the associated tests.

Bug: T152687
Change-Id: I713a90dfb29866b27738e7d19e8a22518a12d417
2016-12-16 10:35:55 +00:00

34 lines
1,019 B
JavaScript

( function ( mw ) {
/**
* Given the global state of the application, creates a function that gets
* whether or not the user should have Page Previews enabled.
*
* The user has previews enabled if:
* * The beta feature is available (see `$wgPopupsBetaFeature`) and they've
* enabled the beta feature.
* * They *haven't disabled* it via the settings modal.
*
* The first case covers the enabled by default case: if
* `$wgPopupsBetaFeature` is `false` and the user hasn't disabled previews via
* their preferences, then previews are enabled.
*
* @param {mw.user} user The `mw.user` singleton instance
* @param {Object} userSettings An object returned by
* `mw.popups.createUserSettings`
*
* @return {Function}
*/
mw.popups.isEnabled = function ( user, userSettings ) {
return function () {
if ( user.isAnon() ) {
return false;
}
return !userSettings.hasIsEnabled() ||
( userSettings.hasIsEnabled() && userSettings.getIsEnabled() );
};
};
}( mediaWiki ) );