2020-12-02 15:48:33 +00:00
|
|
|
/**
|
|
|
|
* @module isReferencePreviewsEnabled
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the global state of the application, creates a function that gets
|
|
|
|
* whether or not the user should have Reference Previews enabled.
|
|
|
|
*
|
2021-04-16 11:06:13 +00:00
|
|
|
* @param {mw.user} user The `mw.user` singleton instance
|
|
|
|
* @param {Object} userSettings An object returned by `userSettings.js`
|
2020-12-02 15:48:33 +00:00
|
|
|
* @param {mw.Map} config
|
|
|
|
*
|
2021-04-16 11:06:13 +00:00
|
|
|
* @return {boolean|null} Null when there is no way the popup type can be enabled at run-time.
|
2020-12-02 15:48:33 +00:00
|
|
|
*/
|
2021-04-16 11:06:13 +00:00
|
|
|
export default function isReferencePreviewsEnabled( user, userSettings, config ) {
|
|
|
|
// TODO: This and the final `mw.user.options` check are currently redundant. Only this here
|
|
|
|
// should be removed when the feature flag is not needed any more.
|
|
|
|
if ( !config.get( 'wgPopupsReferencePreviews' ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// T265872: Unavailable when in conflict with (one of the) reference tooltips gadgets.
|
|
|
|
if ( config.get( 'wgPopupsConflictsWithRefTooltipsGadget' ) ||
|
2020-12-02 15:48:33 +00:00
|
|
|
// T243822: Temporarily disabled in the mobile skin
|
2021-04-16 11:06:13 +00:00
|
|
|
config.get( 'skin' ) === 'minerva'
|
|
|
|
) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For anonymous users, the code loads always, but the feature can be toggled at run-time via
|
|
|
|
// local storage.
|
|
|
|
if ( user.isAnon() ) {
|
|
|
|
return userSettings.isReferencePreviewsEnabled();
|
|
|
|
}
|
|
|
|
|
2021-04-27 11:09:31 +00:00
|
|
|
// TODO: Remove when not in Beta any more
|
|
|
|
if ( config.get( 'wgPopupsReferencePreviews' ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-16 11:06:13 +00:00
|
|
|
// Registered users never can enable popup types at run-time.
|
2021-04-27 11:09:31 +00:00
|
|
|
return mw.user.options.get( 'popups-reference-previews' ) === '1' ? true : null;
|
2020-12-02 15:48:33 +00:00
|
|
|
}
|