2023-10-19 21:12:09 +00:00
|
|
|
import { previewTypes } from './preview/model';
|
|
|
|
|
2020-12-02 15:48:33 +00:00
|
|
|
/**
|
|
|
|
* @module isReferencePreviewsEnabled
|
|
|
|
*/
|
2023-06-12 16:08:27 +00:00
|
|
|
const canSaveToUserPreferences = require( './canSaveToUserPreferences.js' );
|
2020-12-02 15:48:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2021-04-16 11:06:13 +00:00
|
|
|
* @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
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For anonymous users, the code loads always, but the feature can be toggled at run-time via
|
|
|
|
// local storage.
|
2023-06-12 16:08:27 +00:00
|
|
|
if ( !canSaveToUserPreferences( user ) ) {
|
2023-10-19 21:12:09 +00:00
|
|
|
return userSettings.isPreviewTypeEnabled( previewTypes.TYPE_REFERENCE );
|
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
|
|
|
}
|