mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-23 20:12:57 +00:00
179d402344
PHP classes and test are somewhat copies from the Popups codebase. Some refactoring was applied. More could be done. Not to sure if this should happen more in follow ups though. Could also reduce the complexity of checks on the JS side. Most of these things can only change on page load. The only dynamic part left is the anon user setting managed by the Popups extension. Note, that I needed to add a new PHP config for here although the other still exists and is needed in the Popups extension. This will change, when the user settings code also moves. I guess it's okay for now though. Both settings default to true and are not overridden in the config repos. Also needed to add the Gadget extension as phan dependency. Bug: T362771 Depends-On: Ia028c41f8aaa1c522dfc7c372e1ce51e40933a5e Change-Id: Ie6e8bc706235724494036c7f0d873f5c996c46e6
44 lines
1.6 KiB
JavaScript
44 lines
1.6 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 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( 'wgCiteReferencePreviewsVisible', !!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' )
|
|
} };
|
|
}
|