Catrope has uploaded a new change for review.
https://gerrit.wikimedia.org/r/90309
Change subject: Followup 8a4058584: use a single media source for rerendering
images
......................................................................
Followup 8a4058584: use a single media source for rerendering images
The code asked all media sources for a rerender and used whichever one
came in first, which meant that it might potentially render the wrong
image, or reject the promise if one source served an error response
before a good response from another source arrived.
Also make the promise abortable and reject it if we can't find an image
source in the response.
Change-Id: I6b516ad41b8a9e2abd440625bb76f3e1abb54520
---
M modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
1 file changed, 27 insertions(+), 29 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/09/90309/1
diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
b/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
index e33d8a2..1154b62 100644
--- a/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWImageNode.js
@@ -52,37 +52,33 @@
/** */
ve.ce.MWImageNode.prototype.generateContents = function () {
- var i, len, source,
- sources = ve.copy( ve.init.platform.getMediaSources() ),
- deferred = $.Deferred();
+ var i, len, xhr, deferred = $.Deferred(), promise = deferred.promise();
- for ( i = 0, len = sources.length; i < len; i++ ) {
- source = sources[i];
- source.request = $.ajax( {
- 'url': source.url,
- 'data': {
- 'action': 'query',
- 'prop': 'imageinfo',
- 'iiprop': 'url',
- 'iiurlwidth': this.model.getAttribute( 'width'
),
- 'iiurlheight': this.model.getAttribute(
'height' ),
- 'titles': this.model.getAttribute( 'resource'
).replace( /^(.+\/)*/, '' ),
- 'format': 'json'
- },
- // This request won't be cached since the JSON-P
callback is unique. However make sure
- // to allow jQuery to cache otherwise so it won't e.g.
add "&_=(random)" which will
- // trigger a MediaWiki API error for invalid parameter
"_".
- 'cache': true,
- // TODO: Only use JSON-P for cross-domain.
- // jQuery has this logic built-in (if url is not
same-origin ..)
- // but isn't working for some reason.
- 'dataType': 'jsonp',
- 'success': ve.bind( this.onParseSuccess, this, deferred
),
- 'error': ve.bind( this.onParseError, this, deferred )
- } );
- }
+ xhr = $.ajax( {
+ 'url': mw.util.wikiScript( 'api' ),
+ 'data': {
+ 'action': 'query',
+ 'prop': 'imageinfo',
+ 'iiprop': 'url',
+ 'iiurlwidth': this.model.getAttribute( 'width' ),
+ 'iiurlheight': this.model.getAttribute( 'height' ),
+ 'titles': this.model.getAttribute( 'resource'
).replace( /^(.+\/)*/, '' ),
+ 'format': 'json'
+ },
+ // This request won't be cached since the JSON-P callback is
unique. However make sure
+ // to allow jQuery to cache otherwise so it won't e.g. add
"&_=(random)" which will
+ // trigger a MediaWiki API error for invalid parameter "_".
+ 'cache': true,
+ // TODO: Only use JSON-P for cross-domain.
+ // jQuery has this logic built-in (if url is not same-origin ..)
+ // but isn't working for some reason.
+ 'dataType': 'jsonp',
+ 'success': ve.bind( this.onParseSuccess, this, deferred ),
+ 'error': ve.bind( this.onParseError, this, deferred )
+ } );
- return deferred.promise();
+ promise.abort = ve.bind( xhr.abort, xhr );
+ return promise;
};
/**
@@ -100,6 +96,8 @@
}
if ( src ) {
deferred.resolve( src );
+ } else {
+ deferred.reject();
}
};
--
To view, visit https://gerrit.wikimedia.org/r/90309
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b516ad41b8a9e2abd440625bb76f3e1abb54520
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits