r76317 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76316‎ | r76317 | r76318 >
Date:17:02, 8 November 2010
Author:aaron
Status:deferred
Tags:
Comment:
* Output fatals on JS review if they occur
* var rsubmit -> asubmit
* Remove some condition duplication
Modified paths:
  • /trunk/extensions/FlaggedRevs/client/review.js (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/client/review.js
@@ -52,10 +52,10 @@
5353
5454 // (a) If only a few levels are zero ("incomplete") then disable submission.
5555 // (b) Re-enable submission for already accepted revs when ratings change.
56 - var rsubmit = document.getElementById('mw-fr-submit-accept');
57 - if( rsubmit ) {
58 - rsubmit.disabled = somezero ? 'disabled' : '';
59 - rsubmit.value = wgAjaxReview.flagMsg; // reset to "Accept"
 56+ var asubmit = document.getElementById('mw-fr-submit-accept');
 57+ if( asubmit ) {
 58+ asubmit.disabled = somezero ? 'disabled' : '';
 59+ asubmit.value = wgAjaxReview.flagMsg; // reset to "Accept"
6060 }
6161
6262 // Update colors of <select>
@@ -68,9 +68,9 @@
6969 */
7070 FlaggedRevs.maybeDisableAcceptButton = function() {
7171 if ( typeof(jsReviewNeedsChange) != 'undefined' && jsReviewNeedsChange == 1 ) {
72 - var rsubmit = document.getElementById('mw-fr-submit-accept');
73 - if( rsubmit ) {
74 - rsubmit.disabled = 'disabled';
 72+ var asubmit = document.getElementById('mw-fr-submit-accept');
 73+ if( asubmit ) {
 74+ asubmit.disabled = 'disabled';
7575 }
7676 }
7777 }
@@ -215,48 +215,28 @@
216216 window.clearTimeout(wgAjaxReview.timeoutID);
217217 }
218218 var tier = 0; // review tier
219 - var response = request.responseText;
 219+ var response = request.responseText; // full response text
220220 var msg = response.substr(6); // remove <err#> or <suc#>
221221 var tierMatch = msg.match(/^<t#(\d)>/);
222222 if( tierMatch ) {
223223 tier = tierMatch[1];
224224 msg = msg.substr(5); // remove <t#x>
225225 }
226 - var diffRevRatings = null;
227 - // Errors: output any error response message
228 - if( response.indexOf('<err#>') == 0 ) {
229 - jsMsg( msg, 'review' ); // success/failure notice
230 - window.scroll(0,0); // scroll up to notice
231 - // OK: get new diff UI elements
232 - } else {
233 - var diffUIParams = document.getElementById("mw-fr-diff-dataform");
234 - // Diffs: update the contents of the mw-fr-diff-headeritems div
235 - if ( diffUIParams ) {
236 - wgAjaxReview.inprogress = true;
237 - var args = []; // <oldid, newid>
238 - args.push( diffUIParams.getElementsByTagName('input')[0].value );
239 - args.push( diffUIParams.getElementsByTagName('input')[1].value );
240 - // Send!
241 - var old = sajax_request_type;
242 - sajax_request_type = "GET";
243 - sajax_do_call( "FlaggedArticleView::AjaxBuildDiffHeaderItems",
244 - args, wgAjaxReview.processDiffHeaderItemsResult );
245 - sajax_request_type = old;
246 - }
247 - }
248 - var rsubmit = document.getElementById("mw-fr-submit-accept");
249 - var usubmit = document.getElementById("mw-fr-submit-unaccept");
250 - var legend = document.getElementById("mw-fr-reviewformlegend");
251 - var diffNotice = document.getElementById("mw-fr-difftostable");
 226+ // Some form elements...
 227+ var asubmit = document.getElementById('mw-fr-submit-accept');
 228+ var usubmit = document.getElementById('mw-fr-submit-unaccept');
 229+ var legend = document.getElementById('mw-fr-reviewformlegend');
 230+ var diffNotice = document.getElementById('mw-fr-difftostable');
252231 var tagBox = document.getElementById('mw-fr-revisiontag');
253232 // On success...
254233 if( response.indexOf('<suc#>') == 0 ) {
 234+ // (a) Update document title and form buttons...
255235 document.title = wgAjaxReview.actioncomplete;
256 - if( rsubmit && usubmit ) {
 236+ if( asubmit && usubmit ) {
257237 // Revision was flagged
258 - if( rsubmit.value == wgAjaxReview.sendingMsg ) {
259 - rsubmit.value = wgAjaxReview.flaggedMsg; // done!
260 - rsubmit.style.fontWeight = 'bold';
 238+ if( asubmit.value == wgAjaxReview.sendingMsg ) {
 239+ asubmit.value = wgAjaxReview.flaggedMsg; // done!
 240+ asubmit.style.fontWeight = 'bold';
261241 // Unlock and reset *unflag* button
262242 usubmit.value = wgAjaxReview.unflagMsg;
263243 usubmit.removeAttribute( 'style' ); // back to normal
@@ -266,29 +246,52 @@
267247 usubmit.value = wgAjaxReview.unflaggedMsg; // done!
268248 usubmit.style.fontWeight = 'bold';
269249 // Unlock and reset *flag* button
270 - rsubmit.value = wgAjaxReview.flagMsg;
271 - rsubmit.removeAttribute( 'style' ); // back to normal
272 - rsubmit.disabled = '';
 250+ asubmit.value = wgAjaxReview.flagMsg;
 251+ asubmit.removeAttribute( 'style' ); // back to normal
 252+ asubmit.disabled = '';
273253 }
274254 }
275 - // Hide "review this" box on diffs
276 - if( diffNotice ) diffNotice.style.display = 'none';
277 - // Remove review tag from draft
 255+ // (b) Remove review tag from drafts
278256 if( tagBox ) tagBox.style.display = 'none';
 257+ // (c) Update diff-related items...
 258+ var diffUIParams = document.getElementById('mw-fr-diff-dataform');
 259+ if ( diffUIParams ) {
 260+ // Hide "review this" box on diffs
 261+ if( diffNotice ) diffNotice.style.display = 'none';
 262+ // Update the contents of the mw-fr-diff-headeritems div
 263+ wgAjaxReview.inprogress = true;
 264+ var args = []; // <oldid, newid>
 265+ args.push( diffUIParams.getElementsByTagName('input')[0].value );
 266+ args.push( diffUIParams.getElementsByTagName('input')[1].value );
 267+ // Send!
 268+ var old = sajax_request_type;
 269+ sajax_request_type = "GET";
 270+ sajax_do_call( "FlaggedArticleView::AjaxBuildDiffHeaderItems",
 271+ args, wgAjaxReview.processDiffHeaderItemsResult );
 272+ sajax_request_type = old;
 273+ }
279274 // On failure...
280275 } else {
 276+ // (a) Update document title and form buttons...
281277 document.title = wgAjaxReview.actionfailed;
282 - if( rsubmit && usubmit ) {
 278+ if( asubmit && usubmit ) {
283279 // Revision was flagged
284 - if( rsubmit.value == wgAjaxReview.sendingMsg ) {
285 - rsubmit.value = wgAjaxReview.flagMsg; // back to normal
286 - rsubmit.disabled = ''; // unlock flag button
 280+ if( asubmit.value == wgAjaxReview.sendingMsg ) {
 281+ asubmit.value = wgAjaxReview.flagMsg; // back to normal
 282+ asubmit.disabled = ''; // unlock flag button
287283 // Revision was unflagged
288284 } else if( usubmit.value == wgAjaxReview.sendingMsg ) {
289285 usubmit.value = wgAjaxReview.unflagMsg; // back to normal
290286 usubmit.disabled = ''; // unlock
291287 }
292288 }
 289+ // (b) Output any error response message
 290+ if ( response.indexOf('<err#>') == 0 ) {
 291+ jsMsg( msg, 'review' ); // success/failure notice
 292+ } else {
 293+ jsMsg( request.responseText, 'review' ); // fatal notice
 294+ }
 295+ window.scroll(0,0); // scroll up to notice
293296 }
294297 wgAjaxReview.unlockForm();
295298 };
@@ -307,9 +310,9 @@
308311 }
309312
310313 wgAjaxReview.onLoad = function() {
311 - var rsubmit = document.getElementById("mw-fr-submit-accept");
312 - if( rsubmit ) {
313 - rsubmit.onclick = wgAjaxReview.ajaxCall;
 314+ var asubmit = document.getElementById("mw-fr-submit-accept");
 315+ if( asubmit ) {
 316+ asubmit.onclick = wgAjaxReview.ajaxCall;
314317 }
315318 var usubmit = document.getElementById("mw-fr-submit-unaccept");
316319 if( usubmit ) {

Status & tagging log