lib/mw/ApiRequest.js
function ImageInfoRequest(env, filename, dims, key) {
	ApiRequest.call(this, env, null);
	this.env = env;
	this.queueKey = key;
	this.reqType = "Image Info Request";

	var conf = env.conf.wiki;
	var filenames = [ filename ];
	var imgnsid = conf.canonicalNamespaces.image;
	var imgns = conf.namespaceNames[imgnsid];
	var props = [
		'mediatype',
		'mime',
		'size',
		'url',
		'badfile',
	];

	// If the videoinfo prop is available, as determined by our feature
	// detection when initializing the wiki config, use that to fetch the
	// derivates for videos.  videoinfo is just a wrapper for imageinfo,
	// so all our media requests should go there, and the response can be
	// disambiguated by the returned mediatype.
	var prop, prefix;
	if (conf.useVideoInfo) {
		prop = 'videoinfo';
		prefix = 'vi';
		props.push('derivatives', 'timedtext');
	} else {
		prop = 'imageinfo';
		prefix = 'ii';
	}

	this.ns = imgns;

	for (var ix = 0; ix < filenames.length; ix++) {
		filenames[ix] = imgns + ':' + filenames[ix];
	}

	var apiArgs = {
		action: 'query',
		format: 'json',
		formatversion: 2,
		prop: prop,
		titles: filenames.join('|'),
		rawcontinue: 1,
	};

	apiArgs[prefix + 'prop'] = props.join('|');
	apiArgs[prefix + 'badfilecontexttitle'] = env.page.name;

	if (dims) {
		if (dims.width !== undefined && dims.width !== null) {
			console.assert(typeof (dims.width) === 'number');
			apiArgs[prefix + 'urlwidth'] = dims.width;
			if (dims.page !== undefined) {
				// NOTE: This format is specific to PDFs.  Not sure how to
				// support this generally, though it seems common enough /
				// shared with other file types.
				apiArgs[prefix + 'urlparam'] = `page${dims.page}-${dims.width}px`;
			}
		}
		if (dims.height !== undefined && dims.height !== null) {
			console.assert(typeof (dims.height) === 'number');
			apiArgs[prefix + 'urlheight'] = dims.height;
		}
		if (dims.seek !== undefined) {
			apiArgs[prefix + 'urlparam'] = `seek=${dims.seek}`;
		}
	}

	this.requestOptions = {
		method: 'GET',
		followRedirect: true,
		uri: env.conf.wiki.apiURI,
		qs: apiArgs,
		timeout: env.conf.parsoid.timeouts.mwApi.imgInfo,
	};

	this.request(this.requestOptions);
}
function ImageInfoRequest(env, filename, dims, key) {
	ApiRequest.call(this, env, null);
	this.env = env;
	this.queueKey = key;
	this.reqType = "Image Info Request";

	var conf = env.conf.wiki;
	var filenames = [ filename ];
	var imgnsid = conf.canonicalNamespaces.image;
	var imgns = conf.namespaceNames[imgnsid];
	var props = [
		'mediatype',
		'mime',
		'size',
		'url',
		'badfile',
	];

	// If the videoinfo prop is available, as determined by our feature
	// detection when initializing the wiki config, use that to fetch the
	// derivates for videos.  videoinfo is just a wrapper for imageinfo,
	// so all our media requests should go there, and the response can be
	// disambiguated by the returned mediatype.
	var prop, prefix;
	if (conf.useVideoInfo) {
		prop = 'videoinfo';
		prefix = 'vi';
		props.push('derivatives', 'timedtext');
	} else {
		prop = 'imageinfo';
		prefix = 'ii';
	}

	this.ns = imgns;

	for (var ix = 0; ix < filenames.length; ix++) {
		filenames[ix] = imgns + ':' + filenames[ix];
	}

	var apiArgs = {
		action: 'query',
		format: 'json',
		formatversion: 2,
		prop: prop,
		titles: filenames.join('|'),
		rawcontinue: 1,
	};

	apiArgs[prefix + 'prop'] = props.join('|');
	apiArgs[prefix + 'badfilecontexttitle'] = env.page.name;

	if (dims) {
		if (dims.width !== undefined && dims.width !== null) {
			console.assert(typeof (dims.width) === 'number');
			apiArgs[prefix + 'urlwidth'] = dims.width;
			if (dims.page !== undefined) {
				// NOTE: This format is specific to PDFs.  Not sure how to
				// support this generally, though it seems common enough /
				// shared with other file types.
				apiArgs[prefix + 'urlparam'] = `page${dims.page}-${dims.width}px`;
			}
		}
		if (dims.height !== undefined && dims.height !== null) {
			console.assert(typeof (dims.height) === 'number');
			apiArgs[prefix + 'urlheight'] = dims.height;
		}
		if (dims.seek !== undefined) {
			apiArgs[prefix + 'urlparam'] = `seek=${dims.seek}`;
		}
	}

	this.requestOptions = {
		method: 'GET',
		followRedirect: true,
		uri: env.conf.wiki.apiURI,
		qs: apiArgs,
		timeout: env.conf.parsoid.timeouts.mwApi.imgInfo,
	};

	this.request(this.requestOptions);
}
function ImageInfoRequest ( env , filename , dims , key ) { ApiRequest . call ( this , env , null ) ; this . env = env ; this . queueKey = key ; this . reqType = "Image Info Request" ; var conf = env . conf . wiki ; var filenames = [ filename ] ; var imgnsid = conf . canonicalNamespaces . image ; var imgns = conf . namespaceNames [ imgnsid ] ; var props = [ 'mediatype' , 'mime' , 'size' , 'url' , 'badfile' , ] ; // If the videoinfo prop is available, as determined by our feature // detection when initializing the wiki config, use that to fetch the // derivates for videos.  videoinfo is just a wrapper for imageinfo, // so all our media requests should go there, and the response can be // disambiguated by the returned mediatype. var prop , prefix ; if ( conf . useVideoInfo ) { prop = 'videoinfo' ; prefix = 'vi' ; props . push ( 'derivatives' , 'timedtext' ) ; } else { prop = 'imageinfo' ; prefix = 'ii' ; } this . ns = imgns ; for ( var ix = 0 ; ix < filenames . length ; ix ++ ) { filenames [ ix ] = imgns + ':' + filenames [ ix ] ; } var apiArgs = { action : 'query' , format : 'json' , formatversion : 2 , prop : prop , titles : filenames . join ( '|' ) , rawcontinue : 1 , } ; apiArgs [ prefix + 'prop' ] = props . join ( '|' ) ; apiArgs [ prefix + 'badfilecontexttitle' ] = env . page . name ; if ( dims ) { if ( dims . width !== undefined && dims . width !== null ) { console . assert ( typeof ( dims . width ) === 'number' ) ; apiArgs [ prefix + 'urlwidth' ] = dims . width ; if ( dims . page !== undefined ) { // NOTE: This format is specific to PDFs.  Not sure how to // support this generally, though it seems common enough / // shared with other file types. apiArgs [ prefix + 'urlparam' ] = ` ${ dims . page } ${ dims . width } ` ; } } if ( dims . height !== undefined && dims . height !== null ) { console . assert ( typeof ( dims . height ) === 'number' ) ; apiArgs [ prefix + 'urlheight' ] = dims . height ; } if ( dims . seek !== undefined ) { apiArgs [ prefix + 'urlparam' ] = ` ${ dims . seek } ` ; } } this . requestOptions = { method : 'GET' , followRedirect : true , uri : env . conf . wiki . apiURI , qs : apiArgs , timeout : env . conf . parsoid . timeouts . mwApi . imgInfo , } ; this . request ( this . requestOptions ) ; }
Fetch information about an image.

@class
@extends ~ApiRequest
@param {MWParserEnvironment} env
@param {string} filename
@param {Object} [dims]
@param {number} [dims.width]
@param {number} [dims.height]
Fetch information about an image .