From 7579f6eb1f291ed4d36847c3d5f6d6e39c33e506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 18 Sep 2019 22:54:24 +0200 Subject: [PATCH] Fix linking to pages in media dialog/media context/internal link context If you had an image thumbnail for a file 'Foo?.png' on the page, ve.ui.MWMediaContextItem and ve.ui.MWMediaDialog did not escape the '?' when linking to it, which resulted in incorrect links. Similarly, if you had an internal link to the page 'Foo?', ve.ui.MWInternalLinkContextItem did not escape it. Additionally, the links were always generated as if the wiki was using short URLs, even when it is not (T233628). The approach using mw.Title is copied from ve.ui.MWGalleryDialog. Bug: T233628 Change-Id: I10256ed6883dae0ea216de4c0719f03d7fd19ae4 --- .../ui/contextitems/ve.ui.MWInternalLinkContextItem.js | 7 ++++--- modules/ve-mw/ui/contextitems/ve.ui.MWMediaContextItem.js | 4 ++-- modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/ve-mw/ui/contextitems/ve.ui.MWInternalLinkContextItem.js b/modules/ve-mw/ui/contextitems/ve.ui.MWInternalLinkContextItem.js index 1ed1b9a550..d8d6f8e63c 100644 --- a/modules/ve-mw/ui/contextitems/ve.ui.MWInternalLinkContextItem.js +++ b/modules/ve-mw/ui/contextitems/ve.ui.MWInternalLinkContextItem.js @@ -47,17 +47,18 @@ ve.ui.MWInternalLinkContextItem.static.modelClasses = [ ve.dm.MWInternalLinkAnno ve.ui.MWInternalLinkContextItem.static.generateBody = function ( linkCache, model, htmlDoc, context ) { var icon, $description, title = model.getAttribute( 'lookupTitle' ), - description = model.getAttribute( 'normalizedTitle' ), + normalizedTitle = model.getAttribute( 'normalizedTitle' ), href = model.getHref(), + titleObj = mw.Title.newFromText( ve.normalizeParsoidResourceName( href ) ), fragment = model.getFragment(), usePageImages = mw.config.get( 'wgVisualEditorConfig' ).usePageImages, usePageDescriptions = mw.config.get( 'wgVisualEditorConfig' ).usePageDescriptions, $wrapper = $( '
' ), $link = $( '' ) .addClass( 've-ui-linkContextItem-link' ) - .text( description ) + .text( normalizedTitle ) .attr( { - href: ve.resolveUrl( href, htmlDoc ), + href: titleObj.getUrl(), target: '_blank', rel: 'noopener' } ); diff --git a/modules/ve-mw/ui/contextitems/ve.ui.MWMediaContextItem.js b/modules/ve-mw/ui/contextitems/ve.ui.MWMediaContextItem.js index d5892b33c2..f51e8ca659 100644 --- a/modules/ve-mw/ui/contextitems/ve.ui.MWMediaContextItem.js +++ b/modules/ve-mw/ui/contextitems/ve.ui.MWMediaContextItem.js @@ -69,12 +69,12 @@ ve.ui.MWMediaContextItem.prototype.getDescription = function () { * @inheritdoc */ ve.ui.MWMediaContextItem.prototype.renderBody = function () { - var htmlDoc = this.context.getSurface().getModel().getDocument().getHtmlDocument(); + var title = mw.Title.newFromText( ve.normalizeParsoidResourceName( this.model.getAttribute( 'resource' ) ) ); this.$body.append( $( '' ) .text( this.getDescription() ) .attr( { - href: ve.resolveUrl( this.model.getAttribute( 'resource' ), htmlDoc ), + href: title.getUrl(), target: '_blank', rel: 'noopener' } ) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js index 3a65db5882..52016fecc5 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js @@ -920,12 +920,13 @@ ve.ui.MWMediaDialog.prototype.confirmSelectedImage = function () { * Update the filename fieldset (link to media page) */ ve.ui.MWMediaDialog.prototype.updateFilenameFieldset = function () { + var title = mw.Title.newFromText( ve.normalizeParsoidResourceName( this.imageModel.getResourceName() ) ); this.filenameFieldset.setLabel( $( '' ).append( document.createTextNode( this.imageModel.getFilename() + ' ' ), $( '' ) .addClass( 've-ui-mwMediaDialog-description-link' ) - .attr( 'href', ve.resolveUrl( this.imageModel.getResourceName(), this.getFragment().getDocument().getHtmlDocument() ) ) + .attr( 'href', title.getUrl() ) .attr( 'target', '_blank' ) .attr( 'rel', 'noopener' ) .text( ve.msg( 'visualeditor-dialog-media-content-description-link' ) )