MarkTraceur has uploaded a new change for review.
https://gerrit.wikimedia.org/r/106846
Change subject: Refactor to a data model
......................................................................
Refactor to a data model
Image information and repo information are now both stored somewhere
else entirely, so we don't need to keep accessing weird API return
values to sort things out. fetchImageInfo now uses those classes to
an extent, and we now cache thumbnail URLs for different sizes.
Change-Id: Ife8293c86683ea914b1a5a60000584b501d92e55
---
M MultimediaViewer.php
A resources/ext.multimediaViewer/ext.multimediaViewer.dataModel.js
M resources/ext.multimediaViewer/ext.multimediaViewer.js
M resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
A resources/ext.multimediaViewer/mmv.js
5 files changed, 481 insertions(+), 192 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer
refs/changes/46/106846/1
diff --git a/MultimediaViewer.php b/MultimediaViewer.php
index 6df2b66..a7f6a08 100644
--- a/MultimediaViewer.php
+++ b/MultimediaViewer.php
@@ -86,6 +86,23 @@
),
), $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(
'scripts' => array(
'ext.multimediaViewer.js',
@@ -102,6 +119,7 @@
'mediawiki.Title',
'jquery.ui.dialog',
'jquery.hidpi',
+ 'ext.multimediaViewer.dataModel',
),
'messages' => array(
diff --git a/resources/ext.multimediaViewer/ext.multimediaViewer.dataModel.js
b/resources/ext.multimediaViewer/ext.multimediaViewer.dataModel.js
new file mode 100644
index 0000000..2f7599b
--- /dev/null
+++ b/resources/ext.multimediaViewer/ext.multimediaViewer.dataModel.js
@@ -0,0 +1,293 @@
+/*
+ * 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.ImageData
+ * 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 ImageData(
+ title,
+ size,
+ width,
+ height,
+ mimeType,
+ url,
+ descriptionUrl,
+ repo,
+ lastUploader,
+ lastUploadDateTime,
+ originalUploadDateTime,
+ 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} lastUploadDateTime */
+ this.lastUploadDateTime = lastUploadDateTime;
+
+ /** @property {string} originalUploadDateTime */
+ this.originalUploadDateTime = originalUploadDateTime;
+
+ /** @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 ImageData object out of an object containing
+ * imageinfo data from an API response.
+ * @param {mw.Title} title
+ * @param {object} imageInfo
+ * @returns {mw.mmv.ImageData}
+ */
+ ImageData.newFromImageInfo = function ( title, imageInfo ) {
+ var lastUploadDateTime, originalUploadDateTime, imageData,
+ description, source, author, license,
+ innerInfo = imageInfo.imageinfo[0],
+ extmeta = innerInfo.extmetadata;
+
+ if ( extmeta ) {
+ originalUploadDateTime = extmeta.DateTimeOriginal;
+ lastUploadDateTime = extmeta.DateTimeOriginal ||
extmeta.DateTime;
+
+ if ( lastUploadDateTime ) {
+ lastUploadDateTime =
lastUploadDateTime.value.replace( /<.*?>/g, '' );
+ }
+
+ if ( originalUploadDateTime ) {
+ originalUploadDateTime =
originalUploadDateTime.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 ImageData(
+ title,
+ innerInfo.size,
+ innerInfo.width,
+ innerInfo.height,
+ innerInfo.mime,
+ innerInfo.url,
+ innerInfo.descriptionurl,
+ imageInfo.imagerepository,
+ innerInfo.user,
+ lastUploadDateTime,
+ originalUploadDateTime,
+ 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
+ */
+ ImageData.prototype.addThumbUrl = function ( width, url ) {
+ this.thumbUrls[width] = url;
+ };
+
+ /**
+ * @method
+ * Get a thumb URL if we have it.
+ * @param {number} width
+ * @returns {string|undefined}
+ */
+ ImageData.prototype.getThumbUrl = function ( width ) {
+ return this.thumbUrls[width];
+ };
+
+ /**
+ * @class mw.mmv.RepoData
+ * Represents information about a single image repository
+ * @constructor
+ * @param {string} displayName
+ * @param {boolean} isLocal
+ */
+ function RepoData(
+ 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.RepoData}
+ */
+ RepoData.newFromRepoInfo = function ( repoInfo ) {
+ if ( repoInfo.apiurl ) {
+ return new ForeignApiRepoData(
+ repoInfo.displayname,
+ false,
+ repoInfo.apiurl,
+ repoInfo.server,
+ repoInfo.articlepath
+ );
+ } else if ( repoInfo.descBaseUrl ) {
+ return new ForeignDbRepoData(
+ repoInfo.displayname,
+ false,
+ repoInfo.descBaseUrl
+ );
+ } else {
+ return new RepoData( repoInfo.displayname,
repoInfo.local );
+ }
+ };
+
+ /**
+ * @class
+ * Represents information about a foreign API repository
+ * @extends RepoData
+ * @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 ForeignApiRepoData(
+ displayName,
+ isLocal,
+ apiUrl,
+ server,
+ articlePath
+ ) {
+ RepoData.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( ForeignApiRepoData, RepoData );
+
+ /**
+ * @class
+ * Represents information about a foreign, shared DB repository
+ * @extends RepoData
+ * @constructor
+ * @inheritdoc
+ */
+ function ForeignDbRepoData(
+ displayName,
+ isLocal,
+ descBaseUrl
+ ) {
+ RepoData.call( this, displayName, isLocal );
+
+ /** @property {string} descBaseUrl */
+ this.descBaseUrl = descBaseUrl;
+ }
+
+ oo.inheritClass( ForeignDbRepoData, RepoData );
+
+ mw.mmv.ImageData = ImageData;
+ mw.mmv.RepoData = RepoData;
+ mw.mmv.ForeignApiRepoData = ForeignApiRepoData;
+ mw.mmv.ForeignDbRepoData = ForeignDbRepoData;
+}( mediaWiki, OO ) );
diff --git a/resources/ext.multimediaViewer/ext.multimediaViewer.js
b/resources/ext.multimediaViewer/ext.multimediaViewer.js
index 09ff6d1..8a64f15 100755
--- a/resources/ext.multimediaViewer/ext.multimediaViewer.js
+++ b/resources/ext.multimediaViewer/ext.multimediaViewer.js
@@ -115,8 +115,11 @@
this.api = new mw.Api();
/**
- * imageInfo object. TODO: Describe structure and valid states.
- * @property {Object}
+ * imageInfo object, used for caching - promises will resolve
with
+ * an mw.mmv.ImageData 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
*/
this.imageInfo = {};
@@ -317,8 +320,8 @@
var viewer = this,
fileTitle = this.currentImageFileTitle;
- this.fetchImageInfo( fileTitle, [ 'url' ] ).done( function (
imageInfo, repoInfo, targetWidth ) {
- viewer.loadResizedImage( ui, imageInfo, targetWidth );
+ this.fetchImageInfo( fileTitle, [ 'url' ] ).done( function (
imageData, repoInfo, targetWidth ) {
+ viewer.loadResizedImage( ui, imageData, targetWidth );
} );
};
@@ -328,31 +331,30 @@
* @protected
*
* @param {LightboxInterface} ui lightbox that got resized
- * @param {Object} imageInfo information regarding the new resized image
+ * @param {mw.mmv.ImageData} imageData information regarding the new
resized image
* @param {number} targetWidth
*/
- MMVP.loadResizedImage = function ( ui, imageInfo, targetWidth ) {
- var innerInfo, rpid, viewer, image;
+ MMVP.loadResizedImage = function ( ui, imageData, targetWidth,
requestedWidth ) {
+ var rpid, viewer, image, maybeThumb;
// Replace image only if data was returned.
- if ( imageInfo ) {
+ if ( imageData ) {
viewer = this;
image = new Image();
-
- innerInfo = imageInfo.imageinfo[0];
image.onload = function () {
viewer.profileEnd( rpid );
};
rpid = this.profileStart( 'image-resize', {
- width: innerInfo.width,
- height: innerInfo.height,
- fileSize: innerInfo.size
- }, innerInfo.mime );
+ width: imageData.width,
+ height: imageData.height,
+ fileSize: imageData.size
+ }, imageData.mimeType );
- image.src = innerInfo.thumburl || innerInfo.url;
- if ( innerInfo.thumbwidth > targetWidth ) {
+ maybeThumb = imageData.getThumbUrl( requestedWidth );
+ image.src = maybeThumb || imageData.url;
+ if ( maybeThumb && requestedWidth > targetWidth ||
!maybeThumb && imageData.width > targetWidth ) {
image.width = targetWidth;
}
ui.replaceImageWith( image );
@@ -463,24 +465,24 @@
};
/**
- * Get image information out of an API response.
- * @param {Object[]} images The query.pages member of the API response.
- * @returns {Object} Representing image information.
+ * Get first (hopefully only) member of an object.
+ * @param {Array|Object} things
+ * @returns {Mixed}
*/
- MMVP.getImageInfo = function ( images ) {
- var imageInfo;
+ MMVP.getFirst = function ( things ) {
+ var thing;
- if ( images ) {
- $.each( images, function ( i, page ) {
- imageInfo = page;
+ if ( things ) {
+ $.each( things, function ( i, thisone ) {
+ thing = thisone;
return false;
} );
}
- return imageInfo;
+ return thing;
};
- MMVP.setImageInfo = function ( fileTitle, imageInfo ) {
+ MMVP.setImageInfo = function ( fileTitle, imageData, repoData ) {
function whitelistHtml( $el ) {
var child, $prev, $child = $el.children().first();
@@ -508,37 +510,23 @@
}
}
- var extmeta, gfpid,
- repoInfo,
- desc,
- datetime, dtmsg,
- license, msgname,
- username,
- source, author,
+ var gfpid,
+ dtmsg,
+ msgname,
viewer = this,
- ui = this.lightbox.iface,
- innerInfo = imageInfo.imageinfo[0] || {};
+ ui = this.lightbox.iface;
ui.$title.text( fileTitle.getNameText() );
- ui.$useFile.data( 'title', fileTitle );
- ui.$useFile.data( 'src', innerInfo.url );
+ ui.initUseFileData( fileTitle, imageData.url, repoData.isLocal
);
ui.$useFileLi.removeClass( 'empty' );
- if ( this.repoInfo ) {
- repoInfo = this.repoInfo[imageInfo.imagerepository];
- }
+ ui.setRepoDisplayName( repoData.displayname, repoData.isLocal );
+ ui.setFilePageLink( imageData.descriptionUrl );
- if ( repoInfo ) {
- ui.setRepoDisplayName( repoInfo.displayname,
repoInfo.local );
- ui.setFilePageLink( repoInfo, fileTitle );
- }
+ ui.$repoLi.removeClass( 'empty' );
- ui.$repoLi.toggleClass( 'empty', !repoInfo );
-
- username = innerInfo.user;
-
- if ( username ) {
+ if ( imageData.lastUploader ) {
gfpid = this.profileStart( 'gender-fetch' );
// TODO: Reuse the api member, fix everywhere.
@@ -546,115 +534,93 @@
// TODO this is ugly as hell, let's fix this in core.
new mw.Api( {
ajax: {
- url: repoInfo.apiurl ||
mw.util.wikiScript( 'api' )
+ url: repoData.apiUrl ||
mw.util.wikiScript( 'api' )
}
} ).get( {
action: 'query',
list: 'users',
- ususers: username,
+ ususers: imageData.lastUploader,
usprop: 'gender'
} ).done( function ( data ) {
- var gender = data.query.users[0].gender;
+ var gender = 'unknown';
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 () {
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.lastUploadDateTime ) {
+ dtmsg = (
+ 'multimediaviewer-datetime-' +
+ ( imageData.originalUploadDateTime ===
imageData.lastUploadDateTime ? 'created' : 'uploaded' )
+ );
- if ( extmeta ) {
- desc = extmeta.ImageDescription;
-
- ui.$imageDescDiv.toggleClass( 'empty', !desc );
-
- if ( desc ) {
- desc = desc.value;
- whitelistHtml( ui.$imageDesc.append(
$.parseHTML( desc ) ) );
- } else {
- ui.$imageDesc.append( mw.message(
'multimediaviewer-desc-nil' ).text() );
- }
-
- datetime = extmeta.DateTimeOriginal || extmeta.DateTime;
-
- if ( datetime ) {
- // get rid of HTML tags
- 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 );
-
- source = extmeta.Credit;
- author = extmeta.Artist;
-
- if ( source ) {
- source = source.value;
- whitelistHtml( ui.$source.empty().append(
$.parseHTML( source ) ) );
- }
-
- if ( author ) {
- author = author.value;
- whitelistHtml( ui.$author.empty().append(
$.parseHTML( author ) ) );
- }
-
- if ( source && author ) {
- ui.$credit.html(
- mw.message(
- 'multimediaviewer-credit',
- ui.$author.get( 0 ).outerHTML,
- ui.$source.get( 0 ).outerHTML
- ).plain()
- );
- } else {
- // Clobber the contents and only have one of
the fields
- if ( source ) {
- ui.$credit.html( ui.$source );
- } else if ( author ) {
- ui.$credit.html( ui.$author );
- }
- }
-
- ui.$credit.toggleClass( 'empty', !source && !author );
-
- license = extmeta.License;
+ ui.$datetime.text(
+ mw.message( dtmsg, this.formatDate(
imageData.lastUploadDateTime ) ).text()
+ );
}
- if ( license ) {
- license = license.value;
+ ui.$datetimeLi.toggleClass( 'empty',
!imageData.lastUploadDateTime );
+
+ if ( imageData.description ) {
+ whitelistHtml( ui.$imageDesc.empty().append(
$.parseHTML( imageData.description ) ) );
+ } else {
+ ui.$imageDesc.append( mw.message(
'multimediaviewer-desc-nil' ).text() );
}
- msgname = 'multimediaviewer-license-' + ( license || '' );
+ ui.$imageDescDiv.toggleClass( 'empty', !imageData.description );
- if ( !license || !mw.messages.exists( msgname ) ) {
+ if ( imageData.source ) {
+ whitelistHtml( ui.$source.empty().append( $.parseHTML(
imageData.source ) ) );
+ }
+
+ if ( imageData.author ) {
+ whitelistHtml( ui.$author.empty().append( $.parseHTML(
imageData.author ) ) );
+ }
+
+ if ( imageData.source && imageData.author ) {
+ ui.$credit.html(
+ mw.message(
+ 'multimediaviewer-credit',
+ ui.$author.get( 0 ).outerHTML,
+ ui.$source.get( 0 ).outerHTML
+ ).plain()
+ );
+ } else {
+ // Clobber the contents and only have one of the fields
+ if ( imageData.source ) {
+ ui.$credit.empty().append( ui.$source );
+ } else if ( imageData.author ) {
+ ui.$credit.empty().append( ui.$author );
+ }
+ }
+
+ ui.$credit.toggleClass( 'empty', !imageData.source &&
!imageData.author );
+
+ msgname = 'multimediaviewer-license-' + ( imageData.license ||
'' );
+
+ if ( !imageData.license || !mw.messages.exists( msgname ) ) {
// Cannot display, fallback or fail
- license = 'default';
msgname = 'multimediaviewer-license-default';
} else {
// License found, store the license data
ui.$license.data( 'license', mw.message( msgname
).text() );
}
- if ( license ) {
- ui.$license
- .text( mw.message( msgname ).text() )
- .toggleClass( 'cc-license', license.substr( 0,
2 ) === 'cc' );
- }
+ ui.$license
+ .text( mw.message( msgname ).text() )
+ .toggleClass( 'cc-license', ( imageData.license || ''
).substr( 0, 2 ) === 'cc' );
- ui.$license.toggleClass( 'empty', !license );
+ ui.$license.toggleClass( 'empty', !imageData.license );
};
MMVP.loadImage = function ( image, initialSrc ) {
@@ -676,9 +642,9 @@
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,
- innerInfo = imageInfo.imageinfo[0],
+ repoData = mw.mmv.RepoData.newFromRepoInfo(
repoInfo[imageData.repo] ),
imageEle = new Image(),
targetWidth = size;
@@ -698,16 +664,16 @@
viewer.profileEnd( mdpid );
pid = viewer.profileStart( 'image-load', {
- width: innerInfo.width,
- height: innerInfo.height,
- fileSize: innerInfo.size
- }, innerInfo.mime );
+ width: imageData.width,
+ height: imageData.height,
+ fileSize: imageData.size
+ }, 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.replaceImageWith( imageEle );
- viewer.setImageInfo( image.filePageTitle, imageInfo );
+ viewer.setImageInfo( image.filePageTitle, imageData,
repoData );
} );
comingFromPopstate = false;
@@ -753,7 +719,7 @@
requestedWidth = widths.requested;
function handleApiData( data ) {
- var imageInfo;
+ var imageInfo, imageData;
if ( !data || !data.query ) {
// No information, oh well
@@ -761,17 +727,13 @@
}
viewer.cacheRepoInfo( data.query.repos );
- imageInfo = viewer.getImageInfo( data.query.pages );
+ imageInfo = viewer.getFirst( data.query.pages );
if ( imageInfo ) {
- if ( !imageInfo.imageinfo ||
- imageInfo.imageinfo.length ===
0 ) {
- // No data, fail.
- $.Deferred().reject();
- }
+ imageData = mw.mmv.ImageData.newFromImageInfo(
fileTitle, imageInfo );
// Give back the information we have
- return $.Deferred().resolve( imageInfo,
viewer.repoInfo, targetWidth );
+ return $.Deferred().resolve( imageData,
viewer.repoInfo, targetWidth, requestedWidth );
} else {
return $.Deferred().reject();
}
@@ -802,20 +764,25 @@
// Fetch the new thumb url but nothing else, because
it's
// the only non-cacheable thing
apiArgs.iiprop = 'url';
- return this.imageInfo[filename].then( function (
cachedInfo ) {
- return makeImageInfoRequest( apiArgs ).then(
function ( imageInfo, repoInfo, targetWidth ) {
- var innerInfo,
- newInfo = $.extend( true, {},
cachedInfo );
- $.each( imageInfo.imageinfo, function (
i, item ) {
- innerInfo = item;
- return false;
- } );
- $.each( newInfo.imageinfo, function (
i, item ) {
- item.thumburl =
innerInfo.thumburl;
- item.thumbwidth =
innerInfo.thumbwidth;
- item.thumbheight =
innerInfo.thumbheight;
- } );
- return $.Deferred().resolve( newInfo,
repoInfo, targetWidth );
+ return this.imageInfo[filename].then( function (
imageData, repoInfo ) {
+ var maybeThumb = imageData.getThumbUrl(
requestedWidth );
+
+ // Thumbnail caching! Woo!
+ if ( maybeThumb ) {
+ return $.Deferred().resolve( imageData,
repoInfo, targetWidth, requestedWidth );
+ }
+
+ return viewer.api.get( apiArgs ).then( function
( data ) {
+ var imageInfo, innerInfo;
+
+ imageInfo = viewer.getFirst(
data.query.pages );
+ innerInfo = viewer.getFirst(
imageInfo.imageinfo );
+
+ if ( innerInfo.thumburl ) {
+ imageData.addThumbUrl(
innerInfo.thumbwidth, innerInfo.thumburl );
+ }
+
+ return $.Deferred().resolve( imageData,
repoInfo, targetWidth, requestedWidth );
} );
} );
}
diff --git
a/resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
b/resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
index d0d3bcd..dad2b75 100644
--- a/resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
+++ b/resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js
@@ -524,54 +524,43 @@
/**
* @method
* Sets the URL for the File: page of the image
- * @param {Object} repoInfo
- * @param {mw.Title} fileTitle
+ * @param {string} url
*/
- LIP.setFilePageLink = function ( repoInfo, fileTitle ) {
- var linkpath;
+ LIP.setFilePageLink = function ( url ) {
+ this.$repo.prop( 'href', url );
+ this.$license.prop( 'href', url );
+ };
- if ( repoInfo.descBaseUrl ) {
- linkpath = repoInfo.descBaseUrl +
fileTitle.getMainText();
- } else {
- if ( repoInfo.server && repoInfo.articlepath ) {
- linkpath = repoInfo.server +
repoInfo.articlepath;
- } else {
- linkpath = mw.config.get( 'wgArticlePath' );
- }
- linkpath = linkpath.replace( '$1',
fileTitle.getPrefixedText() );
- }
-
- 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
+ * Saves some data about the image on the $useFile element for later
setup.
+ * @param {mw.Title} title
+ * @param {string} src The URL for the full-size image
+ * @param {boolean} isLocal Whether the file is on this wiki or not
+ */
+ LIP.initUseFileData = function ( title, src, isLocal ) {
+ this.$useFile.data( 'title', title );
+ this.$useFile.data( 'src', src );
+ this.$useFile.data( 'isLocal', isLocal );
};
/**
* @method
* Sets the link to the user page where possible
- * @param {Object} repoInfo
+ * @param {mw.mmv.RepoData} repoData
* @param {string} username
* @param {string} gender
*/
- LIP.setUserPageLink = function ( repoInfo, username, gender ) {
+ LIP.setUserPageLink = function ( repoData, username, gender ) {
var userlink,
userpage = 'User:' + username;
- if ( repoInfo.descBaseUrl ) {
+ if ( repoData instanceof mw.mmv.ForeignDbRepoData ) {
// We basically can't do anything about this; fail
this.$username.addClass( 'empty' );
} else {
- if ( repoInfo.server && repoInfo.articlepath ) {
- userlink = repoInfo.server +
repoInfo.articlepath;
+ if ( repoData.absoluteArticlePath ) {
+ userlink = repoData.absoluteArticlePath;
} else {
userlink = mw.config.get( 'wgArticlePath' );
}
diff --git a/resources/ext.multimediaViewer/mmv.js
b/resources/ext.multimediaViewer/mmv.js
new file mode 100644
index 0000000..87f5930
--- /dev/null
+++ b/resources/ext.multimediaViewer/mmv.js
@@ -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 ) );
--
To view, visit https://gerrit.wikimedia.org/r/106846
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ife8293c86683ea914b1a5a60000584b501d92e55
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits