r71995 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71994‎ | r71995 | r71996 >
Date:00:11, 31 August 2010
Author:adam
Status:deferred
Tags:
Comment:
End of the day ArticleAssessment commit. Progress was made. True story.
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css
@@ -116,9 +116,10 @@
117117 .article-assessment-wrapper .article-assessment-rating-field-name {
118118 float: left;
119119 width: 90px;
 120+ font-weight: bold;
 121+ font-size: 11px;
120122 }
121 -.article-assessment-wrapper .article-assessment-rating-field-value-wrapper,
122 -.article-assessment-wrapper .article-assessment-rating-field-value-disabled {
 123+.article-assessment-wrapper .article-assessment-rating-field-value-wrapper {
123124 background: url( ../images/rating_bg.gif ) 0 0 no-repeat;
124125 width: 120px;
125126 height: 13px;
@@ -126,6 +127,7 @@
127128 float: left;
128129 padding: 2px;
129130 text-indent: -9999px;
 131+ margin-top: 2px;
130132 }
131133 .article-assessment-wrapper .article-assessment-rate-instructions,
132134 .article-assessment-wrapper .article-assessment-rate-feedback,
@@ -146,19 +148,37 @@
147149 float: right;
148150 display: block;
149151 }
150 -.article-assessment-wrapper .article-assessment-rating-field-value-disabled {
151 - background: url( ../images/rating_disabled_bg.gif ) 0 0 no-repeat;
152 -}
153152 .article-assessment-wrapper .article-assessment-wrapper .article-assessment-rating-fields {
154153 margin: 8px 0;
155154 }
156155 .article-assessment-wrapper .article-assessment-rating-fields .field-wrapper {
157156 margin-bottom: 5px;
158157 }
 158+.article-assessment-rating-count {
 159+ font-size: 11px;
 160+ margin-left: 5px;
 161+ float: left;
 162+}
 163+.article-assessment-submit input {
 164+ margin: 2px 0;
 165+}
 166+.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-value-wrapper {
 167+ background: url( ../images/rating_disabled_bg.gif ) 0 0 no-repeat;
 168+}
 169+.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-value {
 170+ display: none;
 171+}
 172+.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-count {
 173+ display: none;
 174+}
 175+.article-assessment-wrapper .article-assessment-ratings-disabled .article-assessment-rating-field-name {
 176+ color: #9f9f9f;
 177+}
159178 /* Self Clearing Floats */
160179 .article-assessment-wrapper .article-assessment-information:after,
161180 .article-assessment-wrapper .field-wrapper:after,
162181 .article-assessment-wrapper .article-assessment-rating-fields:after,
 182+.article-assessment-rating:after,
163183 .article-assessment-wrapper .article-assessment-submit:after,
164184 .article-assessment-wrapper .rating-fields:after {
165185 content: ".";
@@ -170,6 +190,7 @@
171191 .article-assessment-wrapper .field-wrapper,
172192 .article-assessment-wrapper .article-assessment-information,
173193 .article-assessment-wrapper .article-assessment-rating-fields,
 194+.article-assessment-rating,
174195 .article-assessment-wrapper .article-assessment-submit,
175196 .article-assessment-wrapper .rating-fields {
176197 display: inline-block;
@@ -177,6 +198,7 @@
178199 * html .article-assessment-wrapper .field-wrapper,
179200 * html .article-assessment-wrapper .article-assessment-information,
180201 * html .article-assessment-wrapper .article-assessment-rating-fields,
 202+* html .article-assessment-rating,
181203 * html .article-assessment-wrapper .article-assessment-submit,
182204 * html .article-assessment-wrapper .rating-fields {
183205 height: 1%;
@@ -184,6 +206,7 @@
185207 .article-assessment-wrapper .field-wrapper,
186208 .article-assessment-wrapper .article-assessment-information,
187209 .article-assessment-wrapper .article-assessment-rating-fields,
 210+.article-assessment-rating,
188211 .article-assessment-wrapper .article-assessment-submit,
189212 .article-assessment-wrapper .rating-fields {
190213 display: block;
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -18,7 +18,7 @@
1919 'fieldPrefix': 'articleassessment-rating-',
2020 'fieldHTML': '<div class="field-wrapper"> \
2121 <label for="rating_{FIELD}" original-title="{HINT}" class="rating-field-label">{LABEL}</label> \
22 - <select id="rating_{FIELD}" name="rating[{FIELD}]" class="rating-field"> \
 22+ <select id="rating_{FIELD}" name="rating{FIELD}" class="rating-field"> \
2323 <option value="1">1</option> \
2424 <option value="2">2</option> \
2525 <option value="3">3</option> \
@@ -48,7 +48,7 @@
4949 </fieldset> \
5050 </form> \
5151 </div>',
52 - 'ratingHTML': '<div class="article-assessment-rating"> \
 52+ 'ratingHTML': '<div class="article-assessment-rating" id="articleassessment-rating-{FIELD}"> \
5353 <span class="article-assessment-rating-field-name">{LABEL}</span> \
5454 <span class="article-assessment-rating-field-value-wrapper"> \
5555 <span class="article-assessment-rating-field-value">{VALUE}</span> \
@@ -76,24 +76,63 @@
7777 .replace( /\{FEEDBACK\}/g, mw.usability.getMsg('articleassessment-featurefeedback') )
7878 .replace( /\{YOURFEEDBACK\}/g, mw.usability.getMsg('articleassessment-yourfeedback') )
7979 .replace( /\{ARTICLERATING\}/g, mw.usability.getMsg('articleassessment-articlerating' ) )
80 - .replace( /\{RESULTSHIDE\}/g, mw.usability.getMsg('articleassessment-results-hide' ) )
81 - .replace( /\{RESULTSSHOW\}/g, mw.usability.getMsg('articleassessment-results-show' ) ) );
 80+ .replace( /\{RESULTSHIDE\}/g, mw.usability.getMsg('articleassessment-results-hide' )
 81+ .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) )
 82+ .replace( /\{RESULTSSHOW\}/g, mw.usability.getMsg('articleassessment-results-show' )
 83+ .replace( /\[\[\|([^\]]*)\]\]/, '<a href="#">$1</a>' ) ) );
8284 for( var field in settings.fieldMessages ) {
8385 $output.find( '.article-assessment-rating-fields' )
8486 .append( $( settings.fieldHTML
8587 .replace( /\{LABEL\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] ) )
86 - .replace( /\{FIELD\}/g, mw.usability.getMsg( settings.fieldMessages[field] ) )
 88+ .replace( /\{FIELD\}/g, "[" + settings.fieldMessages[field] + "]" )
8789 .replace( /\{HINT\}/g, mw.usability.getMsg( settings.fieldPrefix + settings.fieldMessages[field] + settings.fieldHintSuffix ) ) ) );
8890 $output.find( '#article-assessment-ratings' )
8991 .append( $( settings.ratingHTML
9092 .replace( /\{LABEL\}/g, mw.usability.getMsg(settings.fieldPrefix + settings.fieldMessages[field]) )
 93+ .replace( /\{FIELD\}/g, settings.fieldMessages[field] )
9194 .replace( /\{VALUE\}/g, '0%' )
9295 .replace( /\{COUNT\}/g, mw.usability.getMsg( 'field-count' ) ) )
9396 );
9497 }
95 -
 98+ $output.find( '#article-assessment' ).data( 'articleAssessment-context', { 'settings': settings });
 99+ // hook up the ratings show/hide
 100+ $output
 101+ .find( '.article-assessment-show-ratings a' )
 102+ .click( function() {
 103+ $( this )
 104+ .parent()
 105+ .hide();
 106+ $output
 107+ .find( '#article-assessment-ratings' )
 108+ .removeClass( 'article-assessment-ratings-disabled' )
 109+ .end()
 110+ .find( '.article-assessment-hide-ratings' )
 111+ .show();
 112+ return false;
 113+ } )
 114+ .end()
 115+ .find( '.article-assessment-hide-ratings a' )
 116+ .click( function() {
 117+ $( this )
 118+ .parent()
 119+ .hide();
 120+ $output
 121+ .find( '#article-assessment-ratings' )
 122+ .addClass( 'article-assessment-ratings-disabled' )
 123+ .end()
 124+ .find( '.article-assessment-show-ratings' )
 125+ .show();
 126+ return false;
 127+ } )
 128+ .click();
96129 $( '#catlinks' ).before( $output );
97130
 131+ // set the height of our smaller fieldset to match the taller
 132+ if( $( '#article-assessment-rate' ).height() > $( '#article-assessment-ratings' ).height() ) {
 133+ $( '#article-assessment-ratings' ).css( 'minHeight', $( '#article-assessment-rate' ).height() );
 134+ } else {
 135+ $( '#article-assessment-rate' ).css( 'minHeight', $( '#article-assessment-ratings' ).height() );
 136+ }
98137 // attempt to fetch the ratings
99138 $.ArticleAssessment.fn.getRatingData();
100139
@@ -115,15 +154,6 @@
116155 }
117156 } );
118157 });
119 - // if the rating is stale, add the stale class
120 - if( true /* replace with conditional based on returned results of past user ratings */ ) {
121 - // add the stale star class to each on star
122 - $( '.ui-stars-star-on' )
123 - .addClass( 'ui-stars-star-stale' );
124 - // add the stale message
125 - $( '.article-assessment-submit' )
126 - .append( settings.staleMSG.replace( /\{MSG\}/g, mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' ) ) );
127 - }
128158 // intialize the tooltips
129159 $( '.field-wrapper label[original-title]' ).each(function() {
130160 $( this )
@@ -131,38 +161,63 @@
132162 .attr( 'original-title', $( this ).attr( 'original-title' ) )
133163 .tipsy( { gravity : 'se', opacity: '0.9', } ) );
134164 } );
135 - // initialize the ratings
136 - $( '.article-assessment-rating-field-value' ).each( function() {
137 - $( this )
138 - .css( {
139 - 'width': 120 - ( 120 * ( parseInt( $( this ).text() ) / 100 ) ) + "px"
140 - } )
141 - } );
142165 // bind submit event to the form
143 -
 166+ $( '#article-assessment' ).submit( function() { $.ArticleAssessment.fn.submitRating(); return false; } );
144167 // prevent the submit button for being active until all ratings are filled out
145168
146169 },
147170 'getRatingData': function() {
148 - var request = $j.ajax( {
 171+ var request = $.ajax( {
149172 url: wgScriptPath + '/api.php',
150173 data: {
151 - 'action': 'articleassessment',
152 - 'getCumulativeResults': 1,
153 - 'pageId': wgArticleId,
154 - 'revId': wgCurRevisionId
 174+ 'action': 'query',
 175+ 'list': 'articleassessment',
 176+ 'aarevid': wgCurRevisionId,
 177+ 'aapageid': wgArticleId,
 178+ 'format': 'json'
155179 },
156180 dataType: 'json',
157181 success: function( data ) {
158 - console.log(data);
 182+ $.ArticleAssessment.fn.afterGetRatingData( data );
159183 },
160184 error: function(XMLHttpRequest, textStatus, errorThrown) {
161 - console.log(XMLHttpRequest, textStatus, errorThrown);
 185+ // console.log(XMLHttpRequest, textStatus, errorThrown);
162186 }
163187 } );
164188 },
 189+ 'afterGetRatingData' : function( data ) {
 190+ var settings = $( '#article-assessment' ).data( 'articleAssessment-context' ).settings;
 191+ // add the correct data to the markup
 192+ for( rating in data.query.articleassessment[0].ratings) {
 193+ var rating = data.query.articleassessment[0].ratings[rating],
 194+ $rating = $( '#' + rating.ratingdesc ),
 195+ label = mw.usability.getMsg( 'articleassessment-noratings', [rating.total, rating.count] );
 196+ $rating
 197+ .find( '.article-assessment-rating-field-value' )
 198+ .text( rating.total )
 199+ .end()
 200+ .find( '.article-assessment-rating-count' )
 201+ .text( label );
 202+ }
 203+ // if the rating is stale, add the stale class
 204+ if( true /* replace with conditional based on returned results of past user ratings */ ) {
 205+ // add the stale star class to each on star
 206+ $( '.ui-stars-star-on' )
 207+ .addClass( 'ui-stars-star-stale' );
 208+ // add the stale message
 209+ $( '.article-assessment-submit' )
 210+ .append( settings.staleMSG.replace( /\{MSG\}/g, mw.usability.getMsg( 'articleassessment-stalemessage-revisioncount' ) ) );
 211+ }
 212+ // initialize the ratings
 213+ $( '.article-assessment-rating-field-value' ).each( function() {
 214+ $( this )
 215+ .css( {
 216+ 'width': 120 - ( 120 * ( parseFloat( $( this ).text() ) / 5 ) ) + "px"
 217+ } )
 218+ } );
 219+ },
165220 'getUserRatingData': function() {
166 - var request = $j.ajax( {
 221+ var request = $.ajax( {
167222 url: wgScriptPath + '/api.php',
168223 data: {
169224 'action': 'articleassessment',
@@ -176,21 +231,34 @@
177232 console.log(data);
178233 },
179234 error: function(XMLHttpRequest, textStatus, errorThrown) {
180 - console.log(XMLHttpRequest, textStatus, errorThrown);
 235+ // console.log( XMLHttpRequest, textStatus, errorThrown );
181236 }
182237 } );
183238 },
184 - 'submit': function() {
 239+ 'submitRating': function() {
185240 // clear out the stale message
186 - var request = $j.ajax( {
 241+ var results = {};
 242+ $( '.rating-field input' ).each( function() {
 243+ // expects the hidden inputs to have names like 'rating[field-name]' which we use to
 244+ // be transparent about what values we're sending to the server
 245+ var fieldName = $( this ).attr('name').match(/\[([a-zA-Z0-9\-]*)\]/)[1];
 246+ results[ fieldName ] = $( this ).val();
 247+ } );
 248+ var request = $.ajax( {
187249 url: wgScriptPath + '/api.php',
188250 data: {
189 - 'action': 'ratearticle',
190 - 'data': ratingsData
 251+ 'action': 'articleassessment',
 252+ 'aarevid': wgCurRevisionId,
 253+ 'aapageid': wgArticleId,
 254+ 'aar1' : results['wellsourced'],
 255+ 'aar2' : results['neutrality'],
 256+ 'aar3' : results['completeness'],
 257+ 'aar4' : results['readability'],
 258+ 'format': 'json'
191259 },
192260 dataType: 'json',
193261 success: function( data ) {
194 - $this.suggestions( 'suggestions', data[1] );
 262+ console.log(data);
195263 }
196264 } );
197265 }
@@ -198,7 +266,6 @@
199267 };
200268 // FIXME - this should be moved out of here
201269 $( document ).ready( function () {
202 - console.log(this);
203 - $.ArticleAssessment.fn.init( { 'endpoint': wgScriptPath + "/api.php" } );
 270+ $.ArticleAssessment.fn.init( );
204271 } ); //document ready
205272 } )( jQuery );
\ No newline at end of file

Status & tagging log