mediawiki-extensions-Popups/resources/ext.popups/isEnabled.js
Sam Smith c51b33c8b7 Send blob to everyone
As before, we need to send the Page Previews blob that logged out users
can enable/disable previews.

Changes:
* Unconditionally add the ext.popups RL module to the output.
* Send the value of Popups\PopupsContext#isEnabledByUser to the client
  as $wgPopupsIsEnabledByUser.
* Make mw.popups#isEnabled return $wgPopupsIsEnabledByUser if the user
  is logged in.

Bug: T146889
Change-Id: Id2ccfaa81a327e222fff400f4a5f22f96c99ea31
2017-01-17 06:40:24 -08:00

36 lines
1.1 KiB
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.
*
* If Page Previews is configured as a beta feature (see
* `$wgPopupsBetaFeature`), the user must be logged in and have enabled the
* beta feature in order to see previews.
*
* If Page Previews is configured as a preference, then the user must either
* be logged in and have enabled the preference or be logged out and have not
* disabled previews via the settings modal.
*
* @param {mw.user} user The `mw.user` singleton instance
* @param {Object} userSettings An object returned by
* `mw.popups.createUserSettings`
* @param {mw.Map} config
*
* @return {Boolean}
*/
mw.popups.isEnabled = function ( user, userSettings, config ) {
if ( !user.isAnon() ) {
return config.get( 'wgPopupsIsEnabledByUser' );
}
if ( config.get( 'wgPopupsBetaFeature' ) ) {
return false;
}
return !userSettings.hasIsEnabled() ||
( userSettings.hasIsEnabled() && userSettings.getIsEnabled() );
};
}( mediaWiki ) );