2024-02-02 18:29:27 +00:00
|
|
|
const { TYPE_REFERENCE } = require( './constants.js' );
|
2023-10-19 21:12:09 +00:00
|
|
|
|
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.
|
|
|
|
*
|
2023-11-17 16:12:20 +00:00
|
|
|
* @param {mw.User} user The `mw.user` singleton instance
|
2024-01-12 20:08:54 +00:00
|
|
|
* @param {Function} isPreviewTypeEnabled check whether preview has been disabled or enabled.
|
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
|
|
|
*/
|
2024-02-02 18:29:27 +00:00
|
|
|
function isReferencePreviewsEnabled( user, isPreviewTypeEnabled, config ) {
|
2021-04-16 11:06:13 +00:00
|
|
|
// TODO: This and the final `mw.user.options` check are currently redundant. Only this here
|
2023-11-06 08:48:29 +00:00
|
|
|
// should be removed when the wgPopupsReferencePreviews feature flag is not needed any more.
|
2021-04-16 11:06:13 +00:00
|
|
|
if ( !config.get( 'wgPopupsReferencePreviews' ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// T265872: Unavailable when in conflict with (one of the) reference tooltips gadgets.
|
|
|
|
if ( config.get( 'wgPopupsConflictsWithRefTooltipsGadget' ) ||
|
2023-09-26 12:44:05 +00:00
|
|
|
config.get( 'wgPopupsConflictsWithNavPopupGadget' ) ||
|
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;
|
|
|
|
}
|
|
|
|
|
2024-01-12 20:08:54 +00:00
|
|
|
if ( user.isAnon() ) {
|
|
|
|
return isPreviewTypeEnabled( TYPE_REFERENCE );
|
2021-04-16 11:06:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Registered users never can enable popup types at run-time.
|
2024-01-03 01:00:34 +00:00
|
|
|
return user.options.get( 'popups-reference-previews' ) === '1' ? true : null;
|
2020-12-02 15:48:33 +00:00
|
|
|
}
|
2024-02-02 18:29:27 +00:00
|
|
|
|
|
|
|
module.exports = isReferencePreviewsEnabled;
|