mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-30 19:04:19 +00:00
Merge "Use original URL when setting download for original"
This commit is contained in:
commit
05c58ba0b9
|
@ -59,7 +59,7 @@
|
|||
"multimediaviewer-embed-tab": "Embed",
|
||||
"multimediaviewer-download-tab": "Download",
|
||||
"multimediaviewer-download-preview-link-title": "Preview in browser",
|
||||
"multimediaviewer-download-original-button-name": "Download original size",
|
||||
"multimediaviewer-download-original-button-name": "Download original file",
|
||||
"multimediaviewer-download-small-button-name": "Download small size",
|
||||
"multimediaviewer-download-medium-button-name": "Download medium size",
|
||||
"multimediaviewer-download-large-button-name": "Download large size",
|
||||
|
@ -81,7 +81,7 @@
|
|||
"multimediaviewer-embed-license": "Licensed under $1.",
|
||||
"multimediaviewer-embed-via": "Via $1.",
|
||||
"multimediaviewer-default-embed-dimensions": "Default thumbnail size",
|
||||
"multimediaviewer-original-embed-dimensions": "Original size $1",
|
||||
"multimediaviewer-original-embed-dimensions": "Original file $1",
|
||||
"multimediaviewer-large-embed-dimensions": "Large $1",
|
||||
"multimediaviewer-medium-embed-dimensions": "Medium $1",
|
||||
"multimediaviewer-small-embed-dimensions": "Small $1",
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
"multimediaviewer-embed-tab": "Tab title text for the file reuse panel - used for the section with embeddable HTML and wikitext.",
|
||||
"multimediaviewer-download-tab": "Tab title text for the file reuse panel - used for file download functionality.\n{{Identical|Download}}",
|
||||
"multimediaviewer-download-preview-link-title": "Text in the link that allows the user to preview the image of the selected size - used for file download functionality.",
|
||||
"multimediaviewer-download-original-button-name": "Text inside the button that lets the user download the original size image - used for file download functionality.",
|
||||
"multimediaviewer-download-original-button-name": "Text inside the button that lets the user download the original image - used for file download functionality.",
|
||||
"multimediaviewer-download-small-button-name": "Text inside the button that lets the user download a small version of the original image - used for file download functionality.",
|
||||
"multimediaviewer-download-medium-button-name": "Text inside the button that lets the user download a medium version of the original image - used for file download functionality.",
|
||||
"multimediaviewer-download-large-button-name": "Text inside the button that lets the user download a large version of the original image - used for file download functionality.",
|
||||
|
|
|
@ -45,6 +45,9 @@
|
|||
* @property {OO.ui.MenuItemWidget}
|
||||
*/
|
||||
this.defaultItem = this.downloadSizeMenu.getMenu().getSelectedItem();
|
||||
|
||||
/** @property {mw.mmv.model.Image|null} Image the download button currently points to. */
|
||||
this.image = null;
|
||||
}
|
||||
oo.inheritClass( Download, mw.mmv.ui.reuse.Tab );
|
||||
DP = Download.prototype;
|
||||
|
@ -145,19 +148,34 @@
|
|||
var download = this,
|
||||
value = item.getData();
|
||||
|
||||
if ( value.name === 'original' && this.image !== null ) {
|
||||
this.setDownloadUrl( this.image.url );
|
||||
this.setButtonText( value.name, this.getExtensionFromUrl( this.image.url ),
|
||||
value.width, value.height );
|
||||
} else {
|
||||
// Disable download while we get the image
|
||||
this.$downloadButton.addClass( 'disabledLink' );
|
||||
// Set a temporary message. It will be updated once we have the file type.
|
||||
this.setButtonText( value.name, this.imageExtension, value.width, value.height );
|
||||
|
||||
this.utils.getThumbnailUrlPromise( value.width ).done( function ( thumbnail ) {
|
||||
download.$downloadButton.attr( 'href', thumbnail.url + '?download' );
|
||||
download.$previewLink.attr( 'href', thumbnail.url );
|
||||
download.setDownloadUrl( thumbnail.url );
|
||||
download.setButtonText( value.name, download.getExtensionFromUrl( thumbnail.url ),
|
||||
value.width, value.height );
|
||||
// Re-enable download
|
||||
download.$downloadButton.removeClass( 'disabledLink' );
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the URL on the download button.
|
||||
* @param {string} url
|
||||
*/
|
||||
DP.setDownloadUrl = function ( url ) {
|
||||
this.$downloadButton.attr( 'href', url + '?download' );
|
||||
this.$previewLink.attr( 'href', url );
|
||||
|
||||
// Re-enable download
|
||||
this.$downloadButton.removeClass( 'disabledLink' );
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -200,6 +218,8 @@
|
|||
var sizeOptions = this.downloadSizeMenu.getMenu().getItems(),
|
||||
sizes = this.utils.getPossibleImageSizesForHtml( image.width, image.height );
|
||||
|
||||
this.image = image;
|
||||
|
||||
this.utils.updateMenuOptions( sizes, sizeOptions );
|
||||
|
||||
this.downloadSizeMenu.$element.addClass( 'active' );
|
||||
|
@ -221,6 +241,8 @@
|
|||
this.$downloadButton.attr( 'href', '' );
|
||||
this.$previewLink.attr( 'href', '' );
|
||||
this.imageExtension = undefined;
|
||||
|
||||
this.image = null;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
( function ( mw, $ ) {
|
||||
QUnit.module( 'mmv.ui.reuse.download', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sanity test, object creation and UI construction', 6, function ( assert ) {
|
||||
QUnit.test( 'Sanity test, object creation and UI construction', 9, function ( assert ) {
|
||||
var download = new mw.mmv.ui.reuse.Download( $( '#qunit-fixture' ) );
|
||||
|
||||
assert.ok( download, 'download UI element is created.' );
|
||||
|
@ -27,6 +27,10 @@
|
|||
assert.ok( download.downloadSizeMenu, 'Image size pulldown menu created.' );
|
||||
assert.ok( download.$previewLink, 'Preview link created.' );
|
||||
assert.ok( download.defaultItem, 'Default item set.' );
|
||||
|
||||
assert.strictEqual( download.$downloadButton.html(), '', 'Button has empty content.' );
|
||||
assert.strictEqual( download.$downloadButton.attr( 'href' ), undefined, 'Button href is empty.' );
|
||||
assert.strictEqual( download.$previewLink.attr( 'href' ), undefined, 'Preview link href is empty.' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'set()/empty():', 5, function ( assert ) {
|
||||
|
@ -106,23 +110,29 @@
|
|||
download.$selectionArrow.click();
|
||||
} );
|
||||
|
||||
QUnit.test( 'handleSizeSwitch():', 6, function ( assert ) {
|
||||
QUnit.test( 'handleSizeSwitch():', 3, function ( assert ) {
|
||||
var download = new mw.mmv.ui.reuse.Download( $( '#qunit-fixture' ) ),
|
||||
newImageUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/NewFoobar.jpg';
|
||||
|
||||
assert.strictEqual( download.$downloadButton.html(), '', 'Button has empty content.' );
|
||||
assert.strictEqual( download.$downloadButton.attr( 'href' ), undefined, 'Button href is empty.' );
|
||||
assert.strictEqual( download.$previewLink.attr( 'href' ), undefined, 'Preview link href is empty.' );
|
||||
|
||||
download.utils.getThumbnailUrlPromise = function() {
|
||||
download.utils.getThumbnailUrlPromise = function () {
|
||||
return $.Deferred().resolve( { url: newImageUrl } ).promise();
|
||||
};
|
||||
|
||||
download.setDownloadUrl = function ( url ) {
|
||||
assert.strictEqual( url, newImageUrl, 'URL passed to setDownloadUrl is correct' );
|
||||
};
|
||||
|
||||
download.handleSizeSwitch( download.downloadSizeMenu.getMenu().getSelectedItem() );
|
||||
|
||||
assert.ok( download.$downloadButton.html().match( /original.*/ ), 'Button message updated.' );
|
||||
assert.strictEqual( download.$downloadButton.attr( 'href' ), newImageUrl + '?download', 'Button href updated.' );
|
||||
assert.strictEqual( download.$previewLink.attr( 'href' ), newImageUrl, 'Preview link href updated.' );
|
||||
|
||||
download.image = { url: newImageUrl };
|
||||
|
||||
download.utils.getThumbnailUrlPromise = function () {
|
||||
assert.ok( false, 'Should not fetch the thumbnail if the image is original size.' );
|
||||
};
|
||||
|
||||
download.handleSizeSwitch( download.downloadSizeMenu.getMenu().getSelectedItem() );
|
||||
} );
|
||||
|
||||
QUnit.test( 'setButtonText() sanity check:', 2, function ( assert ) {
|
||||
|
@ -143,4 +153,15 @@
|
|||
assert.strictEqual( download.getExtensionFromUrl( 'http://example.com/bing/foo.bar.png' ),
|
||||
'png', 'Extension is parsed correctly' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'setDownloadUrl', 3, function ( assert ) {
|
||||
var download = new mw.mmv.ui.reuse.Download( $( '#qunit-fixture' ) ),
|
||||
imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/NewFoobar.jpg';
|
||||
|
||||
download.setDownloadUrl( imageUrl );
|
||||
|
||||
assert.strictEqual( download.$downloadButton.attr( 'href' ), imageUrl + '?download', 'Download link is set correctly.' );
|
||||
assert.strictEqual( download.$previewLink.attr( 'href' ), imageUrl, 'Preview link is set correctly.' );
|
||||
assert.ok( !download.$downloadButton.hasClass( 'disabledLink' ), 'Download link is enabled.' );
|
||||
} );
|
||||
}( mediaWiki, jQuery ) );
|
||||
|
|
Loading…
Reference in a new issue