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
47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
const isReferencePreviewsEnabled = require( './isReferencePreviewsEnabled.js' );
|
|
const { initReferencePreviewsInstrumentation, LOGGING_SCHEMA } = require( './referencePreviewsInstrumentation.js' );
|
|
const createReferenceGateway = require( './createReferenceGateway.js' );
|
|
const renderFn = require( './createReferencePreview.js' );
|
|
const { TYPE_REFERENCE, FETCH_DELAY_REFERENCE_TYPE } = require( './constants.js' );
|
|
const setUserConfigFlags = require( './setUserConfigFlags.js' );
|
|
|
|
setUserConfigFlags( mw.config );
|
|
const referencePreviewsState = isReferencePreviewsEnabled(
|
|
mw.user,
|
|
mw.popups.isEnabled,
|
|
mw.config
|
|
);
|
|
const gateway = createReferenceGateway();
|
|
|
|
// For tracking baseline stats in the Cite extension https://phabricator.wikimedia.org/T353798
|
|
// FIXME: This might be obsolete when the code moves to the Cite extension and the tracking there
|
|
// can check that state differently.
|
|
mw.config.set( 'wgPopupsReferencePreviewsVisible', !!referencePreviewsState );
|
|
|
|
mw.trackSubscribe( 'Popups.SettingChange', ( data ) => {
|
|
if ( data.previewType === TYPE_REFERENCE ) {
|
|
mw.track( LOGGING_SCHEMA, data );
|
|
}
|
|
} );
|
|
|
|
module.exports = referencePreviewsState !== null ? {
|
|
type: TYPE_REFERENCE,
|
|
selector: '#mw-content-text .reference a[ href*="#" ]',
|
|
delay: FETCH_DELAY_REFERENCE_TYPE,
|
|
gateway,
|
|
renderFn,
|
|
init: () => {
|
|
initReferencePreviewsInstrumentation();
|
|
}
|
|
} : null;
|
|
|
|
// Expose private methods for QUnit tests
|
|
if ( typeof QUnit !== 'undefined' ) {
|
|
module.exports = { private: {
|
|
createReferenceGateway: require( './createReferenceGateway.js' ),
|
|
createReferencePreview: require( './createReferencePreview.js' ),
|
|
isReferencePreviewsEnabled: require( './isReferencePreviewsEnabled.js' ),
|
|
setUserConfigFlags: require( './setUserConfigFlags.js' )
|
|
} };
|
|
}
|