r73256 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73255‎ | r73256 | r73257 >
Date:23:07, 17 September 2010
Author:bharris
Status:resolved (Comments)
Tags:
Comment:
Add a little bulletproofing.
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -246,6 +246,7 @@
247247 if ( config.userID.length == 32 ) {
248248 requestData.aaanontoken = config.userID;
249249 }
 250+
250251 var request = $.ajax( {
251252 url: wgScriptPath + '/api.php',
252253 data: requestData,
@@ -259,8 +260,12 @@
260261 },
261262 'afterGetRatingData' : function( data ) {
262263 var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings;
 264+ if (data.error) {
 265+ alert(data.error.code);
 266+ }
 267+
263268 // add the correct data to the markup
264 - if ( data.query.articleassessment && data.query.articleassessment.length > 0 ) {
 269+ if ( data.query && data.query.articleassessment && data.query.articleassessment.length > 0 ) {
265270 for ( var r in data.query.articleassessment[0].ratings ) {
266271 var rating = data.query.articleassessment[0].ratings[r],
267272 $rating = $( '#' + rating.ratingdesc ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r73267removing debug code added in r73256adam01:09, 18 September 2010
r73522ArticleAssessment: Followup to r73256: use typeof foo != 'undefined' as this ...catrope12:55, 22 September 2010

Comments

#Comment by Catrope (talk | contribs)   12:55, 22 September 2010
+				if ( data.query && data.query.articleassessment && data.query.articleassessment.length > 0 ) {

This is insufficient, you need to use typeof data.query != 'undefined' to avoid a JS error when accessing the possibly nonexistent property .query. Fixed in r73522.

Status & tagging log