jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/351698 )

Change subject: Reduce some redundancy in _requestInfoAndRenderLink
......................................................................


Reduce some redundancy in _requestInfoAndRenderLink

Change-Id: I6b27188610b744c99e124a0ee33b45d996600c61
---
M lib/wt2html/tt/LinkHandler.js
1 file changed, 34 insertions(+), 50 deletions(-)

Approvals:
  Subramanya Sastry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/wt2html/tt/LinkHandler.js b/lib/wt2html/tt/LinkHandler.js
index c4890e3..d3b53cb 100644
--- a/lib/wt2html/tt/LinkHandler.js
+++ b/lib/wt2html/tt/LinkHandler.js
@@ -1302,34 +1302,22 @@
 };
 
 // Internal Helper
-WikiLinkHandler.prototype._requestInfoAndRenderLink = function(reqs, 
manualthumb, errorHandler, renderer) {
+WikiLinkHandler.prototype._requestInfoAndRenderLink = function(reqs, 
errorHandler, renderer) {
        var env = this.manager.env;
-       Promise.all(reqs)
+       Promise.all(reqs.map(function(s) { return s.promise; }))
        .then(function(result) {
                var errs = [];
-               var info = extractInfo(env, result[0]);
-               if (!info) {
-                       info = errorHandler();
-                       errs.push(makeErr('apierror-filedoesnotexist', 'This 
image does not exist.'));
-               } else if (info.hasOwnProperty('thumberror')) {
-                       errs.push(makeErr('apierror-unknownerror', 
info.thumberror));
-               }
-
-               // Only valid for files (via renderFile)
-               var manualinfo;
-               if (manualthumb !== undefined) {
-                       manualinfo = extractInfo(env, result[1]);
-                       if (!manualinfo) {
-                               manualinfo = errorHandler();
-                               errs.push(makeErr('apierror-filedoesnotexist',
-                                       'This thumbnail does not exist.',
-                                       { name: manualthumb.v }));
-                       } else if (manualinfo.hasOwnProperty('thumberror')) {
-                               errs.push(makeErr('apierror-unknownerror', 
manualinfo.thumberror));
+               var infos = result.map(function(r, i) {
+                       var info = extractInfo(env, r);
+                       if (!info) {
+                               info = errorHandler();
+                               errs.push(makeErr('apierror-filedoesnotexist', 
'This image does not exist.', reqs[i].params));
+                       } else if (info.hasOwnProperty('thumberror')) {
+                               errs.push(makeErr('apierror-unknownerror', 
info.thumberror));
                        }
-               }
-
-               return [errs, info, manualinfo];
+                       return info;
+               });
+               return [errs].concat(infos);
        }, function(e) {
                var err = makeErr('apierror-unknownerror', e);
                return [[err], errorHandler()];
@@ -1791,9 +1779,9 @@
                }
        }
 
-       var reqs = [
-               env.batcher.imageinfo(title.getKey(), 
dims).then(wrapResp(title)),
-       ];
+       var reqs = [{
+               promise: env.batcher.imageinfo(title.getKey(), 
dims).then(wrapResp(title)),
+       }];
 
        // If this is a manual thumbnail, fetch the info for that as well
        if (opts.manualthumb) {
@@ -1807,17 +1795,17 @@
                        manualThumbTitle.ns = title.ns;
                        manualThumbTitle.nskey = title.nskey;
                }
-               reqs.push(
-                       env.batcher.imageinfo(manualThumbTitle.getKey(), 
opts.size.v)
-                       .then(wrapResp(manualThumbTitle))
-               );
+               reqs.push({
+                       promise: env.batcher
+                               .imageinfo(manualThumbTitle.getKey(), 
opts.size.v)
+                               .then(wrapResp(manualThumbTitle)),
+                       params: { name: opts.manualthumb.v },
+               });
        }
 
        cb({ async: true });
 
-       this._requestInfoAndRenderLink(reqs,
-               opts.manualthumb,
-               errorInfo.bind(null, env, opts),
+       this._requestInfoAndRenderLink(reqs, errorInfo.bind(null, env, opts),
                this.handleInfo.bind(this, cb, token, opts, optSources));
 };
 
@@ -1877,23 +1865,19 @@
 
        var env = this.manager.env;
        var title = target.title;
-       var reqs = [
-               env.batcher.imageinfo(title.getKey(), { height: null, width: 
null })
-               .then(function(data) {
-                       return { title: title, data: data };
-               })
-       ];
+       var reqs = [{
+               promise: env.batcher
+                       .imageinfo(title.getKey(), { height: null, width: null 
})
+                       .then(function(data) {
+                               return { title: title, data: data };
+                       }),
+       }];
 
-       this._requestInfoAndRenderLink(
-               reqs,
-               undefined, // pass undefined, not null
-               function() {
-                       return {
-                               url: './Special:FilePath/' + (title ? 
Util.sanitizeTitleURI(title.getKey()) : ''),
-                       };
-               },
-               this.linkToMedia.bind(this, cb, token, title)
-       );
+       this._requestInfoAndRenderLink(reqs, function() {
+               return {
+                       url: './Special:FilePath/' + (title ? 
Util.sanitizeTitleURI(title.getKey()) : ''),
+               };
+       }, this.linkToMedia.bind(this, cb, token, title));
 };
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/351698
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6b27188610b744c99e124a0ee33b45d996600c61
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to