From 6037fefbe044fbf61e7734923f3b625f10e910a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 17 Oct 2019 22:12:58 +0200 Subject: [PATCH] Fix media embeds which don't link to the file page Follow-up to da9b6fffbdba9007cfe893b1eafd1ccb42dbb537. Bug: T235707 Change-Id: Ie5a12bf274ae6178106f81a4c84686a88307c9fb --- modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js | 12 +++++++----- modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js index b6dbd3e481..d289c1c79e 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js @@ -83,12 +83,14 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter width = img.getAttribute( 'width' ); height = img.getAttribute( 'height' ); - // Convert absolute URLs to relative if the href refers to a page on this wiki. - // Otherwise Parsoid generates |link= options for copy-pasted images (T193253). href = imgWrapper.getAttribute( 'href' ); - targetData = ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref( href, converter.getTargetHtmlDocument() ); - if ( targetData.isInternal ) { - href = './' + targetData.title; + if ( href ) { + // Convert absolute URLs to relative if the href refers to a page on this wiki. + // Otherwise Parsoid generates |link= options for copy-pasted images (T193253). + targetData = ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref( href, converter.getTargetHtmlDocument() ); + if ( targetData.isInternal ) { + href = './' + targetData.title; + } } // Ensure that resource and href are identical if they refer to the same page. // https://www.mediawiki.org/w/?diff=931265&oldid=prev diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js index ea280a411a..26b6540db5 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWInlineImageNode.js @@ -64,12 +64,14 @@ ve.dm.MWInlineImageNode.static.toDataElement = function ( domElements, converter width = img.getAttribute( 'width' ), height = img.getAttribute( 'height' ); - // Convert absolute URLs to relative if the href refers to a page on this wiki. - // Otherwise Parsoid generates |link= options for copy-pasted images (T193253). href = imgWrapper.getAttribute( 'href' ); - targetData = ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref( href, converter.getTargetHtmlDocument() ); - if ( targetData.isInternal ) { - href = './' + targetData.title; + if ( href ) { + // Convert absolute URLs to relative if the href refers to a page on this wiki. + // Otherwise Parsoid generates |link= options for copy-pasted images (T193253). + targetData = ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref( href, converter.getTargetHtmlDocument() ); + if ( targetData.isInternal ) { + href = './' + targetData.title; + } } // Ensure that resource and href are identical if they refer to the same page. // https://www.mediawiki.org/w/?diff=931265&oldid=prev