Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/120808
Change subject: Image model ...................................................................... Image model Splitting the huge commit. Commit message to follow. Change-Id: Ibe71bc8bd74e4ba5a024ac722432ccf0b8f65e71 --- A modules/ve-mw/dm/models/ve.dm.MWImageModel.js 1 file changed, 192 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/08/120808/1 diff --git a/modules/ve-mw/dm/models/ve.dm.MWImageModel.js b/modules/ve-mw/dm/models/ve.dm.MWImageModel.js new file mode 100644 index 0000000..540b12e --- /dev/null +++ b/modules/ve-mw/dm/models/ve.dm.MWImageModel.js @@ -0,0 +1,192 @@ +/*! + * VisualEditor DataModel MWImageModel class. + * + * @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * MediaWiki image model. + * + * @class + * @mixins OO.EventEmitter + * @mixins ve.Scalable + * + * @constructor + */ +ve.dm.MWImageModel = function VeDmMWImageModel() { + // Mixin constructors + OO.EventEmitter.call( this ); +// ve.Scalable.call( this ); + + // Properties + this.viewNode = null; + this.modelNode = null; + this.mediaType = null; + + // Image properties + this.caption = null; + this.altText = null; + this.type = null; + this.alignment = null; + this.currentDimensions = { + 'width': null, + 'height': null + }; + this.originalDimensions = { + 'width': null, + 'height': null + }; +}; + +/* Inheritance */ + +OO.mixinClass( ve.dm.MWImageModel, OO.EventEmitter ); + +/* Events */ + +/** + * @event change + */ + +/* Static Properties */ + +ve.dm.MWImageModel.static.infoCache = {}; + +/* Static Methods */ + +/** + * Get the original size of the image object from the API, if it exists + * + * @static + * @param {string} filename Image file name + * @returns {jQuery.Promise} Promise which resolves with an info object + * containing width, height and mediatype properties + * +ve.dm.MWImageModel.static.getInfo = function ( filename ) { + var deferred = $.Deferred(), + cache = this.infoCache; + + if ( cache[filename] ) { + deferred.resolve( cache[filename] ); + } else { + // Get image info from server + ve.init.mw.Target.static.apiRequest( + { + 'action': 'query', + 'prop': 'imageinfo', + 'indexpageids': '1', + 'iiprop': 'size|mediatype', + 'titles': filename + }, + { 'type': 'POST' } + ) + .done( function ( response ) { + var svgMaxSize, + page = response.query && response.query.pages[response.query.pageids[0]], + info = page && page.imageinfo && page.imageinfo[0], + originalDimensions = { + 'width': info.width, + 'height': info.height + }, + maxDimensions = originalDimensions, + ratio = originalDimensions.width / originalDimensions.height; + + // Calculate max dimensions for drawings + if ( info.mediatype === 'DRAWING' ) { + svgMaxSize = mw.config.get( 'wgVisualEditor' ).svgMaxSize; + maxDimensions = ratio > 1 ? + { 'width': Math.round( svgMaxSize * ratio ), 'height': svgMaxSize } : + { 'width': svgMaxSize, 'height': Math.round( svgMaxSize / ratio ) }; + } + + if ( info ) { + info = { + 'originalDimensions': originalDimensions, + 'maxDimensions': maxDimensions, + 'mediaType': info.mediatype + }; + // Store result and resolve + cache[filename] = info; + deferred.resolve( info ); + } else { + deferred.reject(); + } + } ) + .fail( function () { + deferred.reject(); + } ); + } + + return deferred.promise(); +}; + +/* Methods */ + +/** + * Load from image data, and fetch additional info from server. + * + * @param {ve.dm.MWImageNode} model Image node + * @returns {jQuery.Promise} Promise, resolved when info is loaded + */ +ve.dm.MWImageModel.prototype.load = function ( model ) { + var deferred = $.Deferred(); + +/* // Get additional info from API + this.constructor.static.getInfo( model.getFilename() ) + .done( ve.bind( function ( info ) { + //this.setOriginalDimensions( info.originalDimensions ); + //this.setMaxDimensions( info.maxDimensions ); + //this.setMediaType( info.mediaType ); + }, this ) ) + .always( ve.bind( function () { + deferred.resolve(); + }, this ) ); +*/ + return deferred.promise(); +}; + +ve.dm.MWImageModel.prototype.setOriginalDimensions = function ( dimensions ) { + this.originalDimensions = dimensions; +}; + +ve.dm.MWImageModel.prototype.setCurrentDimensions = function ( dimensions ) { + this.currentDimensions = dimensions; +}; + +ve.dm.MWImageModel.prototype.setMaxDimensions = function ( dimensions ) { + this.originalDimensions = dimensions; +}; + +/** + * Get plain object representation of image. + * + * @returns {Object|null} Plain object representation, or null if empty + */ +ve.dm.MWImageModel.prototype.getPlainObject = function () { + return { + // TODO: Export properties in a format compatible with Parsoid image attributes + }; +}; + +/** + * Get symbolic name of media type. + * + * Example values: "BITMAP" for JPEG or PNG images; "DRAWING" for SVG graphics + * + * @returns {string|null} Symbolic media type name, or null if empty + */ +ve.dm.MWImageModel.prototype.getMediaType = function () { + return this.mediaType; +}; + +/** + * Set symbolic name of media type. + * + * @see #getMediaType. + * + * @returns {string} Symbolic media type name + */ +ve.dm.MWImageModel.prototype.setMediaType = function ( type ) { + this.mediaType = type; +}; -- To view, visit https://gerrit.wikimedia.org/r/120808 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibe71bc8bd74e4ba5a024ac722432ccf0b8f65e71 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits