mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-12-01 03:06:17 +00:00
Merge "Refactor to a data model"
This commit is contained in:
commit
03ef24563b
|
@ -86,6 +86,23 @@ $wgResourceModules['ext.multimediaViewer.lightboxinterface'] = array_merge( arra
|
||||||
),
|
),
|
||||||
), $moduleInfoMMV );
|
), $moduleInfoMMV );
|
||||||
|
|
||||||
|
$wgResourceModules['ext.multimediaViewer.dataModel'] = array_merge( array(
|
||||||
|
'scripts' => array(
|
||||||
|
'ext.multimediaViewer.dataModel.js',
|
||||||
|
),
|
||||||
|
|
||||||
|
'dependencies' => array(
|
||||||
|
'ext.multimediaViewer.base',
|
||||||
|
'oojs',
|
||||||
|
),
|
||||||
|
), $moduleInfoMMV );
|
||||||
|
|
||||||
|
$wgResourceModules['ext.multimediaViewer.base'] = array_merge( array(
|
||||||
|
'scripts' => array(
|
||||||
|
'mmv.js',
|
||||||
|
),
|
||||||
|
), $moduleInfoMMV );
|
||||||
|
|
||||||
$wgResourceModules['ext.multimediaViewer'] = array_merge( array(
|
$wgResourceModules['ext.multimediaViewer'] = array_merge( array(
|
||||||
'scripts' => array(
|
'scripts' => array(
|
||||||
'ext.multimediaViewer.js',
|
'ext.multimediaViewer.js',
|
||||||
|
@ -102,6 +119,7 @@ $wgResourceModules['ext.multimediaViewer'] = array_merge( array(
|
||||||
'mediawiki.Title',
|
'mediawiki.Title',
|
||||||
'jquery.ui.dialog',
|
'jquery.ui.dialog',
|
||||||
'jquery.hidpi',
|
'jquery.hidpi',
|
||||||
|
'ext.multimediaViewer.dataModel',
|
||||||
),
|
),
|
||||||
|
|
||||||
'messages' => array(
|
'messages' => array(
|
||||||
|
|
|
@ -118,6 +118,7 @@ class MultimediaViewerHooks {
|
||||||
$testModules['qunit']['ext.multimediaViewer.tests'] = array(
|
$testModules['qunit']['ext.multimediaViewer.tests'] = array(
|
||||||
'scripts' => array(
|
'scripts' => array(
|
||||||
'tests/qunit/ext.multimediaViewer.test.js',
|
'tests/qunit/ext.multimediaViewer.test.js',
|
||||||
|
'tests/qunit/ext.multimediaViewer.dataModel.test.js',
|
||||||
'tests/qunit/ext.multimediaViewer.lightboxinterface.test.js',
|
'tests/qunit/ext.multimediaViewer.lightboxinterface.test.js',
|
||||||
'tests/qunit/lightboximage.test.js',
|
'tests/qunit/lightboximage.test.js',
|
||||||
'tests/qunit/lightboxinterface.test.js',
|
'tests/qunit/lightboxinterface.test.js',
|
||||||
|
|
303
resources/ext.multimediaViewer/ext.multimediaViewer.dataModel.js
Normal file
303
resources/ext.multimediaViewer/ext.multimediaViewer.dataModel.js
Normal file
|
@ -0,0 +1,303 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
||||||
|
*
|
||||||
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
( function ( mw, oo ) {
|
||||||
|
/**
|
||||||
|
* @class mw.mmv.model.Image
|
||||||
|
* Represents information about a single image
|
||||||
|
* @constructor
|
||||||
|
* @param {mw.Title} title
|
||||||
|
* @param {number} size Filesize in bytes of the original image
|
||||||
|
* @param {number} width Width of the original image
|
||||||
|
* @param {number} height Height of the original image
|
||||||
|
* @param {string} mimeType
|
||||||
|
* @param {string} url URL to the image itself (original version)
|
||||||
|
* @param {string} descriptionUrl URL to the image description page
|
||||||
|
* @param {string} repo The repository this image belongs to
|
||||||
|
* @param {string} lastUploader The last person to upload a version of this image.
|
||||||
|
* @param {string} lastUploadDateTime The time and date the last upload occurred
|
||||||
|
* @param {string} originalUploadDateTime The time and date the original upload occurred
|
||||||
|
* @param {string} description
|
||||||
|
* @param {string} source
|
||||||
|
* @param {string} author
|
||||||
|
* @param {string} license
|
||||||
|
*/
|
||||||
|
function Image(
|
||||||
|
title,
|
||||||
|
size,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
mimeType,
|
||||||
|
url,
|
||||||
|
descriptionUrl,
|
||||||
|
repo,
|
||||||
|
lastUploader,
|
||||||
|
uploadDateTime,
|
||||||
|
creationDateTime,
|
||||||
|
description,
|
||||||
|
source,
|
||||||
|
author,
|
||||||
|
license
|
||||||
|
) {
|
||||||
|
/** @property {mw.Title} title */
|
||||||
|
this.title = title;
|
||||||
|
|
||||||
|
/** @property {number} size */
|
||||||
|
this.size = size;
|
||||||
|
|
||||||
|
/** @property {number} width */
|
||||||
|
this.width = width;
|
||||||
|
|
||||||
|
/** @property {number} height */
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
/** @property {string} mimeType */
|
||||||
|
this.mimeType = mimeType;
|
||||||
|
|
||||||
|
/** @property {string} url */
|
||||||
|
this.url = url;
|
||||||
|
|
||||||
|
/** @property {string} descriptionUrl */
|
||||||
|
this.descriptionUrl = descriptionUrl;
|
||||||
|
|
||||||
|
/** @property {string} repo */
|
||||||
|
this.repo = repo;
|
||||||
|
|
||||||
|
/** @property {string} lastUploader */
|
||||||
|
this.lastUploader = lastUploader;
|
||||||
|
|
||||||
|
/** @property {string} uploadDateTime */
|
||||||
|
this.uploadDateTime = uploadDateTime;
|
||||||
|
|
||||||
|
/** @property {string} creationDateTime */
|
||||||
|
this.creationDateTime = creationDateTime;
|
||||||
|
|
||||||
|
/** @property {string} description */
|
||||||
|
this.description = description;
|
||||||
|
|
||||||
|
/** @property {string} source */
|
||||||
|
this.source = source;
|
||||||
|
|
||||||
|
/** @property {string} author */
|
||||||
|
this.author = author;
|
||||||
|
|
||||||
|
/** @property {string} license */
|
||||||
|
this.license = license;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {object} thumbUrls
|
||||||
|
* An object indexed by image widths
|
||||||
|
* with URLs to appropriately sized thumbnails
|
||||||
|
*/
|
||||||
|
this.thumbUrls = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method
|
||||||
|
* @static
|
||||||
|
* Constructs a new Image object out of an object containing
|
||||||
|
* imageinfo data from an API response.
|
||||||
|
* @param {mw.Title} title
|
||||||
|
* @param {object} imageInfo
|
||||||
|
* @returns {mw.mmv.model.Image}
|
||||||
|
*/
|
||||||
|
Image.newFromImageInfo = function ( title, imageInfo ) {
|
||||||
|
var uploadDateTime, creationDateTime, imageData,
|
||||||
|
description, source, author, license,
|
||||||
|
innerInfo = imageInfo.imageinfo[0],
|
||||||
|
extmeta = innerInfo.extmetadata;
|
||||||
|
|
||||||
|
if ( extmeta ) {
|
||||||
|
creationDateTime = extmeta.DateTimeOriginal;
|
||||||
|
uploadDateTime = extmeta.DateTime;
|
||||||
|
|
||||||
|
if ( uploadDateTime ) {
|
||||||
|
uploadDateTime = uploadDateTime.value.replace( /<.*?>/g, '' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( creationDateTime ) {
|
||||||
|
creationDateTime = creationDateTime.value.replace( /<.*?>/g, '' );
|
||||||
|
}
|
||||||
|
|
||||||
|
description = extmeta.ImageDescription && extmeta.ImageDescription.value;
|
||||||
|
source = extmeta.Credit && extmeta.Credit.value;
|
||||||
|
author = extmeta.Artist && extmeta.Artist.value;
|
||||||
|
license = extmeta.License && extmeta.License.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
imageData = new Image(
|
||||||
|
title,
|
||||||
|
innerInfo.size,
|
||||||
|
innerInfo.width,
|
||||||
|
innerInfo.height,
|
||||||
|
innerInfo.mime,
|
||||||
|
innerInfo.url,
|
||||||
|
innerInfo.descriptionurl,
|
||||||
|
imageInfo.imagerepository,
|
||||||
|
innerInfo.user,
|
||||||
|
uploadDateTime,
|
||||||
|
creationDateTime,
|
||||||
|
description,
|
||||||
|
source,
|
||||||
|
author,
|
||||||
|
license
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( innerInfo.thumburl ) {
|
||||||
|
imageData.addThumbUrl(
|
||||||
|
innerInfo.thumbwidth,
|
||||||
|
innerInfo.thumburl
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageData;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method
|
||||||
|
* Add a thumb URL
|
||||||
|
* @param {number} width
|
||||||
|
* @param {string} url
|
||||||
|
*/
|
||||||
|
Image.prototype.addThumbUrl = function ( width, url ) {
|
||||||
|
this.thumbUrls[width] = url;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method
|
||||||
|
* Get a thumb URL if we have it.
|
||||||
|
* @param {number} width
|
||||||
|
* @returns {string|undefined}
|
||||||
|
*/
|
||||||
|
Image.prototype.getThumbUrl = function ( width ) {
|
||||||
|
return this.thumbUrls[width];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method
|
||||||
|
* Check whether the image is CC-licensed.
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
Image.prototype.isCcLicensed = function () {
|
||||||
|
return this.license && this.license.substr( 0, 2 ) === 'cc';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class mw.mmv.model.Repo
|
||||||
|
* Represents information about a single image repository
|
||||||
|
* @constructor
|
||||||
|
* @param {string} displayName
|
||||||
|
* @param {boolean} isLocal
|
||||||
|
*/
|
||||||
|
function Repo(
|
||||||
|
displayName,
|
||||||
|
isLocal
|
||||||
|
) {
|
||||||
|
/** @property {string} displayName */
|
||||||
|
this.displayName = displayName;
|
||||||
|
|
||||||
|
/** @property {boolean} isLocal */
|
||||||
|
this.isLocal = isLocal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method
|
||||||
|
* @static
|
||||||
|
* Creates a new object from repoInfo we found in an API response.
|
||||||
|
* @param {object} repoInfo
|
||||||
|
* @returns {mw.mmv.model.Repo}
|
||||||
|
*/
|
||||||
|
Repo.newFromRepoInfo = function ( repoInfo ) {
|
||||||
|
if ( repoInfo.apiurl ) {
|
||||||
|
return new ForeignApiRepo(
|
||||||
|
repoInfo.displayname,
|
||||||
|
false,
|
||||||
|
repoInfo.apiurl,
|
||||||
|
repoInfo.server,
|
||||||
|
repoInfo.articlepath
|
||||||
|
);
|
||||||
|
} else if ( repoInfo.descBaseUrl ) {
|
||||||
|
return new ForeignDbRepo(
|
||||||
|
repoInfo.displayname,
|
||||||
|
false,
|
||||||
|
repoInfo.descBaseUrl
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return new Repo( repoInfo.displayname, repoInfo.local );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class mw.mmv.model.ForeignApiRepo
|
||||||
|
* Represents information about a foreign API repository
|
||||||
|
* @extends Repo
|
||||||
|
* @constructor
|
||||||
|
* @inheritdoc
|
||||||
|
* @param {string} apiUrl URL to the wiki's api.php
|
||||||
|
* @param {string} server Hostname for the wiki
|
||||||
|
* @param {string} articlePath Path to articles on the wiki, relative to the hostname.
|
||||||
|
*/
|
||||||
|
function ForeignApiRepo(
|
||||||
|
displayName,
|
||||||
|
isLocal,
|
||||||
|
apiUrl,
|
||||||
|
server,
|
||||||
|
articlePath
|
||||||
|
) {
|
||||||
|
Repo.call( this, displayName, isLocal );
|
||||||
|
|
||||||
|
/** @property {string} apiUrl */
|
||||||
|
this.apiUrl = apiUrl;
|
||||||
|
|
||||||
|
/** @property {string} server */
|
||||||
|
this.server = server;
|
||||||
|
|
||||||
|
/** @property {string} articlePath */
|
||||||
|
this.articlePath = articlePath;
|
||||||
|
|
||||||
|
/** @property {string} absoluteArticlePath */
|
||||||
|
this.absoluteArticlePath = server + articlePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
oo.inheritClass( ForeignApiRepo, Repo );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class mw.mmv.model.ForeignDbRepo
|
||||||
|
* Represents information about a foreign, shared DB repository
|
||||||
|
* @extends Repo
|
||||||
|
* @constructor
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
function ForeignDbRepo(
|
||||||
|
displayName,
|
||||||
|
isLocal,
|
||||||
|
descBaseUrl
|
||||||
|
) {
|
||||||
|
Repo.call( this, displayName, isLocal );
|
||||||
|
|
||||||
|
/** @property {string} descBaseUrl */
|
||||||
|
this.descBaseUrl = descBaseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
oo.inheritClass( ForeignDbRepo, Repo );
|
||||||
|
|
||||||
|
mw.mmv.model = {};
|
||||||
|
mw.mmv.model.Image = Image;
|
||||||
|
mw.mmv.model.Repo = Repo;
|
||||||
|
mw.mmv.model.ForeignApiRepo = ForeignApiRepo;
|
||||||
|
mw.mmv.model.ForeignDbRepo = ForeignDbRepo;
|
||||||
|
}( mediaWiki, OO ) );
|
|
@ -115,8 +115,11 @@
|
||||||
this.api = new mw.Api();
|
this.api = new mw.Api();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* imageInfo object. TODO: Describe structure and valid states.
|
* imageInfo object, used for caching - promises will resolve with
|
||||||
* @property {Object}
|
* an mw.mmv.model.Image object, a repoInfo object, the best width for
|
||||||
|
* the current screen configuration, and the width requested from
|
||||||
|
* the server (if any).
|
||||||
|
* @property {jQuery.Promise[]}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.imageInfo = {};
|
this.imageInfo = {};
|
||||||
|
@ -317,8 +320,8 @@
|
||||||
var viewer = this,
|
var viewer = this,
|
||||||
fileTitle = this.currentImageFileTitle;
|
fileTitle = this.currentImageFileTitle;
|
||||||
|
|
||||||
this.fetchImageInfo( fileTitle, [ 'url' ] ).done( function ( imageInfo, repoInfo, targetWidth ) {
|
this.fetchImageInfo( fileTitle, [ 'url' ] ).done( function ( imageData, repoInfo, targetWidth ) {
|
||||||
viewer.loadResizedImage( ui, imageInfo, targetWidth );
|
viewer.loadResizedImage( ui, imageData, targetWidth );
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -328,31 +331,30 @@
|
||||||
* @protected
|
* @protected
|
||||||
*
|
*
|
||||||
* @param {LightboxInterface} ui lightbox that got resized
|
* @param {LightboxInterface} ui lightbox that got resized
|
||||||
* @param {Object} imageInfo information regarding the new resized image
|
* @param {mw.mmv.model.Image} imageData information regarding the new resized image
|
||||||
* @param {number} targetWidth
|
* @param {number} targetWidth
|
||||||
*/
|
*/
|
||||||
MMVP.loadResizedImage = function ( ui, imageInfo, targetWidth ) {
|
MMVP.loadResizedImage = function ( ui, imageData, targetWidth, requestedWidth ) {
|
||||||
var innerInfo, rpid, viewer, image;
|
var rpid, viewer, image, maybeThumb;
|
||||||
|
|
||||||
// Replace image only if data was returned.
|
// Replace image only if data was returned.
|
||||||
if ( imageInfo ) {
|
if ( imageData ) {
|
||||||
viewer = this;
|
viewer = this;
|
||||||
image = new Image();
|
image = new Image();
|
||||||
|
|
||||||
innerInfo = imageInfo.imageinfo[0];
|
|
||||||
|
|
||||||
image.onload = function () {
|
image.onload = function () {
|
||||||
viewer.profileEnd( rpid );
|
viewer.profileEnd( rpid );
|
||||||
};
|
};
|
||||||
|
|
||||||
rpid = this.profileStart( 'image-resize', {
|
rpid = this.profileStart( 'image-resize', {
|
||||||
width: innerInfo.width,
|
width: imageData.width,
|
||||||
height: innerInfo.height,
|
height: imageData.height,
|
||||||
fileSize: innerInfo.size
|
fileSize: imageData.size
|
||||||
}, innerInfo.mime );
|
}, imageData.mimeType );
|
||||||
|
|
||||||
image.src = innerInfo.thumburl || innerInfo.url;
|
maybeThumb = imageData.getThumbUrl( requestedWidth );
|
||||||
if ( innerInfo.thumbwidth > targetWidth ) {
|
image.src = maybeThumb || imageData.url;
|
||||||
|
if ( maybeThumb && requestedWidth > targetWidth || !maybeThumb && imageData.width > targetWidth ) {
|
||||||
image.width = targetWidth;
|
image.width = targetWidth;
|
||||||
}
|
}
|
||||||
ui.replaceImageWith( image );
|
ui.replaceImageWith( image );
|
||||||
|
@ -463,24 +465,32 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get image information out of an API response.
|
* @method
|
||||||
* @param {Object[]} images The query.pages member of the API response.
|
* Get first (hopefully only) member of an object.
|
||||||
* @returns {Object} Representing image information.
|
* @param {Array|Object} things
|
||||||
|
* @returns {Mixed}
|
||||||
*/
|
*/
|
||||||
MMVP.getImageInfo = function ( images ) {
|
MMVP.getFirst = function ( things ) {
|
||||||
var imageInfo;
|
var thing;
|
||||||
|
|
||||||
if ( images ) {
|
if ( things ) {
|
||||||
$.each( images, function ( i, page ) {
|
$.each( things, function ( i, thisone ) {
|
||||||
imageInfo = page;
|
thing = thisone;
|
||||||
return false;
|
return false;
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
return imageInfo;
|
return thing;
|
||||||
};
|
};
|
||||||
|
|
||||||
MMVP.setImageInfo = function ( fileTitle, imageInfo ) {
|
/**
|
||||||
|
* @method
|
||||||
|
* Set the image information in the UI.
|
||||||
|
* @param {mw.Title} fileTitle
|
||||||
|
* @param {mw.mmv.model.Image} imageData
|
||||||
|
* @param {mw.mmv.model.Repo} repoData
|
||||||
|
*/
|
||||||
|
MMVP.setImageInfo = function ( fileTitle, imageData, repoData ) {
|
||||||
function whitelistHtml( $el ) {
|
function whitelistHtml( $el ) {
|
||||||
var child, $prev, $child = $el.children().first();
|
var child, $prev, $child = $el.children().first();
|
||||||
|
|
||||||
|
@ -508,37 +518,22 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var extmeta, gfpid,
|
var gfpid,
|
||||||
repoInfo,
|
msgname,
|
||||||
desc,
|
|
||||||
datetime, dtmsg,
|
|
||||||
license, msgname,
|
|
||||||
username,
|
|
||||||
source, author,
|
|
||||||
viewer = this,
|
viewer = this,
|
||||||
ui = this.lightbox.iface,
|
ui = this.lightbox.iface;
|
||||||
innerInfo = imageInfo.imageinfo[0] || {};
|
|
||||||
|
|
||||||
ui.$title.text( fileTitle.getNameText() );
|
ui.$title.text( fileTitle.getNameText() );
|
||||||
|
|
||||||
ui.$useFile.data( 'title', fileTitle );
|
ui.initUseFileData( fileTitle, imageData.url, repoData.isLocal );
|
||||||
ui.$useFile.data( 'src', innerInfo.url );
|
|
||||||
ui.$useFileLi.removeClass( 'empty' );
|
ui.$useFileLi.removeClass( 'empty' );
|
||||||
|
|
||||||
if ( this.repoInfo ) {
|
ui.setRepoDisplayName( repoData.displayname, repoData.isLocal );
|
||||||
repoInfo = this.repoInfo[imageInfo.imagerepository];
|
ui.setFilePageLink( imageData.descriptionUrl );
|
||||||
}
|
|
||||||
|
|
||||||
if ( repoInfo ) {
|
ui.$repoLi.removeClass( 'empty' );
|
||||||
ui.setRepoDisplayName( repoInfo.displayname, repoInfo.local );
|
|
||||||
ui.setFilePageLink( repoInfo, fileTitle );
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.$repoLi.toggleClass( 'empty', !repoInfo );
|
if ( imageData.lastUploader ) {
|
||||||
|
|
||||||
username = innerInfo.user;
|
|
||||||
|
|
||||||
if ( username ) {
|
|
||||||
gfpid = this.profileStart( 'gender-fetch' );
|
gfpid = this.profileStart( 'gender-fetch' );
|
||||||
|
|
||||||
// TODO: Reuse the api member, fix everywhere.
|
// TODO: Reuse the api member, fix everywhere.
|
||||||
|
@ -546,72 +541,65 @@
|
||||||
// TODO this is ugly as hell, let's fix this in core.
|
// TODO this is ugly as hell, let's fix this in core.
|
||||||
new mw.Api( {
|
new mw.Api( {
|
||||||
ajax: {
|
ajax: {
|
||||||
url: repoInfo.apiurl || mw.util.wikiScript( 'api' )
|
url: repoData.apiUrl || mw.util.wikiScript( 'api' )
|
||||||
}
|
}
|
||||||
} ).get( {
|
} ).get( {
|
||||||
action: 'query',
|
action: 'query',
|
||||||
list: 'users',
|
list: 'users',
|
||||||
ususers: username,
|
ususers: imageData.lastUploader,
|
||||||
usprop: 'gender'
|
usprop: 'gender'
|
||||||
} ).done( function ( data ) {
|
} ).done( function ( data ) {
|
||||||
var gender = data.query.users[0].gender;
|
var gender = 'unknown';
|
||||||
|
|
||||||
viewer.profileEnd( gfpid );
|
viewer.profileEnd( gfpid );
|
||||||
|
|
||||||
ui.setUserPageLink( repoInfo, username, gender );
|
if ( data && data.query && data.query.users &&
|
||||||
|
data.query.users[0] && data.query.users[0].gender ) {
|
||||||
|
gender = data.query.users[0].gender;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.setUserPageLink( repoData, imageData.lastUploader, gender );
|
||||||
} ).fail( function () {
|
} ).fail( function () {
|
||||||
mw.log( 'Gender fetch with ID ' + gfpid + ' failed, probably due to cross-domain API request.' );
|
mw.log( 'Gender fetch with ID ' + gfpid + ' failed, probably due to cross-domain API request.' );
|
||||||
ui.setUserPageLink( repoInfo, username, 'unknown' );
|
ui.setUserPageLink( repoData, imageData.lastUploader, 'unknown' );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
extmeta = innerInfo.extmetadata;
|
if ( imageData.creationDateTime ) {
|
||||||
|
ui.$datetime.text(
|
||||||
|
mw.message(
|
||||||
|
'multimediaviewer-datetime-created',
|
||||||
|
this.formatDate( imageData.creationDateTime )
|
||||||
|
).text()
|
||||||
|
);
|
||||||
|
} else if ( imageData.uploadDateTime ) {
|
||||||
|
ui.$datetime.text(
|
||||||
|
mw.message(
|
||||||
|
'multimediaviewer-datetime-uploaded',
|
||||||
|
this.formatDate( imageData.uploadDateTime )
|
||||||
|
).text()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ( extmeta ) {
|
ui.$datetimeLi.toggleClass( 'empty', !imageData.uploadDateTime && !imageData.creationDateTime );
|
||||||
desc = extmeta.ImageDescription;
|
|
||||||
|
|
||||||
ui.$imageDescDiv.toggleClass( 'empty', !desc );
|
if ( imageData.description ) {
|
||||||
|
whitelistHtml( ui.$imageDesc.empty().append( $.parseHTML( imageData.description ) ) );
|
||||||
if ( desc ) {
|
|
||||||
desc = desc.value;
|
|
||||||
whitelistHtml( ui.$imageDesc.append( $.parseHTML( desc ) ) );
|
|
||||||
} else {
|
} else {
|
||||||
ui.$imageDesc.append( mw.message( 'multimediaviewer-desc-nil' ).text() );
|
ui.$imageDesc.append( mw.message( 'multimediaviewer-desc-nil' ).text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
datetime = extmeta.DateTimeOriginal || extmeta.DateTime;
|
ui.$imageDescDiv.toggleClass( 'empty', !imageData.description );
|
||||||
|
|
||||||
if ( datetime ) {
|
if ( imageData.source ) {
|
||||||
// get rid of HTML tags
|
whitelistHtml( ui.$source.empty().append( $.parseHTML( imageData.source ) ) );
|
||||||
datetime = datetime.value.replace( /<.*?>/g, '' );
|
|
||||||
datetime = this.formatDate( datetime );
|
|
||||||
|
|
||||||
dtmsg = (
|
|
||||||
'multimediaviewer-datetime-' +
|
|
||||||
( extmeta.DateTimeOriginal ? 'created' : 'uploaded' )
|
|
||||||
);
|
|
||||||
|
|
||||||
ui.$datetime.text(
|
|
||||||
mw.message( dtmsg, datetime ).text()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.$datetimeLi.toggleClass( 'empty', !datetime );
|
if ( imageData.author ) {
|
||||||
|
whitelistHtml( ui.$author.empty().append( $.parseHTML( imageData.author ) ) );
|
||||||
source = extmeta.Credit;
|
|
||||||
author = extmeta.Artist;
|
|
||||||
|
|
||||||
if ( source ) {
|
|
||||||
source = source.value;
|
|
||||||
whitelistHtml( ui.$source.empty().append( $.parseHTML( source ) ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( author ) {
|
if ( imageData.source && imageData.author ) {
|
||||||
author = author.value;
|
|
||||||
whitelistHtml( ui.$author.empty().append( $.parseHTML( author ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( source && author ) {
|
|
||||||
ui.$credit.html(
|
ui.$credit.html(
|
||||||
mw.message(
|
mw.message(
|
||||||
'multimediaviewer-credit',
|
'multimediaviewer-credit',
|
||||||
|
@ -621,40 +609,30 @@
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// Clobber the contents and only have one of the fields
|
// Clobber the contents and only have one of the fields
|
||||||
if ( source ) {
|
if ( imageData.source ) {
|
||||||
ui.$credit.html( ui.$source );
|
ui.$credit.empty().append( ui.$source );
|
||||||
} else if ( author ) {
|
} else if ( imageData.author ) {
|
||||||
ui.$credit.html( ui.$author );
|
ui.$credit.empty().append( ui.$author );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.$credit.toggleClass( 'empty', !source && !author );
|
ui.$credit.toggleClass( 'empty', !imageData.source && !imageData.author );
|
||||||
|
|
||||||
license = extmeta.License;
|
msgname = 'multimediaviewer-license-' + ( imageData.license || '' );
|
||||||
}
|
|
||||||
|
|
||||||
if ( license ) {
|
if ( !imageData.license || !mw.messages.exists( msgname ) ) {
|
||||||
license = license.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
msgname = 'multimediaviewer-license-' + ( license || '' );
|
|
||||||
|
|
||||||
if ( !license || !mw.messages.exists( msgname ) ) {
|
|
||||||
// Cannot display, fallback or fail
|
// Cannot display, fallback or fail
|
||||||
license = 'default';
|
|
||||||
msgname = 'multimediaviewer-license-default';
|
msgname = 'multimediaviewer-license-default';
|
||||||
} else {
|
} else {
|
||||||
// License found, store the license data
|
// License found, store the license data
|
||||||
ui.$license.data( 'license', mw.message( msgname ).text() );
|
ui.$license.data( 'license', mw.message( msgname ).text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( license ) {
|
|
||||||
ui.$license
|
ui.$license
|
||||||
.text( mw.message( msgname ).text() )
|
.text( mw.message( msgname ).text() )
|
||||||
.toggleClass( 'cc-license', license.substr( 0, 2 ) === 'cc' );
|
.toggleClass( 'cc-license', imageData.isCcLicensed() );
|
||||||
}
|
|
||||||
|
|
||||||
ui.$license.toggleClass( 'empty', !license );
|
ui.$license.toggleClass( 'empty', !imageData.license );
|
||||||
};
|
};
|
||||||
|
|
||||||
MMVP.loadImage = function ( image, initialSrc ) {
|
MMVP.loadImage = function ( image, initialSrc ) {
|
||||||
|
@ -676,9 +654,9 @@
|
||||||
|
|
||||||
mdpid = this.profileStart( 'metadata-fetch' );
|
mdpid = this.profileStart( 'metadata-fetch' );
|
||||||
|
|
||||||
this.fetchImageInfo( image.filePageTitle ).done( function ( imageInfo, res, size ) {
|
this.fetchImageInfo( image.filePageTitle ).done( function ( imageData, repoInfo, size, requestedWidth ) {
|
||||||
var pid,
|
var pid,
|
||||||
innerInfo = imageInfo.imageinfo[0],
|
repoData = mw.mmv.model.Repo.newFromRepoInfo( repoInfo[imageData.repo] ),
|
||||||
imageEle = new Image(),
|
imageEle = new Image(),
|
||||||
targetWidth = size;
|
targetWidth = size;
|
||||||
|
|
||||||
|
@ -698,16 +676,16 @@
|
||||||
viewer.profileEnd( mdpid );
|
viewer.profileEnd( mdpid );
|
||||||
|
|
||||||
pid = viewer.profileStart( 'image-load', {
|
pid = viewer.profileStart( 'image-load', {
|
||||||
width: innerInfo.width,
|
width: imageData.width,
|
||||||
height: innerInfo.height,
|
height: imageData.height,
|
||||||
fileSize: innerInfo.size
|
fileSize: imageData.size
|
||||||
}, innerInfo.mime );
|
}, imageData.mimeType );
|
||||||
|
|
||||||
imageEle.src = imageInfo.imageinfo[0].thumburl || imageInfo.imageinfo[0].url;
|
imageEle.src = imageData.getThumbUrl( requestedWidth ) || imageData.url;
|
||||||
|
|
||||||
viewer.lightbox.iface.$imageDiv.removeClass( 'empty' );
|
viewer.lightbox.iface.$imageDiv.removeClass( 'empty' );
|
||||||
viewer.lightbox.iface.replaceImageWith( imageEle );
|
viewer.lightbox.iface.replaceImageWith( imageEle );
|
||||||
viewer.setImageInfo( image.filePageTitle, imageInfo );
|
viewer.setImageInfo( image.filePageTitle, imageData, repoData );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
comingFromPopstate = false;
|
comingFromPopstate = false;
|
||||||
|
@ -729,9 +707,13 @@
|
||||||
* @method
|
* @method
|
||||||
* Fetches image information from the API.
|
* Fetches image information from the API.
|
||||||
*
|
*
|
||||||
* Will resolve the promise with two objects (imageInfo and repoInfo) and the
|
* Will resolve the promise with two objects (imageData and repoData), the
|
||||||
* target width - basically the screen size - that the caller should resize
|
* target width - basically the screen size - that the caller should resize
|
||||||
* the image to eventually.
|
* the image to eventually, and the requested width - that is, what we asked
|
||||||
|
* for from the API - that should be used to fetch the thumbnail URL from
|
||||||
|
* the imageData object.
|
||||||
|
*
|
||||||
|
* The target
|
||||||
* @param {mw.Title} fileTitle Title of the file page for the image.
|
* @param {mw.Title} fileTitle Title of the file page for the image.
|
||||||
* @param {string[]} [props] List of properties to get from imageinfo
|
* @param {string[]} [props] List of properties to get from imageinfo
|
||||||
* @returns {jQuery.Promise}
|
* @returns {jQuery.Promise}
|
||||||
|
@ -753,7 +735,7 @@
|
||||||
requestedWidth = widths.requested;
|
requestedWidth = widths.requested;
|
||||||
|
|
||||||
function handleApiData( data ) {
|
function handleApiData( data ) {
|
||||||
var imageInfo;
|
var imageInfo, imageData;
|
||||||
|
|
||||||
if ( !data || !data.query ) {
|
if ( !data || !data.query ) {
|
||||||
// No information, oh well
|
// No information, oh well
|
||||||
|
@ -761,17 +743,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
viewer.cacheRepoInfo( data.query.repos );
|
viewer.cacheRepoInfo( data.query.repos );
|
||||||
imageInfo = viewer.getImageInfo( data.query.pages );
|
imageInfo = viewer.getFirst( data.query.pages );
|
||||||
|
|
||||||
if ( imageInfo ) {
|
if ( imageInfo ) {
|
||||||
if ( !imageInfo.imageinfo ||
|
imageData = mw.mmv.model.Image.newFromImageInfo( fileTitle, imageInfo );
|
||||||
imageInfo.imageinfo.length === 0 ) {
|
|
||||||
// No data, fail.
|
|
||||||
$.Deferred().reject();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Give back the information we have
|
// Give back the information we have
|
||||||
return $.Deferred().resolve( imageInfo, viewer.repoInfo, targetWidth );
|
return $.Deferred().resolve( imageData, viewer.repoInfo, targetWidth, requestedWidth );
|
||||||
} else {
|
} else {
|
||||||
return $.Deferred().reject();
|
return $.Deferred().reject();
|
||||||
}
|
}
|
||||||
|
@ -802,20 +780,25 @@
|
||||||
// Fetch the new thumb url but nothing else, because it's
|
// Fetch the new thumb url but nothing else, because it's
|
||||||
// the only non-cacheable thing
|
// the only non-cacheable thing
|
||||||
apiArgs.iiprop = 'url';
|
apiArgs.iiprop = 'url';
|
||||||
return this.imageInfo[filename].then( function ( cachedInfo ) {
|
return this.imageInfo[filename].then( function ( imageData, repoInfo ) {
|
||||||
return makeImageInfoRequest( apiArgs ).then( function ( imageInfo, repoInfo, targetWidth ) {
|
var maybeThumb = imageData.getThumbUrl( requestedWidth );
|
||||||
var innerInfo,
|
|
||||||
newInfo = $.extend( true, {}, cachedInfo );
|
// Thumbnail caching! Woo!
|
||||||
$.each( imageInfo.imageinfo, function ( i, item ) {
|
if ( maybeThumb ) {
|
||||||
innerInfo = item;
|
return $.Deferred().resolve( imageData, repoInfo, targetWidth, requestedWidth );
|
||||||
return false;
|
}
|
||||||
} );
|
|
||||||
$.each( newInfo.imageinfo, function ( i, item ) {
|
return viewer.api.get( apiArgs ).then( function ( data ) {
|
||||||
item.thumburl = innerInfo.thumburl;
|
var imageInfo, innerInfo;
|
||||||
item.thumbwidth = innerInfo.thumbwidth;
|
|
||||||
item.thumbheight = innerInfo.thumbheight;
|
imageInfo = viewer.getFirst( data.query.pages );
|
||||||
} );
|
innerInfo = viewer.getFirst( imageInfo.imageinfo );
|
||||||
return $.Deferred().resolve( newInfo, repoInfo, targetWidth );
|
|
||||||
|
if ( innerInfo.thumburl ) {
|
||||||
|
imageData.addThumbUrl( innerInfo.thumbwidth, innerInfo.thumburl );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $.Deferred().resolve( imageData, repoInfo, targetWidth, requestedWidth );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -524,54 +524,43 @@
|
||||||
/**
|
/**
|
||||||
* @method
|
* @method
|
||||||
* Sets the URL for the File: page of the image
|
* Sets the URL for the File: page of the image
|
||||||
* @param {Object} repoInfo
|
* @param {string} url
|
||||||
* @param {mw.Title} fileTitle
|
|
||||||
*/
|
*/
|
||||||
LIP.setFilePageLink = function ( repoInfo, fileTitle ) {
|
LIP.setFilePageLink = function ( url ) {
|
||||||
var linkpath;
|
this.$repo.prop( 'href', url );
|
||||||
|
this.$license.prop( 'href', url );
|
||||||
|
};
|
||||||
|
|
||||||
if ( repoInfo.descBaseUrl ) {
|
/**
|
||||||
linkpath = repoInfo.descBaseUrl + fileTitle.getMainText();
|
* @method
|
||||||
} else {
|
* Saves some data about the image on the $useFile element for later setup.
|
||||||
if ( repoInfo.server && repoInfo.articlepath ) {
|
* @param {mw.Title} title
|
||||||
linkpath = repoInfo.server + repoInfo.articlepath;
|
* @param {string} src The URL for the full-size image
|
||||||
} else {
|
* @param {boolean} isLocal Whether the file is on this wiki or not
|
||||||
linkpath = mw.config.get( 'wgArticlePath' );
|
*/
|
||||||
}
|
LIP.initUseFileData = function ( title, src, isLocal ) {
|
||||||
linkpath = linkpath.replace( '$1', fileTitle.getPrefixedText() );
|
this.$useFile.data( 'title', title );
|
||||||
}
|
this.$useFile.data( 'src', src );
|
||||||
|
this.$useFile.data( 'isLocal', isLocal );
|
||||||
if ( repoInfo.local ) {
|
|
||||||
this.$useFile.data( 'isLocal', repoInfo.local );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !/^(https?:)?\/\//.test( linkpath ) ) {
|
|
||||||
this.$useFile.data( 'link', mw.config.get( 'wgServer' ) + linkpath );
|
|
||||||
} else {
|
|
||||||
this.$useFile.data( 'link', linkpath );
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$repo.prop( 'href', linkpath );
|
|
||||||
this.$license.prop( 'href', linkpath );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method
|
* @method
|
||||||
* Sets the link to the user page where possible
|
* Sets the link to the user page where possible
|
||||||
* @param {Object} repoInfo
|
* @param {mw.mmv.model.Repo} repoData
|
||||||
* @param {string} username
|
* @param {string} username
|
||||||
* @param {string} gender
|
* @param {string} gender
|
||||||
*/
|
*/
|
||||||
LIP.setUserPageLink = function ( repoInfo, username, gender ) {
|
LIP.setUserPageLink = function ( repoData, username, gender ) {
|
||||||
var userlink,
|
var userlink,
|
||||||
userpage = 'User:' + username;
|
userpage = 'User:' + username;
|
||||||
|
|
||||||
if ( repoInfo.descBaseUrl ) {
|
if ( repoData instanceof mw.mmv.model.ForeignDbRepo ) {
|
||||||
// We basically can't do anything about this; fail
|
// We basically can't do anything about this; fail
|
||||||
this.$username.addClass( 'empty' );
|
this.$username.addClass( 'empty' );
|
||||||
} else {
|
} else {
|
||||||
if ( repoInfo.server && repoInfo.articlepath ) {
|
if ( repoData.absoluteArticlePath ) {
|
||||||
userlink = repoInfo.server + repoInfo.articlepath;
|
userlink = repoData.absoluteArticlePath;
|
||||||
} else {
|
} else {
|
||||||
userlink = mw.config.get( 'wgArticlePath' );
|
userlink = mw.config.get( 'wgArticlePath' );
|
||||||
}
|
}
|
||||||
|
|
22
resources/ext.multimediaViewer/mmv.js
Normal file
22
resources/ext.multimediaViewer/mmv.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
||||||
|
*
|
||||||
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This will just set up various objects for the main
|
||||||
|
// MultimediaViewer load.
|
||||||
|
( function ( mw ) {
|
||||||
|
mw.mmv = {};
|
||||||
|
}( mediaWiki ) );
|
60
tests/qunit/ext.multimediaViewer.dataModel.test.js
Normal file
60
tests/qunit/ext.multimediaViewer.dataModel.test.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
||||||
|
*
|
||||||
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
( function ( mw ) {
|
||||||
|
QUnit.module( 'ext.multimediaViewer.dataModel', QUnit.newMwEnvironment() );
|
||||||
|
|
||||||
|
QUnit.test( 'Image model constructor sanity check', 16, function ( assert ) {
|
||||||
|
var
|
||||||
|
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||||
|
size = 100,
|
||||||
|
width = 10,
|
||||||
|
height = 15,
|
||||||
|
mime = 'image/jpeg',
|
||||||
|
url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
||||||
|
descurl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
|
||||||
|
repo = 'wikimediacommons',
|
||||||
|
user = 'Kaldari',
|
||||||
|
datetime = '2011-07-04T23:31:14Z',
|
||||||
|
origdatetime = '2010-07-04T23:31:14Z',
|
||||||
|
description = 'This is a test file.',
|
||||||
|
source = 'WMF',
|
||||||
|
author = 'Ryan Kaldari',
|
||||||
|
license = 'cc0',
|
||||||
|
imageData = new mw.mmv.model.Image(
|
||||||
|
title, size, width, height, mime, url,
|
||||||
|
descurl, repo, user, datetime, origdatetime,
|
||||||
|
description, source, author, license );
|
||||||
|
|
||||||
|
assert.strictEqual( imageData.title, title, 'Title is set correctly' );
|
||||||
|
assert.strictEqual( imageData.size, size, 'Size is set correctly' );
|
||||||
|
assert.strictEqual( imageData.width, width, 'Width is set correctly' );
|
||||||
|
assert.strictEqual( imageData.height, height, 'Height is set correctly' );
|
||||||
|
assert.strictEqual( imageData.mimeType, mime, 'MIME type is set correctly' );
|
||||||
|
assert.strictEqual( imageData.url, url, 'URL for original image is set correctly' );
|
||||||
|
assert.strictEqual( imageData.descriptionUrl, descurl, 'URL for image description page is set correctly' );
|
||||||
|
assert.strictEqual( imageData.repo, repo, 'Repository name is set correctly' );
|
||||||
|
assert.strictEqual( imageData.lastUploader, user, 'Name of last uploader is set correctly' );
|
||||||
|
assert.strictEqual( imageData.uploadDateTime, datetime, 'Date and time of last upload is set correctly' );
|
||||||
|
assert.strictEqual( imageData.creationDateTime, origdatetime, 'Date and time of original upload is set correctly' );
|
||||||
|
assert.strictEqual( imageData.description, description, 'Description is set correctly' );
|
||||||
|
assert.strictEqual( imageData.source, source, 'Source is set correctly' );
|
||||||
|
assert.strictEqual( imageData.author, author, 'Author is set correctly' );
|
||||||
|
assert.strictEqual( imageData.license, license, 'License is set correctly' );
|
||||||
|
assert.ok( imageData.thumbUrls, 'Thumb URL cache is set up properly' );
|
||||||
|
} );
|
||||||
|
}( mediaWiki ) );
|
|
@ -123,21 +123,8 @@
|
||||||
assert.strictEqual( handlerCalls, 1, 'The handler was not called after calling lightbox.clearEvents().' );
|
assert.strictEqual( handlerCalls, 1, 'The handler was not called after calling lightbox.clearEvents().' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'Setting repository information in the UI works as expected', 5, function ( assert ) {
|
QUnit.test( 'Setting repository information in the UI works as expected', 3, function ( assert ) {
|
||||||
var lightbox = new mw.LightboxInterface(),
|
var lightbox = new mw.LightboxInterface();
|
||||||
|
|
||||||
localRepoInfo = {
|
|
||||||
local: true
|
|
||||||
},
|
|
||||||
|
|
||||||
remoteDBRepoInfo = {
|
|
||||||
descBaseUrl: 'http://example.com/wiki/File:'
|
|
||||||
},
|
|
||||||
|
|
||||||
remoteAPIRepoInfo = {
|
|
||||||
server: 'http://commons.example.org',
|
|
||||||
articlepath: '/wiki/$1'
|
|
||||||
};
|
|
||||||
|
|
||||||
lightbox.setRepoDisplayName( 'Example Wiki' );
|
lightbox.setRepoDisplayName( 'Example Wiki' );
|
||||||
assert.strictEqual( lightbox.$repo.text(), 'Learn more on Example Wiki', 'Text set to something useful for remote wiki - if this fails it might be because of localisation' );
|
assert.strictEqual( lightbox.$repo.text(), 'Learn more on Example Wiki', 'Text set to something useful for remote wiki - if this fails it might be because of localisation' );
|
||||||
|
@ -145,13 +132,7 @@
|
||||||
lightbox.setRepoDisplayName();
|
lightbox.setRepoDisplayName();
|
||||||
assert.strictEqual( lightbox.$repo.text(), 'Learn more on ' + mw.config.get( 'wgSiteName' ), 'Text set to something useful for local wiki - if this fails it might be because of localisation' );
|
assert.strictEqual( lightbox.$repo.text(), 'Learn more on ' + mw.config.get( 'wgSiteName' ), 'Text set to something useful for local wiki - if this fails it might be because of localisation' );
|
||||||
|
|
||||||
lightbox.setFilePageLink( localRepoInfo, mw.Title.newFromText( 'File:Foobar.jpg' ) );
|
lightbox.setFilePageLink( 'https://commons.wikimedia.org/wiki/File:Foobar.jpg' );
|
||||||
assert.strictEqual( lightbox.$repo.prop( 'href' ), mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' ).replace( '$1', 'File:Foobar.jpg' ), 'The file link was set to a local page successfully.' );
|
assert.strictEqual( lightbox.$repo.prop( 'href' ), 'https://commons.wikimedia.org/wiki/File:Foobar.jpg', 'The file link was set successfully.' );
|
||||||
|
|
||||||
lightbox.setFilePageLink( remoteDBRepoInfo, mw.Title.newFromText( 'File:Foobar.jpg' ) );
|
|
||||||
assert.strictEqual( lightbox.$repo.prop( 'href' ), 'http://example.com/wiki/File:Foobar.jpg', 'The file link was set to a remote shared DB page successfully.' );
|
|
||||||
|
|
||||||
lightbox.setFilePageLink( remoteAPIRepoInfo, mw.Title.newFromText( 'File:Foobar.jpg' ) );
|
|
||||||
assert.strictEqual( lightbox.$repo.prop( 'href' ), 'http://commons.example.org/wiki/File:Foobar.jpg', 'The file link was set to a remote API page successfully.' );
|
|
||||||
} );
|
} );
|
||||||
}( mediaWiki, jQuery ) );
|
}( mediaWiki, jQuery ) );
|
||||||
|
|
Loading…
Reference in a new issue