From 4b00c765ffddacbc88526b9d757e751f0ec151e8 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Sat, 5 May 2018 15:13:15 +0100 Subject: [PATCH] Add an 'api' parameter to ApiResponseCache Change-Id: Ie68b70472447a4bb2c9be8ed505a91f24858059d --- modules/ve-mw/init/ve.init.mw.ApiResponseCache.js | 5 ++++- modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js | 6 ++++-- modules/ve-mw/init/ve.init.mw.ImageInfoCache.js | 6 ++++-- modules/ve-mw/init/ve.init.mw.LinkCache.js | 6 ++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/ve-mw/init/ve.init.mw.ApiResponseCache.js b/modules/ve-mw/init/ve.init.mw.ApiResponseCache.js index 03f2fbe476..d2d6419662 100644 --- a/modules/ve-mw/init/ve.init.mw.ApiResponseCache.js +++ b/modules/ve-mw/init/ve.init.mw.ApiResponseCache.js @@ -14,11 +14,14 @@ * @class * @extends OO.EventEmitter * @constructor + * @param {mw.Api} [api] API object to use. Defaults to new mw.Api() */ -ve.init.mw.ApiResponseCache = function VeInitMwApiResponseCache() { +ve.init.mw.ApiResponseCache = function VeInitMwApiResponseCache( api ) { // Mixin constructor OO.EventEmitter.call( this ); + this.api = api || new mw.Api(); + // Keys are titles, values are deferreds this.deferreds = {}; diff --git a/modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js b/modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js index 743e4c0f79..f53a838ebf 100644 --- a/modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js +++ b/modules/ve-mw/init/ve.init.mw.GalleryImageInfoCache.js @@ -11,9 +11,11 @@ * @class * @extends ve.init.mw.ImageInfoCache * @constructor + * @param {mw.Api} [api] */ ve.init.mw.GalleryImageInfoCache = function VeInitMwGalleryImageInfoCache() { - ve.init.mw.GalleryImageInfoCache.super.call( this ); + // Parent constructor + ve.init.mw.GalleryImageInfoCache.super.apply( this, arguments ); }; /* Inheritance */ @@ -26,7 +28,7 @@ OO.inheritClass( ve.init.mw.GalleryImageInfoCache, ve.init.mw.ImageInfoCache ); * @inheritdoc */ ve.init.mw.GalleryImageInfoCache.prototype.getRequestPromise = function ( subqueue ) { - return new mw.Api().get( + return this.api.get( { action: 'query', prop: 'imageinfo', diff --git a/modules/ve-mw/init/ve.init.mw.ImageInfoCache.js b/modules/ve-mw/init/ve.init.mw.ImageInfoCache.js index 478bdb1c34..68d17369da 100644 --- a/modules/ve-mw/init/ve.init.mw.ImageInfoCache.js +++ b/modules/ve-mw/init/ve.init.mw.ImageInfoCache.js @@ -11,9 +11,11 @@ * @class * @extends ve.init.mw.ApiResponseCache * @constructor + * @param {mw.Api} [api] */ ve.init.mw.ImageInfoCache = function VeInitMwImageInfoCache() { - ve.init.mw.ImageInfoCache.super.call( this ); + // Parent constructor + ve.init.mw.ImageInfoCache.super.apply( this, arguments ); }; /* Inheritance */ @@ -41,7 +43,7 @@ ve.init.mw.ImageInfoCache.static.processPage = function ( page ) { ve.init.mw.ImageInfoCache.prototype.getRequestPromise = function ( subqueue ) { // If you change what `iiprop`s are being fetched, update // ve.ui.MWMediaDialog to add the same ones to the cache. - return new mw.Api().get( + return this.api.get( { action: 'query', prop: 'imageinfo', diff --git a/modules/ve-mw/init/ve.init.mw.LinkCache.js b/modules/ve-mw/init/ve.init.mw.LinkCache.js index b6310a9b59..de6a192f64 100644 --- a/modules/ve-mw/init/ve.init.mw.LinkCache.js +++ b/modules/ve-mw/init/ve.init.mw.LinkCache.js @@ -11,9 +11,11 @@ * @class * @extends ve.init.mw.ApiResponseCache * @constructor + * @param {mw.Api} [api] */ ve.init.mw.LinkCache = function VeInitMwLinkCache() { - ve.init.mw.LinkCache.super.call( this ); + // Parent constructor + ve.init.mw.LinkCache.super.apply( this, arguments ); // Keys are page names, values are link data objects // This is kept for synchronous retrieval of cached values via #getCached @@ -184,7 +186,7 @@ ve.init.mw.LinkCache.prototype.get = function ( title ) { * @inheritdoc */ ve.init.mw.LinkCache.prototype.getRequestPromise = function ( subqueue ) { - return new mw.Api().get( { + return this.api.get( { action: 'query', prop: 'info|pageprops|pageimages|pageterms', pithumbsize: 80,