mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-24 04:22:51 +00:00
dcb513eb0e
The ext.cite.referencePreviews module will transparently replace the ext.popups.referencePreviews module after this patch. Configuration stays in Popups for now, we can migrate it in later work. CSS classes may be renamed in the future but this will be handled separately since it could be a breaking change for on-wiki customizations. A lot of fancy footwork happens in this patch to emulate a soft dependency on Popups. This mechanism doesn't exist explicitly in either ResourceLoader or QUnit, so lots of workarounds are used, to conditionally load the module and to dynamically skip dependent tests. renderer.test.js is fully skipped for now, but can be wired up in later work. Bug: T355194 Change-Id: I0dc47abb59a40d4e41e7dda0eb7b415a2e1ae508
42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
const { TYPE_REFERENCE } = require( './constants.js' );
|
|
|
|
/**
|
|
* @module isReferencePreviewsEnabled
|
|
*/
|
|
|
|
/**
|
|
* Given the global state of the application, creates a function that gets
|
|
* whether or not the user should have Reference Previews enabled.
|
|
*
|
|
* @param {mw.user} user The `mw.user` singleton instance
|
|
* @param {Function} isPreviewTypeEnabled check whether preview has been disabled or enabled.
|
|
* @param {mw.Map} config
|
|
*
|
|
* @return {boolean|null} Null when there is no way the popup type can be enabled at run-time.
|
|
*/
|
|
function isReferencePreviewsEnabled( user, isPreviewTypeEnabled, config ) {
|
|
// TODO: This and the final `mw.user.options` check are currently redundant. Only this here
|
|
// should be removed when the wgPopupsReferencePreviews 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' ) ||
|
|
config.get( 'wgPopupsConflictsWithNavPopupGadget' ) ||
|
|
// T243822: Temporarily disabled in the mobile skin
|
|
config.get( 'skin' ) === 'minerva'
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
if ( user.isAnon() ) {
|
|
return isPreviewTypeEnabled( TYPE_REFERENCE );
|
|
}
|
|
|
|
// Registered users never can enable popup types at run-time.
|
|
return user.options.get( 'popups-reference-previews' ) === '1' ? true : null;
|
|
}
|
|
|
|
module.exports = isReferencePreviewsEnabled;
|