From 5db452f5fa9e92103ab152cfd938b129b6ba62fd Mon Sep 17 00:00:00 2001 From: David Lynch Date: Tue, 28 Nov 2023 11:37:42 -0600 Subject: [PATCH] Fix Gallery images always having |link=| and |alt=| Link is fixed by having the gallery image search results automatically link to the image, which will resolve down to there being no `link=` in the output. This lets us preserve whatever existing link has been applied from source when editing gallery images later. Follow-up to Iefc520b8513e833665dae9d5c3a9dca2762264a6 Bug: T350912 Change-Id: Iab21f72b7f1625d75fe52471b33718606c469518 --- modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js | 5 +++-- modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js index 60dcedab20..1406c37e13 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWGalleryImageNode.js @@ -230,10 +230,11 @@ ve.dm.MWGalleryImageNode.static.toDomElements = function ( data, doc, converter while ( captionWrapper.firstChild ) { li.appendChild( captionWrapper.firstChild ); } + var captionText = ve.dm.MWGalleryImageNode.static.textContentFromCaption( li ).trim(); if ( img.nodeName.toLowerCase() === 'img' ) { - if ( attributes.altTextSame ) { - img.setAttribute( 'alt', ve.dm.MWGalleryImageNode.static.textContentFromCaption( li ).trim() ); + if ( attributes.altTextSame && captionText ) { + img.setAttribute( 'alt', captionText ); } else if ( typeof alt === 'string' ) { img.setAttribute( 'alt', alt ); } diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js index 007fe62eae..4418213c23 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js @@ -671,7 +671,11 @@ ve.ui.MWGalleryDialog.prototype.onRequestImagesSuccess = function ( response ) { resource: title, altText: null, altTextSame: true, - href: null, + // TODO: support changing the link in the UI somewhere; + // for now, always link to the resource. Do it here when + // generating new results, so existing links from source + // will be preserved. + href: title, src: '', height: thumbUrls[ title ].height, width: thumbUrls[ title ].width,