r76287 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76286‎ | r76287 | r76288 >
Date:06:21, 8 November 2010
Author:neilk
Status:deferred
Tags:
Comment:
rudimentary api for accessing imageinfo. Not actually part of UploadWizard (this code is obsolete) just abstracting into a library
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.ApiQueryImageInfo.js (added) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.ApiQueryImageInfo.js
@@ -0,0 +1,79 @@
 2+/**
 3+ * Library to assist with fetching images
 4+ * Abstracted out of some code which was in mw.UploadWizard which is no longer necessary.
 5+ * This may have a number of bugs, as I'm just leaving it here to save the functionality, it's not yet used in anything
 6+ */
 7+( function( mw, $ ) {
 8+
 9+ $.extend( mw.Api.prototype, {
 10+
 11+ /**
 12+ * Get information about an image.
 13+ * TODO the API can handle multiple titles, this assumes only one
 14+ * @param {mw.Title} title of the image
 15+ * @param {Array} properties: array of strings of properties wanted (see api documentation)
 16+ * @param {Object} extraParams: parameters (such as width; not needed for all calls).
 17+ * @param {Function} ok: success callback, takes a javascript object like imageinfo results (see API Docs)
 18+ * @param {Function} err: error callback
 19+ */
 20+ getImageInfo: function( title, properties, extraParams, ok, err ) {
 21+ var params = {
 22+ 'prop': 'imageinfo',
 23+ 'titles': title.toString()
 24+ };
 25+ if ( mw.isDefined( extraParams.width ) ) {
 26+ params['iiurlwidth'] = extraParams.width;
 27+ }
 28+ params.iiprop = properties.join( '|' );
 29+
 30+ var success = function( data ) {
 31+ if ( !data || !data.query || !data.query.pages ) {
 32+ return;
 33+ }
 34+
 35+ var foundImageInfo = false;
 36+ $j.each( data.query.pages, function( id, page ) {
 37+ if ( page.imageinfo && page.imageinfo.length ) {
 38+ var imageinfo = page.imageinfo[0];
 39+ ok( imageinfo );
 40+ foundImageInfo = true;
 41+ return false;
 42+ }
 43+ } );
 44+
 45+ if ( ! foundImageInfo ) {
 46+ err( data );
 47+ }
 48+ };
 49+
 50+ this.get( params, { ok: ok, err: err } );
 51+ },
 52+
 53+ /**
 54+ * Get information about the thumbnail of an image.
 55+ * @param {mw.Title} title of the image
 56+ * @param {Number} width desired
 57+ * @param {Function} execute on success, taking an object with the properties of src, width, height
 58+ * @param {Function} to execute if error encountered
 59+ */
 60+ getThumbnail: function( title, width, ok, err ) {
 61+
 62+ var extraParams = { 'width': width };
 63+ var properties = [ 'url', 'size' ];
 64+
 65+ var success = function( imageinfo ) {
 66+ ok( {
 67+ 'src': imageinfo.thumburl,
 68+ 'width': imageinfo.thumbwidth,
 69+ 'height': imageinfo.thumbheight
 70+ } );
 71+ };
 72+
 73+ this.getImageInfo( title, properties, extraParams, success, err );
 74+ }
 75+
 76+ } );
 77+
 78+}) ( window.mw, jQuery );
 79+
 80+
Property changes on: trunk/extensions/UploadWizard/resources/mw.ApiQueryImageInfo.js
___________________________________________________________________
Added: svn:eol-style
181 + native

Status & tagging log