r72182 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72181‎ | r72182 | r72183 >
Date:00:00, 2 September 2010
Author:adam
Status:deferred
Tags:
Comment:
ArticleAssessment js improvements. Fixed some bad code in the stars plugin and general improvements and further implimentations in the AA code itself
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/jquery.stars.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css
@@ -108,13 +108,25 @@
109109 .article-assessment-wrapper .article-assessment-submit {
110110 text-align: right;
111111 }
112 -.article-assessment-wrapper .article-assessment-stale-msg {
113 - background: #d6f3ff;
114 - border: 1px solid #5dc9f4;
 112+.article-assessment-wrapper .article-assessment-flash {
115113 float: left;
116114 font-size: 11px;
117115 padding: 1px 5px;
 116+ width: 560px;
 117+ text-align: left;
118118 }
 119+.article-assessment-wrapper .article-assessment-stale-msg {
 120+ background: #d6f3ff;
 121+ border: 2px solid #5dc9f4;
 122+}
 123+.article-assessment-wrapper .article-assessment-success-msg {
 124+ background: #e8e8e8;
 125+ border: 2px solid #006505;
 126+}
 127+.article-assessment-wrapper .article-assessment-error-msg {
 128+ background: #e8e8e8;
 129+ border: 2px solid #a91100;
 130+}
119131 .article-assessment-wrapper .article-assessment-rating-field-name {
120132 float: left;
121133 width: 90px;
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php
@@ -89,6 +89,8 @@
9090 'articleassessment-rating-neutrality-tooltip',
9191 'articleassessment-rating-completeness-tooltip',
9292 'articleassessment-rating-readability-tooltip',
 93+ 'articleassessment-error',
 94+ 'articleassessment-thanks',
9395 'articleassessment-articlerating',
9496 'articleassessment-featurefeedback',
9597 'articleassessment-noratings',
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -2,7 +2,7 @@
33 $.ArticleAssessment = {
44 'config': {
55 'authtoken': '',
6 - 'userID': wgUserName,
 6+ 'userID': '',
77 'pageID': wgArticleId,
88 'revID': wgCurRevisionId
99 },
@@ -66,8 +66,8 @@
6767 var config = $.ArticleAssessment.config;
6868 // if this is an anon user, get a unique identifier for them
6969 // load up the stored ratings and update the markup if the cookie exists
70 - var cookieSettings = $.cookie( 'mwArticleAssessment' );
71 - if ( true || typeof cookieSettings == 'undefined' ) {
 70+ var userToken = $.cookie( 'mwArticleAssessmentUserToken' );
 71+ if ( typeof userToken == 'undefined' || userToken == null ) {
7272 function randomString( string_length ) {
7373 var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
7474 var randomstring = '';
@@ -77,24 +77,22 @@
7878 }
7979 return randomstring;
8080 }
81 - cookieSettings = {
82 - uid: randomString( 32 )
83 - };
84 - $.cookie( 'mwArticleAssessment', cookieSettings );
 81+ userToken = randomString( 32 );
 82+ $.cookie( 'mwArticleAssessmentUserToken', userToken );
8583 }
8684 if ( ! wgUserName ) {
87 - config.userID = cookieSettings.uid;
 85+ config.userID = userToken;
8886 }
8987 // setup our markup using the template varibales in settings
9088 var $output = $( settings.structureHTML
9189 .replace( /\{INSTRUCTIONS\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-pleaserate') )
92 - .replace( /\{FEEDBACK\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-featurefeedback')
 90+ .replace( /\{FEEDBACK\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-featurefeedback')
9391 .replace( /\[\[([^\|\]]*)\|([^\|\]]*)\]\]/, '<a href="' + wgArticlePath + '">$2</a>' ) )
94 - .replace( /\{YOURFEEDBACK\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-yourfeedback') )
95 - .replace( /\{ARTICLERATING\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-articlerating' ) )
96 - .replace( /\{RESULTSHIDE\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-results-hide' )
 92+ .replace( /\{YOURFEEDBACK\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-yourfeedback') )
 93+ .replace( /\{ARTICLERATING\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-articlerating' ) )
 94+ .replace( /\{RESULTSHIDE\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-results-hide' )
9795 .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) )
98 - .replace( /\{RESULTSSHOW\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-results-show' )
 96+ .replace( /\{RESULTSSHOW\}/g, $.ArticleAssessment.fn.getMsg('articleassessment-results-show' )
9997 .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) ) );
10098 for( var field in settings.fieldMessages ) {
10199 $output.find( '.article-assessment-rating-fields' )
@@ -146,9 +144,9 @@
147145
148146 // set the height of our smaller fieldset to match the taller
149147 if( $( '#article-assessment-rate' ).height() > $( '#article-assessment-ratings' ).height() ) {
150 - $( '#article-assessment-ratings' ).css( 'minHeight', $( '#article-assessment-rate' ).height() );
 148+ $( '#article-assessment-ratings' ).css( 'minHeight', $( '#article-assessment-rate' ).height() );
151149 } else {
152 - $( '#article-assessment-rate' ).css( 'minHeight', $( '#article-assessment-ratings' ).height() );
 150+ $( '#article-assessment-rate' ).css( 'minHeight', $( '#article-assessment-ratings' ).height() );
153151 }
154152 // attempt to fetch the ratings
155153 $.ArticleAssessment.fn.getRatingData();
@@ -177,7 +175,7 @@
178176 $( this )
179177 .after( $( '<span class="rating-field-hint" />' )
180178 .attr( 'original-title', $( this ).attr( 'original-title' ) )
181 - .tipsy( { gravity : 'se', opacity: '0.9', } ) );
 179+ .tipsy( { gravity : 'se', opacity: '0.9', } ) );
182180 } );
183181 // bind submit event to the form
184182 $( '#article-assessment' )
@@ -189,35 +187,39 @@
190188 // Request the ratings data for the current article
191189 'getRatingData': function() {
192190 var config = $( '#article-assessment' ).data( 'articleAssessment-context' ).config;
 191+ var requestData = {
 192+ 'action': 'query',
 193+ 'list': 'articleassessment',
 194+ 'aarevid': config.revID,
 195+ 'aapageid': config.pageID,
 196+ 'aauserrating': 1,
 197+ 'format': 'json'
 198+ }
 199+ if( config.userID.length == 32 ) {
 200+ requestData.aaanontoken = config.userID;
 201+ }
193202 var request = $.ajax( {
194203 url: wgScriptPath + '/api.php',
195 - data: {
196 - 'action': 'query',
197 - 'list': 'articleassessment',
198 - 'aarevid': config.revID,
199 - 'aapageid': config.pageID,
200 - 'aauserrating': 1,
201 - 'aauserid': config.userID,
202 - 'format': 'json'
203 - },
 204+ data: requestData,
204205 dataType: 'json',
205206 success: function( data ) {
206207 $.ArticleAssessment.fn.afterGetRatingData( data );
207208 },
208 - error: function(XMLHttpRequest, textStatus, errorThrown) {
209 - // console.log(XMLHttpRequest, textStatus, errorThrown);
 209+ error: function( XMLHttpRequest, textStatus, errorThrown ) {
 210+ $.ArticleAssessment.fn.flashNotice( $.ArticleAssessment.fn.getMsg( 'articleassessment-error' ),
 211+ { 'class': 'article-assessment-error-msg' } );
210212 }
211213 } );
212214 },
213215 'afterGetRatingData' : function( data ) {
214216 var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings;
215217 // add the correct data to the markup
216 - if( data.query.articleassessment.length > 0 ) {
 218+ if( data.query.articleassessment && data.query.articleassessment.length > 0 ) {
217219 for( rating in data.query.articleassessment[0].ratings) {
218220 var rating = data.query.articleassessment[0].ratings[rating],
219221 $rating = $( '#' + rating.ratingdesc ),
220222 count = rating.count,
221 - total = rating.total / count,
 223+ total = ( rating.total / count ).toFixed( 1 ),
222224 label = $.ArticleAssessment.fn.getMsg( 'articleassessment-noratings', [total, count] );
223225 $rating
224226 .find( '.article-assessment-rating-field-value' )
@@ -231,7 +233,7 @@
232234 }
233235 }
234236 // if the rating is stale, add the stale class
235 - if( data.query.articleassessment ) {
 237+ if( data.query.articleassessment.stale ) {
236238 // add the stale star class to each on star
237239 $( '.ui-stars-star-on' )
238240 .addClass( 'ui-stars-star-stale' );
@@ -240,8 +242,11 @@
241243 .replace( /'''([^']*)'''/g, '<strong>$1</strong>' )
242244 .replace( /''([^']*)''/g, '<em>$1</em>' );
243245 $.ArticleAssessment.fn.flashNotice( msg, { 'class': 'article-assessment-stale-msg' } );
 246+ } else {
 247+ // if it's not a stale rating, we want to make the stars blue
 248+ $( '.ui-stars-star-on' ).addClass( 'ui-stars-star-rated' );
244249 }
245 - }
 250+ }
246251 // initialize the ratings
247252 $( '.article-assessment-rating-field-value' ).each( function() {
248253 $( this )
@@ -255,8 +260,9 @@
256261 // clear out the stale message
257262 $.ArticleAssessment.fn.flashNotice( );
258263
259 - //lock the star inputs
260 -
 264+ // lock the star inputs & submit
 265+ $( '.rating-field' ).stars( 'disable' );
 266+ $( '#article-assessment input' ).attr( "disabled", "disabled" );
261267 // get our results for submitting
262268 var results = {};
263269 $( '.rating-field input' ).each( function() {
@@ -280,14 +286,24 @@
281287 },
282288 dataType: 'json',
283289 success: function( data ) {
 290+ // update the ratings
 291+ $.ArticleAssessment.fn.getRatingData();
284292 // set the stars to rated status
285 - $j('.ui-stars-star-on').addClass('ui-stars-star-rated');
286 - // unlock the stars
287 -
 293+ $( '.ui-stars-star-on' ).addClass( 'ui-stars-star-rated' );
 294+ // unlock the stars & submit
 295+ $( '.rating-field' ).stars( 'enable' );
 296+ $( '#article-assessment input:disabled' ).removeAttr( "disabled" );
288297 // update the results
289298
290299 // show the results
291300 $( '#article-assessment .article-assessment-show-ratings a' ).click();
 301+ // say thank you
 302+ $.ArticleAssessment.fn.flashNotice( $.ArticleAssessment.fn.getMsg( 'articleassessment-thanks' ),
 303+ { 'class': 'article-assessment-success-msg' } );
 304+ },
 305+ error: function( XMLHttpRequest, textStatus, errorThrown ) {
 306+ $.ArticleAssessment.fn.flashNotice( $.ArticleAssessment.fn.getMsg( 'articleassessment-error' ),
 307+ { 'class': 'article-assessment-error-msg' } );
292308 }
293309 } );
294310 },
Index: trunk/extensions/ArticleAssessmentPilot/js/jquery.stars.js
@@ -264,10 +264,8 @@
265265 $.fn.stars = function ( ) {
266266 // convert the arguments to an array
267267 var args = Array.prototype.slice.call(arguments);
268 -
269268 // default value to return -- overwritten by api calls
270269 var out = $( this );
271 -
272270 $( this ).each( function() {
273271 // get the context if it's already been initialized
274272 var context = $( this ).data( 'stars-context' );
@@ -287,9 +285,9 @@
288286 $.stars.create.call( context );
289287 } else if ( typeof args[0] == 'string' ) {
290288 // API call
291 - var funcName = args.shift();
 289+ var funcName = args[0];
292290 // call the function, and if it returns something, store the output in our return var
293 - out = $.stars[funcName].call( context, args[0] ) || out;
 291+ out = $.stars[funcName].call( context, args.slice(1) ) || out;
294292 }
295293 } else {
296294 // initialize with the defaults

Status & tagging log