MarkTraceur has uploaded a new change for review.
https://gerrit.wikimedia.org/r/109331
Change subject: Add Thumbnail model
......................................................................
Add Thumbnail model
Change-Id: Icefc9fe851c960b2668f107bd07b95427d69c28f
---
M MultimediaViewer.php
M resources/mmv/mmv.js
M resources/mmv/mmv.lightboximage.js
A resources/mmv/model/mmv.model.Thumbnail.js
4 files changed, 83 insertions(+), 39 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer
refs/changes/31/109331/1
diff --git a/MultimediaViewer.php b/MultimediaViewer.php
index 0ad250b..1c48628 100644
--- a/MultimediaViewer.php
+++ b/MultimediaViewer.php
@@ -141,6 +141,17 @@
),
), $moduleInfoMMVM );
+$wgResourceModules['mmv.model.Thumbnail'] = array_merge( array(
+ 'scripts' => array(
+ 'mmv.model.Thumbnail.js',
+ ),
+
+ 'dependencies' => array(
+ 'mmv.model',
+ 'oojs',
+ ),
+), $moduleInfoMMVM );
+
$wgResourceModules['mmv.provider'] = array_merge( array(
'scripts' => array(
'mmv.provider.js',
@@ -200,6 +211,7 @@
'mmv.model.FileUsage',
'mmv.model.Image',
'mmv.model.Repo',
+ 'mmv.model.Thumbnail',
'mmv.provider',
'mediawiki.language',
),
diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js
index 2611170..fd0947d 100755
--- a/resources/mmv/mmv.js
+++ b/resources/mmv/mmv.js
@@ -155,7 +155,7 @@
$links.data( 'filePageLink', filePageLink );
// Create a LightboxImage object for each legit image
- thisImage = viewer.createNewImage( $thumb.prop( 'src'
), filePageLink, fileTitle, index, thumb, caption );
+ thisImage = viewer.createNewImage( $thumb.prop( 'src'
), fileTitle, index, thumb, caption );
urls.push( thisImage );
@@ -222,14 +222,8 @@
* @param {string} [caption] The caption, if any.
* @returns {mw.LightboxImage}
*/
- MMVP.createNewImage = function ( fileLink, filePageLink, fileTitle,
index, thumb, caption ) {
- var thisImage = new mw.LightboxImage( fileLink, filePageLink,
fileTitle, index, thumb, caption );
- thisImage.filePageLink = filePageLink;
- thisImage.filePageTitle = fileTitle;
- thisImage.index = index;
- thisImage.thumbnail = thumb;
-
- return thisImage;
+ MMVP.createNewImage = function ( fileLink, fileTitle, index, thumb,
caption ) {
+ return new mw.LightboxImage( fileLink, fileTitle, index, thumb,
caption );
};
/**
@@ -264,7 +258,7 @@
*/
MMVP.getImageSizeApiArgs = function ( ui ) {
var requestedWidth, calculatedMaxWidth,
- thumb = ui.currentImage.thumbnail,
+ thumb = ui.currentImage.thumbnail.thumb,
targetWidth = ui.$imageWrapper.width(),
targetHeight = ui.$imageWrapper.height();
@@ -440,21 +434,19 @@
/**
* @method
* Set the image information in the UI.
- * @param {mw.LightboxImage} image
+ * @param {mw.mmv.model.Thumbnail} thumbnail
* @param {mw.mmv.model.Image} imageData
* @param {mw.mmv.model.Repo} repoData
*/
- MMVP.setImageInfo = function ( image, imageData, repoData ) {
+ MMVP.setImageInfo = function ( thumbnail, imageData, repoData ) {
var gfpid,
msgname,
- fileTitle = image.filePageTitle,
- caption = image.caption,
viewer = this,
ui = this.lightbox.iface;
- ui.$title.text( fileTitle.getNameText() );
+ ui.$title.text( imageData.title.getNameText() );
- ui.initUseFileData( fileTitle, imageData.url, repoData.isLocal
);
+ ui.initUseFileData( imageData.title, imageData.url,
repoData.isLocal );
ui.$useFileLi.removeClass( 'empty' );
ui.setRepoDisplay( repoData.displayName, repoData.favIcon,
repoData.isLocal );
@@ -540,7 +532,7 @@
ui.$credit.toggleClass( 'empty', !imageData.source &&
!imageData.author );
- ui.description.set( imageData.description, caption );
+ ui.description.set( imageData.description, thumbnail.caption );
msgname = 'multimediaviewer-license-' + ( imageData.license ||
'' );
@@ -611,22 +603,22 @@
var mdpid,
viewer = this;
- this.lightbox.currentIndex = image.index;
+ this.lightbox.currentIndex = image.thumbnail.index;
// Open with the already-loaded thumbnail
// Avoids trying to load /wiki/Undefined and doesn't
// cost any network time - the library currently needs
// some src attribute to work. Will fix.
image.initialSrc = initialSrc;
- this.currentImageFilename =
image.filePageTitle.getPrefixedText();
- this.currentImageFileTitle = image.filePageTitle;
+ this.currentImageFilename =
image.thumbnail.title.getPrefixedText();
+ this.currentImageFileTitle = image.thumbnail.title;
this.lightbox.iface.comingFromPopstate = comingFromPopstate;
this.lightbox.open();
$( document.body ).addClass( 'mw-mlb-lightbox-open' );
mdpid = this.profileStart( 'metadata-fetch' );
- this.fetchImageInfo( image.filePageTitle ).done( function (
imageData, repoInfo, size, requestedWidth ) {
+ this.fetchImageInfo( image.thumbnail.title ).done( function (
imageData, repoInfo, size, requestedWidth ) {
var pid,
repoData = mw.mmv.model.Repo.newFromRepoInfo(
repoInfo[imageData.repo] ),
imageEle = new Image(),
@@ -655,7 +647,7 @@
viewer.lightbox.iface.$imageDiv.removeClass( 'empty' );
viewer.lightbox.iface.replaceImageWith( imageEle );
- viewer.setImageInfo( image, imageData, repoData );
+ viewer.setImageInfo( image.thumbnail, imageData,
repoData );
} );
comingFromPopstate = false;
@@ -888,7 +880,7 @@
comingFromPopstate = true;
if ( linkState[0] === '#mediaviewer' ) {
statedIndex =
mw.mediaViewer.lightbox.images[linkState[2]];
- if ( statedIndex.filePageTitle.getPrefixedText() ===
linkState[1] ) {
+ if ( statedIndex.thumbnail.title.getPrefixedText() ===
linkState[1] ) {
$foundElement = $( imgsSelector ).eq(
linkState[2] );
mw.mediaViewer.loadImage( statedIndex,
$foundElement.prop( 'src' ) );
}
diff --git a/resources/mmv/mmv.lightboximage.js
b/resources/mmv/mmv.lightboximage.js
index f00c653..d74cfea 100644
--- a/resources/mmv/mmv.lightboximage.js
+++ b/resources/mmv/mmv.lightboximage.js
@@ -22,29 +22,21 @@
* Represents an image on the page.
* @constructor
* @param {string} fileLink Link to the file - generally a thumb URL
- * @param {string} filePageLink Link to the File: page
* @param {mw.Title} fileTitle Represents the File: page
* @param {number} index Which number file this is
* @param {HTMLImageElement} thumb The thumbnail that represents this
image on the page
* @param {string} [caption] The caption, if any.
*/
- function LightboxImage( fileLink, filePageLink, fileTitle, index,
thumb, caption ) {
+ function LightboxImage( fileLink, fileTitle, index, thumb, caption ) {
MLBImage.call( this, fileLink );
- /** @property {string} filePageLink URL to the image's file
page */
- this.filePageLink = filePageLink;
-
- /** @property {mw.Title} filePageTitle Title of the image's
file page */
- this.filePageTitle = fileTitle;
-
- /** @property {number} index What number this image is in the
array of indexed images */
- this.index = index;
-
- /** @property {HTMLImageElement} thumbnail The <img> element
that holds the already-loaded thumbnail of the image*/
- this.thumbnail = thumb;
-
- /** @property {string} caption The caption of the image, if any
*/
- this.caption = caption;
+ /** @property {mw.mmv.model.Thumbnail} thumbnail The thumbnail
data for this image */
+ this.thumbnail = new mw.mmv.model.Thumbnail(
+ fileTitle,
+ index,
+ thumb,
+ caption
+ );
}
oo.inheritClass( LightboxImage, MLBImage );
diff --git a/resources/mmv/model/mmv.model.Thumbnail.js
b/resources/mmv/model/mmv.model.Thumbnail.js
new file mode 100644
index 0000000..da128e8
--- /dev/null
+++ b/resources/mmv/model/mmv.model.Thumbnail.js
@@ -0,0 +1,48 @@
+/*
+ * 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.Thumbnail
+ * @extends mw.mmv.model.Model
+ * Represents a thumbnail object on the page
+ * @constructor
+ * @param {mw.Title} title
+ * @param {number} index
+ * @param {HTMLImageElement} thumb
+ * @param {string} [caption]
+ */
+ function Thumbnail( title, index, thumb, caption ) {
+ mw.mmv.model.Model.apply( this );
+
+ /** @property {mw.Title} title Title for the file page of the
image */
+ this.title = title;
+
+ /** @property {number} index Used to determine order, in the
DOM, of the thumbnails */
+ this.index = index;
+
+ /** @property {HTMLImageElement} thumb The thumbnail itself */
+ this.thumb = thumb;
+
+ /** @property {string/undefined} caption Unsafe HTML sometimes
goes here, and may be undefined */
+ this.caption = caption;
+ }
+
+ oo.inheritClass( Thumbnail, mw.mmv.model.Model );
+
+ mw.mmv.model.Thumbnail = Thumbnail;
+}( mediaWiki, OO ) );
--
To view, visit https://gerrit.wikimedia.org/r/109331
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icefc9fe851c960b2668f107bd07b95427d69c28f
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