Set a global when reference previews are visible.

Used for tracking baseline stats in the Cite extension.

Also fixed the wireing of the Reference Preview type constant so
that the settings can be tracked. Not sure where this should go
best in the new code.

Bug: T353798
Change-Id: I1c434f0098ae23bd62256686a658e3d5ef7f70b9
This commit is contained in:
WMDE-Fisch 2024-01-09 15:19:28 +01:00 committed by Jon Robson
parent e15e2c4d14
commit 694b96a19f
7 changed files with 14 additions and 6 deletions

View file

@ -11,7 +11,6 @@ import { previewTypes } from '../../src/preview/model';
import scaleDownThumbnail from './scaleDownThumbnail';
registerPreviewUI( previewTypes.TYPE_PAGE, createPagePreview );
registerPreviewUI( previewTypes.TYPE_REFERENCE, createReferencePreview );
registerPreviewUI( previewTypes.TYPE_DISAMBIGUATION, createDisambiguationPreview );
/**
@ -95,8 +94,8 @@ function createPopup( model, layoutHint ) {
link.setAttribute( 'href', '#' );
link.setAttribute( 'class', 'popups-storybook-link' );
link.textContent = `Page preview ${layout.flippedX ? 'flipped-x' : ''}
${layout.flippedY ? 'flipped-y' : ''}
${preview.isTall ? '(landscape)' : '(portrait)'}
${layout.flippedY ? 'flipped-y' : ''}
${preview.isTall ? '(landscape)' : '(portrait)'}
${preview.hasThumbnail ? 'with thumbnail' : ''}`;
wrapper.appendChild( link );

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -6,9 +6,17 @@ import { TYPE_REFERENCE, FETCH_DELAY_REFERENCE_TYPE } from './constants';
import setUserConfigFlags from './setUserConfigFlags';
setUserConfigFlags( mw.config );
const referencePreviewsState = isReferencePreviewsEnabled( mw.user, mw.popups.isEnabled, 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 );
window.refPreviews = referencePreviewsState !== null ? {
type: TYPE_REFERENCE,
selector: '#mw-content-text .reference a[ href*="#" ]',

View file

@ -1,4 +1,5 @@
import { previewTypes } from './preview/model';
import { TYPE_REFERENCE } from './ext.popups.referencePreviews/constants.js';
/**
* @module userSettings
@ -33,7 +34,7 @@ export default function createUserSettings( storage ) {
const isRefsDisabled = !!storage.get( REFERENCE_PREVIEWS_ENABLED_KEY );
if ( isRefsDisabled ) {
storage.remove( REFERENCE_PREVIEWS_ENABLED_KEY );
this.storePreviewTypeEnabled( previewTypes.TYPE_REFERENCE, false );
this.storePreviewTypeEnabled( TYPE_REFERENCE, false );
}
},
/**
@ -60,7 +61,7 @@ export default function createUserSettings( storage ) {
* @param {boolean} enabled
*/
storePreviewTypeEnabled( previewType, enabled ) {
if ( previewType === previewTypes.TYPE_REFERENCE ) {
if ( previewType === TYPE_REFERENCE ) {
mw.track( REFERENCE_PREVIEWS_LOGGING_SCHEMA, {
action: enabled ? 'anonymousEnabled' : 'anonymousDisabled'
} );