Merge "Revert "Remove global for if previews are shown""

This commit is contained in:
jenkins-bot 2024-04-22 09:00:09 +00:00 committed by Gerrit Code Review
commit 7a63c9fa95
2 changed files with 18 additions and 9 deletions

View file

@ -13,6 +13,11 @@ const referencePreviewsState = isReferencePreviewsEnabled(
);
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 );

View file

@ -11,10 +11,10 @@
* @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsCite
*/
const isReferencePreviewsEnabled =
require( './ext.cite.referencePreviews/isReferencePreviewsEnabled.js' );
const CITE_BASELINE_LOGGING_SCHEMA = 'ext.cite.baseline';
// Same as in the Popups extension
// FIXME: Could be an extension wide constant when Reference Previews is merged into this code base
const REFERENCE_PREVIEWS_LOGGING_SCHEMA = 'event.ReferencePreviewsPopups';
// EventLogging may not be installed
mw.loader.using( 'ext.eventLogging' ).then( function () {
@ -25,24 +25,28 @@ mw.loader.using( 'ext.eventLogging' ).then( function () {
return;
}
// FIXME: This might be obsolete when the code moves to the this extension
mw.trackSubscribe( REFERENCE_PREVIEWS_LOGGING_SCHEMA, function ( type, data ) {
if ( data.action.indexOf( 'anonymous' ) !== -1 ) {
mw.config.set( 'wgPopupsReferencePreviewsVisible', data.action === 'anonymousEnabled' );
}
} );
// eslint-disable-next-line no-jquery/no-global-selector
$( '#mw-content-text' ).on(
'click',
// Footnote links, references block in VisualEditor, and reference content links.
'.reference a[ href*="#" ], .mw-reference-text a, .reference-text a',
function () {
const referencePreviewsState = isReferencePreviewsEnabled(
mw.user,
mw.popups.isEnabled,
mw.config
);
const isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
mw.eventLog.dispatch( CITE_BASELINE_LOGGING_SCHEMA, {
action: ( isInReferenceBlock ?
'clickedReferenceContentLink' :
'clickedFootnote' ),
// FIXME: This might be obsolete when the code moves to the this extension and
// we get state directly.
// eslint-disable-next-line camelcase
with_ref_previews: referencePreviewsState
with_ref_previews: mw.config.get( 'wgPopupsReferencePreviewsVisible' )
} );
}
);