2014-01-10 21:11:21 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2014-01-13 21:40:22 +00:00
|
|
|
* @param {number} latitude
|
|
|
|
* @param {number} longitude
|
2014-01-10 21:11:21 +00:00
|
|
|
*/
|
|
|
|
function Image(
|
|
|
|
title,
|
|
|
|
size,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
mimeType,
|
|
|
|
url,
|
|
|
|
descriptionUrl,
|
|
|
|
repo,
|
|
|
|
lastUploader,
|
|
|
|
uploadDateTime,
|
|
|
|
creationDateTime,
|
|
|
|
description,
|
|
|
|
source,
|
|
|
|
author,
|
2014-01-13 21:40:22 +00:00
|
|
|
license,
|
|
|
|
latitude,
|
|
|
|
longitude
|
2014-01-10 21:11:21 +00:00
|
|
|
) {
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {mw.Title} title The title of the image file */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.title = title;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {number} size The filesize, in bytes, of the original image */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.size = size;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {number} width The width, in pixels, of the original image */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.width = width;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {number} height The height, in pixels, of the original image */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.height = height;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} mimeType The MIME type of the original image */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.mimeType = mimeType;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} url The URL to the original image */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.url = url;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} descriptionUrl The URL to the description page for the image */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.descriptionUrl = descriptionUrl;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} repo The name of the repository where this image is stored */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.repo = repo;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} lastUploader The person who uploaded the last version of the file */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.lastUploader = lastUploader;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} uploadDateTime The date and time of the last upload */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.uploadDateTime = uploadDateTime;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} creationDateTime The date and time that the image was created */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.creationDateTime = creationDateTime;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} description The description from the file page - unsafe HTML sometimes goes here */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.description = description;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} source The source for the image (could be an organization, e.g.) - unsafe HTML sometimes goes here */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.source = source;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} author The author of the image - unsafe HTML sometimes goes here */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.author = author;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} license The license under which the image is distributed */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.license = license;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {number} latitude The latitude of the place where the image was created */
|
2014-01-13 21:40:22 +00:00
|
|
|
this.latitude = latitude;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {number} longitude The longitude of the place where the image was created */
|
2014-01-13 21:40:22 +00:00
|
|
|
this.longitude = longitude;
|
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
/**
|
2014-01-11 00:05:03 +00:00
|
|
|
* @property {Object} thumbUrls
|
2014-01-10 21:11:21 +00:00
|
|
|
* 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
|
2014-01-11 00:05:03 +00:00
|
|
|
* @param {Object} imageInfo
|
2014-01-10 21:11:21 +00:00
|
|
|
* @returns {mw.mmv.model.Image}
|
|
|
|
*/
|
|
|
|
Image.newFromImageInfo = function ( title, imageInfo ) {
|
|
|
|
var uploadDateTime, creationDateTime, imageData,
|
|
|
|
description, source, author, license,
|
2014-01-13 21:40:22 +00:00
|
|
|
latitude, longitude,
|
2014-01-10 21:11:21 +00:00
|
|
|
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;
|
2014-01-13 21:40:22 +00:00
|
|
|
|
|
|
|
latitude = extmeta.GPSLatitude && parseFloat( extmeta.GPSLatitude.value );
|
|
|
|
longitude = extmeta.GPSLongitude && parseFloat( extmeta.GPSLongitude.value );
|
2014-01-10 21:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2014-01-13 21:40:22 +00:00
|
|
|
license,
|
|
|
|
latitude,
|
|
|
|
longitude
|
2014-01-10 21:11:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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';
|
|
|
|
};
|
|
|
|
|
2014-01-13 21:40:22 +00:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* Check whether the image has geolocation data.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
Image.prototype.hasCoords = function () {
|
|
|
|
return this.hasOwnProperty( 'latitude' ) && this.hasOwnProperty( 'longitude' ) &&
|
|
|
|
this.latitude !== undefined && this.latitude !== null &&
|
|
|
|
this.longitude !== undefined && this.longitude !== null;
|
|
|
|
};
|
|
|
|
|
2014-01-10 21:11:21 +00:00
|
|
|
/**
|
|
|
|
* @class mw.mmv.model.Repo
|
|
|
|
* Represents information about a single image repository
|
|
|
|
* @constructor
|
|
|
|
* @param {string} displayName
|
2014-01-15 16:18:33 +00:00
|
|
|
* @param {string} favIcon URL to the repo's favicon
|
2014-01-10 21:11:21 +00:00
|
|
|
* @param {boolean} isLocal
|
|
|
|
*/
|
|
|
|
function Repo(
|
|
|
|
displayName,
|
2014-01-15 16:18:33 +00:00
|
|
|
favIcon,
|
2014-01-10 21:11:21 +00:00
|
|
|
isLocal
|
|
|
|
) {
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} displayName Human-readable name of the repository */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.displayName = displayName;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} favIcon An icon that represents the repository */
|
2014-01-15 16:18:33 +00:00
|
|
|
this.favIcon = favIcon;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {boolean} isLocal Whether the repository is the local wiki */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.isLocal = isLocal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* @static
|
|
|
|
* Creates a new object from repoInfo we found in an API response.
|
2014-01-11 00:05:03 +00:00
|
|
|
* @param {Object} repoInfo
|
2014-01-10 21:11:21 +00:00
|
|
|
* @returns {mw.mmv.model.Repo}
|
|
|
|
*/
|
|
|
|
Repo.newFromRepoInfo = function ( repoInfo ) {
|
|
|
|
if ( repoInfo.apiurl ) {
|
|
|
|
return new ForeignApiRepo(
|
|
|
|
repoInfo.displayname,
|
2014-01-15 16:18:33 +00:00
|
|
|
repoInfo.favicon,
|
2014-01-10 21:11:21 +00:00
|
|
|
false,
|
|
|
|
repoInfo.apiurl,
|
|
|
|
repoInfo.server,
|
|
|
|
repoInfo.articlepath
|
|
|
|
);
|
|
|
|
} else if ( repoInfo.descBaseUrl ) {
|
|
|
|
return new ForeignDbRepo(
|
|
|
|
repoInfo.displayname,
|
2014-01-15 16:18:33 +00:00
|
|
|
repoInfo.favicon,
|
2014-01-10 21:11:21 +00:00
|
|
|
false,
|
|
|
|
repoInfo.descBaseUrl
|
|
|
|
);
|
|
|
|
} else {
|
2014-01-15 16:18:33 +00:00
|
|
|
return new Repo( repoInfo.displayname, repoInfo.favicon, repoInfo.local );
|
2014-01-10 21:11:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class mw.mmv.model.ForeignApiRepo
|
|
|
|
* Represents information about a foreign API repository
|
2014-01-11 00:05:03 +00:00
|
|
|
* @extends mw.mmv.model.Repo
|
2014-01-10 21:11:21 +00:00
|
|
|
* @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,
|
2014-01-15 16:18:33 +00:00
|
|
|
favIcon,
|
2014-01-10 21:11:21 +00:00
|
|
|
isLocal,
|
|
|
|
apiUrl,
|
|
|
|
server,
|
|
|
|
articlePath
|
|
|
|
) {
|
2014-01-15 16:18:33 +00:00
|
|
|
Repo.call( this, displayName, favIcon, isLocal );
|
2014-01-10 21:11:21 +00:00
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} apiUrl URL to the wiki's api.php */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.apiUrl = apiUrl;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} server Hostname for the wiki */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.server = server;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} articlePath Path to articles on the wiki, relative to the hostname */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.articlePath = articlePath;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} absoluteArticlePath Path to articles on the wiki, relative to nothing */
|
2014-01-10 21:11:21 +00:00
|
|
|
this.absoluteArticlePath = server + articlePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
oo.inheritClass( ForeignApiRepo, Repo );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class mw.mmv.model.ForeignDbRepo
|
|
|
|
* Represents information about a foreign, shared DB repository
|
2014-01-11 00:05:03 +00:00
|
|
|
* @extends mw.mmv.model.Repo
|
2014-01-10 21:11:21 +00:00
|
|
|
* @constructor
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
function ForeignDbRepo(
|
|
|
|
displayName,
|
2014-01-15 16:18:33 +00:00
|
|
|
favIcon,
|
2014-01-10 21:11:21 +00:00
|
|
|
isLocal,
|
|
|
|
descBaseUrl
|
|
|
|
) {
|
2014-01-15 16:18:33 +00:00
|
|
|
Repo.call( this, displayName, favIcon, isLocal );
|
2014-01-10 21:11:21 +00:00
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} descBaseUrl Base URL for descriptions on the wiki - append a file's title to this to get the description page */
|
2014-01-10 21:11:21 +00:00
|
|
|
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 ) );
|