From afdbf2d46d2d3c15aed9d519b1eeb221a584b941 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Mon, 15 Apr 2024 20:17:25 +0200 Subject: [PATCH] Remove global for if previews are shown This global was needed to communicate the actual state of the previews from Popups to Cite. Now this setting can be retrieved in a more direct way. Change-Id: I592761bb0121abcf7e8ab279b7385d6920cce37e --- modules/ext.cite.referencePreviews/index.js | 5 ----- modules/ext.cite.tracking.js | 22 +++++++++------------ 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/modules/ext.cite.referencePreviews/index.js b/modules/ext.cite.referencePreviews/index.js index 323ae9377..9810a9b4f 100644 --- a/modules/ext.cite.referencePreviews/index.js +++ b/modules/ext.cite.referencePreviews/index.js @@ -13,11 +13,6 @@ 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 ); diff --git a/modules/ext.cite.tracking.js b/modules/ext.cite.tracking.js index 78d71deaf..d1df0bf3c 100644 --- a/modules/ext.cite.tracking.js +++ b/modules/ext.cite.tracking.js @@ -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,28 +25,24 @@ 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: mw.config.get( 'wgPopupsReferencePreviewsVisible' ) + with_ref_previews: referencePreviewsState } ); } );