From 21ccb20d3a8776692c732a02f4c40afa70a18f7f Mon Sep 17 00:00:00 2001 From: Moriel Schottlender Date: Fri, 14 Feb 2014 17:58:30 -0500 Subject: [PATCH] Only display image info if that exists When a new search is performed in the MWMediaSearchWidget, image thumbnail details are extracted from the API's imageinfo. In some cases, this parameter does not exist. MWMediaResultWidget relies on that parameter to get image details like 'src' and width/height. Without it the search fails. This fix makes sure that the thumbnail result is only displayed if there are 'imageinfo' details at all. Otherwise, the image result is ignored. Bug: 61392 Change-Id: I5261059bb42d3a57441514eafaa0bffa3a3c3ba4 --- .../ui/widgets/ve.ui.MWMediaSearchWidget.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js index 5590ff6685..64d0479b54 100755 --- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaSearchWidget.js @@ -187,15 +187,20 @@ ve.ui.MWMediaSearchWidget.prototype.onMediaQueryDone = function ( source, data ) } for ( page in pages ) { - title = new mw.Title( pages[page].title ).getMainText(); - if ( !( title in this.titles ) ) { - this.titles[title] = true; - items.push( - new ve.ui.MWMediaResultWidget( - pages[page], - { '$': this.$, 'size': this.size } - ) - ); + // Verify that imageinfo exists + // In case it does not, skip the image to avoid errors in + // ve.ui.MWMediaResultWidget + if ( pages[page].imageinfo && pages[page].imageinfo.length > 0 ) { + title = new mw.Title( pages[page].title ).getMainText(); + if ( !( title in this.titles ) ) { + this.titles[title] = true; + items.push( + new ve.ui.MWMediaResultWidget( + pages[page], + { '$': this.$, 'size': this.size } + ) + ); + } } }