mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-03 18:36:20 +00:00
7579f6eb1f
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
87 lines
2.2 KiB
JavaScript
87 lines
2.2 KiB
JavaScript
/*!
|
|
* VisualEditor MWMediaContextItem class.
|
|
*
|
|
* @copyright 2011-2017 VisualEditor Team and others; see http://ve.mit-license.org
|
|
*/
|
|
|
|
/**
|
|
* Context item for a MWImageNode.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.LinearContextItem
|
|
*
|
|
* @constructor
|
|
* @param {ve.ui.Context} context Context item is in
|
|
* @param {ve.dm.Model} model Model item is related to
|
|
* @param {Object} config Configuration options
|
|
*/
|
|
ve.ui.MWMediaContextItem = function VeUiMWMediaContextItem( context, model ) {
|
|
var mediaClass;
|
|
|
|
// Parent constructor
|
|
ve.ui.MWMediaContextItem.super.apply( this, arguments );
|
|
|
|
// Initialization
|
|
this.$element.addClass( 've-ui-mwMediaContextItem' );
|
|
|
|
mediaClass = model.getAttribute( 'mediaClass' ) || 'Image';
|
|
|
|
this.setIcon( model.getAttribute( 'isError' ) ? 'imageBroken' : {
|
|
Image: 'image',
|
|
// TODO: Better icons for audio/video
|
|
Audio: 'play',
|
|
Video: 'play'
|
|
}[ mediaClass ] );
|
|
// The following messages are used here:
|
|
// * visualeditor-media-title-audio
|
|
// * visualeditor-media-title-image
|
|
// * visualeditor-media-title-video
|
|
this.setLabel( ve.msg( 'visualeditor-media-title-' + mediaClass.toLowerCase() ) );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWMediaContextItem, ve.ui.LinearContextItem );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ui.MWMediaContextItem.static.name = 'mwMedia';
|
|
|
|
ve.ui.MWMediaContextItem.static.icon = 'image';
|
|
|
|
ve.ui.MWMediaContextItem.static.label =
|
|
OO.ui.deferMsg( 'visualeditor-media-title-image' );
|
|
|
|
ve.ui.MWMediaContextItem.static.modelClasses = [ ve.dm.MWBlockImageNode, ve.dm.MWInlineImageNode ];
|
|
|
|
ve.ui.MWMediaContextItem.static.commandName = 'media';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.MWMediaContextItem.prototype.getDescription = function () {
|
|
return ve.ce.nodeFactory.getDescription( this.model );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.MWMediaContextItem.prototype.renderBody = function () {
|
|
var title = mw.Title.newFromText( ve.normalizeParsoidResourceName( this.model.getAttribute( 'resource' ) ) );
|
|
this.$body.append(
|
|
$( '<a>' )
|
|
.text( this.getDescription() )
|
|
.attr( {
|
|
href: title.getUrl(),
|
|
target: '_blank',
|
|
rel: 'noopener'
|
|
} )
|
|
);
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWMediaContextItem );
|