r99317 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99316‎ | r99317 | r99318 >
Date:18:52, 8 October 2011
Author:aaron
Status:resolved
Tags:
Comment:
ext.flaggedRevs.review.js cleanup:
* Set review form onchange events via JS instead of in the HTML
* Don't expose FlaggedRevsReview js objects
* Refactored an 'init' function into review.js
* Use dataType parameter as "json" for review activity ajax
* Use mw.util.wikiScript for ajax urls
* Removed document.title setting (which clobbered the existing title)
* Use jQuery selectors in some places
* Removed wpNotes input JS (param was removed with $wgFlaggedRevsComments)
* Renamed confusing function names
* Some style cleanups
Modified paths:
  • /trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/modules/ext.flaggedRevs.review.js (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php
@@ -305,8 +305,7 @@
306306 # If the sum of qualities of all flags is above 6, use drop down boxes.
307307 # 6 is an arbitrary value choosen according to screen space and usability.
308308 if ( $size > 6 ) {
309 - $attribs = array( 'name' => "wp$quality", 'id' => "wp$quality",
310 - 'onchange' => "FlaggedRevsReview.updateRatingForm()" );
 309+ $attribs = array( 'name' => "wp$quality", 'id' => "wp$quality" );
311310 $item .= Xml::openElement( 'select', $attribs ) . "\n";
312311 foreach ( $levels as $i => $name ) {
313312 $optionClass = array( 'class' => "fr-rating-option-$i" );
@@ -317,16 +316,14 @@
318317 # If there are more than two levels, current user gets radio buttons
319318 } elseif ( $numLevels > 2 ) {
320319 foreach ( $levels as $i => $name ) {
321 - $attribs = array( 'class' => "fr-rating-option-$i",
322 - 'onchange' => "FlaggedRevsReview.updateRatingForm()" );
 320+ $attribs = array( 'class' => "fr-rating-option-$i" );
323321 $item .= Xml::radioLabel( FlaggedRevs::getTagMsg( $name ), "wp$quality",
324322 $i, "wp$quality" . $i, ( $i == $selected ), $attribs ) . "\n";
325323 }
326324 # Otherwise make checkboxes (two levels available for current user)
327325 } elseif ( $numLevels == 2 ) {
328326 $i = $minLevel;
329 - $attribs = array( 'class' => "fr-rating-option-$i",
330 - 'onchange' => "FlaggedRevsReview.updateRatingForm()" );
 327+ $attribs = array( 'class' => "fr-rating-option-$i" );
331328 $attribs = $attribs + array( 'value' => $i );
332329 $item .= Xml::checkLabel( wfMsg( 'revreview-' . $levels[$i] ),
333330 "wp$quality", "wp$quality", ( $selected == $i ), $attribs ) . "\n";
Index: trunk/extensions/FlaggedRevs/presentation/modules/ext.flaggedRevs.review.js
@@ -3,9 +3,45 @@
44 * @author Aaron Schulz
55 * @author Daniel Arnold 2008
66 */
 7+( function( $ ) {
78
8 -window.FlaggedRevsReview = {
9 - 'isUserReviewing': 0, // user reviewing this page?
 9+var fr = {
 10+ /* User is reviewing this page? */
 11+ 'isUserReviewing': 0,
 12+
 13+ /* Startup function */
 14+ 'init': function() {
 15+ var form = $( '#mw-fr-reviewform' );
 16+
 17+ // Enable AJAX-based submit functionality to the review form on this page
 18+ $( '#mw-fr-submit-accept,#mw-fr-submit-unaccept' ).click( function( e ) {
 19+ fr.submitRevisionReview( this, form );
 20+ return false; // don't do normal non-AJAX submit
 21+ } );
 22+
 23+ // Disable 'accept' button if the revision was already reviewed.
 24+ // This is used so that they can be re-enabled if a rating changes.
 25+ if ( typeof( jsReviewNeedsChange ) != 'undefined' && jsReviewNeedsChange === 1 ) {
 26+ $( 'mw-fr-submit-accept' ).prop( 'disabled', 'disabled' );
 27+ }
 28+
 29+ // Setup <select> form option colors
 30+ fr.updateReviewFormColors( form );
 31+ // Update review form on change
 32+ form.find( 'input,select' ).change( function( e ) {
 33+ fr.updateReviewForm( form );
 34+ } );
 35+
 36+ // Display "advertise" notice
 37+ fr.enableAjaxReviewActivity();
 38+ // "De-advertise" user as "no longer reviewing" on navigate-away
 39+ $( window ).bind( 'beforeunload', function( e ) {
 40+ if ( fr.isUserReviewing === 1 ) {
 41+ fr.deadvertiseReviewing();
 42+ }
 43+ } );
 44+ },
 45+
1046 /*
1147 * Updates for radios/checkboxes on patch by Daniel Arnold (bug 13744).
1248 * Visually update the revision rating form on change.
@@ -14,325 +50,265 @@
1551 * - Also remove comment box clutter in case of invalid input.
1652 * NOTE: all buttons should exist (perhaps hidden though)
1753 */
18 - 'updateRatingForm': function() {
19 - var ratingform = document.getElementById('mw-fr-ratingselects');
20 - if( !ratingform ) return;
21 - var disabled = document.getElementById('fr-rating-controls-disabled');
22 - if( disabled ) return;
23 -
 54+ 'updateReviewForm': function( form ) {
 55+ if ( form.prop( 'disabled' ) ) {
 56+ return;
 57+ }
 58+
2459 var quality = true;
2560 var somezero = false;
26 -
2761 // Determine if this is a "quality" or "incomplete" review
28 - for( var tag in wgFlaggedRevsParams.tags ) {
29 - var controlName = "wp" + tag;
30 - var levels = document.getElementsByName(controlName);
31 - if( !levels.length ) continue;
32 -
 62+ for ( var tag in wgFlaggedRevsParams.tags ) {
 63+ var levels = form.find( "[name='wp" + tag + "']" ).eq( 0 );
 64+ if ( !levels.length ) continue;
 65+
3366 var selectedlevel = 0; // default
34 - if( levels[0].nodeName == 'SELECT' ) {
35 - selectedlevel = levels[0].selectedIndex;
36 - } else if( levels[0].type == 'radio' ) {
37 - for( var i = 0; i < levels.length; i++ ) {
38 - if( levels[i].checked ) {
 67+ if ( levels.prop( 'nodeName' ) === 'SELECT' ) {
 68+ selectedlevel = levels.prop( 'selectedIndex' );
 69+ } else if ( levelsprop( 'type' ) === 'radio' ) {
 70+ for ( var i = 0; i < levels.length; i++ ) {
 71+ if ( levels.eq( i ).prop( 'checked' ) ) {
3972 selectedlevel = i;
4073 break;
4174 }
4275 }
43 - } else if( levels[0].type == 'checkbox' ) {
44 - selectedlevel = (levels[0].checked) ? 1: 0;
 76+ } else if ( levels.prop( 'type' ) == 'checkbox' ) {
 77+ selectedlevel = levels.prop( 'checked' ) ? 1 : 0;
4578 } else {
4679 return; // error: should not happen
4780 }
48 -
 81+
4982 // Get quality level for this tag
5083 var qualityLevel = wgFlaggedRevsParams.tags[tag]['quality'];
51 -
52 - if( selectedlevel < qualityLevel ) {
 84+ if ( selectedlevel < qualityLevel ) {
5385 quality = false; // not a quality review
5486 }
55 - if( selectedlevel <= 0 ) {
 87+ if ( selectedlevel <= 0 ) {
5688 somezero = true;
5789 }
5890 }
59 -
 91+
6092 // (a) If only a few levels are zero ("incomplete") then disable submission.
6193 // (b) Re-enable submission for already accepted revs when ratings change.
62 - var asubmit = document.getElementById('mw-fr-submit-accept');
63 - if( asubmit ) {
64 - asubmit.disabled = somezero ? 'disabled' : '';
65 - asubmit.value = mediaWiki.msg('revreview-submit-review'); // reset to "Accept"
66 - }
67 -
 94+ $( '#mw-fr-submit-accept' )
 95+ .prop( 'disabled', somezero ? 'disabled' : '' )
 96+ .val( mw.msg( 'revreview-submit-review' ) ); // reset to "Accept"
 97+
6898 // Update colors of <select>
69 - FlaggedRevsReview.updateRatingFormColors( ratingform );
 99+ fr.updateReviewFormColors( form );
70100 },
71 -
 101+
72102 /*
73 - * Update <select> color for the selected item
 103+ * Update <select> color for the selected item/option
74104 */
75 - 'updateRatingFormColors': function() {
76 - for( var tag in wgFlaggedRevsParams.tags ) {
77 - var controlName = "wp" + tag;
78 - var levels = document.getElementsByName(controlName);
79 - if( levels.length && levels[0].nodeName == 'SELECT' ) {
80 - var selectedlevel = levels[0].selectedIndex;
81 - var value = levels[0].getElementsByTagName('option')[selectedlevel].value;
82 - levels[0].className = 'fr-rating-option-' + value;
 105+ 'updateReviewFormColors': function( form ) {
 106+ for ( var tag in wgFlaggedRevsParams.tags ) { // for each tag
 107+ var select = form.find( "[name='wp" + tag + "']" ).eq( 0 );
 108+ // Look for a selector for this tag
 109+ if ( select.length && select.prop( 'nodeName' ) == 'SELECT' ) {
 110+ var selectedlevel = select.prop( 'selectedIndex' );
 111+ var value = select.children( 'option' ).eq( selectedlevel ).val();
 112+ select.prop( 'className', 'fr-rating-option-' + value );
83113 // Fix FF one-time jitter bug of changing an <option>
84 - levels[0].selectedIndex = null;
85 - levels[0].selectedIndex = selectedlevel;
 114+ select.prop( 'selectedIndex', null );
 115+ select.prop( 'selectedIndex', selectedlevel );
86116 }
87117 }
88118 },
89 -
 119+
90120 /*
91 - * Disable 'accept' button if the revision was already reviewed
92 - * NOTE: this is used so that they can be re-enabled if a rating changes
93 - */
94 - 'maybeDisableAcceptButton': function() {
95 - if( typeof(jsReviewNeedsChange) != 'undefined' && jsReviewNeedsChange == 1 ) {
96 - var asubmit = document.getElementById('mw-fr-submit-accept');
97 - if( asubmit ) {
98 - asubmit.disabled = 'disabled';
99 - }
100 - }
101 - },
102 -
103 - /*
104 - * Enable AJAX-based submit functionality to the review form on this page
105 - */
106 - 'enableAjaxReview': function() {
107 - var asubmit = document.getElementById("mw-fr-submit-accept");
108 - if( asubmit ) {
109 - asubmit.onclick = FlaggedRevsReview.submitRevisionReview;
110 - }
111 - var usubmit = document.getElementById("mw-fr-submit-unaccept");
112 - if( usubmit ) {
113 - usubmit.onclick = FlaggedRevsReview.submitRevisionReview;
114 - }
115 - },
116 -
117 - /*
118121 * Lock review form from submissions (using during AJAX requests)
119122 */
120123 'lockReviewForm': function( form ) {
121 - var inputs = form.getElementsByTagName("input");
122 - for( var i=0; i < inputs.length; i++) {
123 - inputs[i].disabled = "disabled";
124 - }
125 - var textareas = document.getElementsByTagName("textarea");
126 - for( var i=0; i < textareas.length; i++) {
127 - textareas[i].disabled = "disabled";
128 - }
129 - var selects = form.getElementsByTagName("select");
130 - for( var i=0; i < selects.length; i++) {
131 - selects[i].disabled = "disabled";
132 - }
 124+ form.find( 'input,textarea,select' ).prop( 'disabled', 'disabled' );
133125 },
134 -
 126+
135127 /*
136128 * Unlock review form from submissions (using after AJAX requests)
137 - */
 129+ */
138130 'unlockReviewForm': function( form ) {
139 - var inputs = form.getElementsByTagName("input");
140 - for( var i=0; i < inputs.length; i++) {
141 - if( inputs[i].type != 'submit' ) { // not all buttons can be enabled
142 - inputs[i].disabled = "";
 131+ var inputs = form.find( 'input' );
 132+ for ( var i=0; i < inputs.length; i++ ) {
 133+ if ( inputs.eq( i ).prop( 'type' ) !== 'submit' ) { // not all buttons can be enabled
 134+ inputs.eq( i ).prop( 'disabled', '' );
143135 } else {
144 - inputs[i].blur(); // focus off element (bug 24013)
 136+ inputs.eq( i ).blur(); // focus off element (bug 24013)
145137 }
146138 }
147 - var textareas = document.getElementsByTagName("textarea");
148 - for( var i=0; i < textareas.length; i++) {
149 - textareas[i].disabled = "";
150 - }
151 - var selects = form.getElementsByTagName("select");
152 - for( var i=0; i < selects.length; i++) {
153 - selects[i].disabled = "";
154 - }
 139+ form.find( 'textarea,select' ).prop( 'disabled', '' );
155140 },
156 -
 141+
157142 /*
158143 * Submit a revision review via AJAX and update form elements.
159144 *
160145 * Note: requestArgs build-up from radios/checkboxes
161146 * based on patch by Daniel Arnold (bug 13744)
162147 */
163 - 'submitRevisionReview': function() {
164 - var form = document.getElementById("mw-fr-reviewform");
165 - if( !form ) {
166 - return true; // do normal behavoir (shouldn't happen)
167 - }
168 - FlaggedRevsReview.lockReviewForm( form ); // disallow submissions
169 -
170 - var notes = document.getElementById("wpNotes");
 148+ 'submitRevisionReview': function( button, form ) {
 149+ fr.lockReviewForm( form ); // disallow submissions
171150 // Build up arguments array and update submit button text...
172151 var requestArgs = []; // array of strings of the format <"pname|pval">.
173 - var inputs = form.getElementsByTagName("input");
174 - for( var i=0; i < inputs.length; i++) {
 152+ var inputs = form.find( 'input' );
 153+ for ( var i=0; i < inputs.length; i++ ) {
 154+ var input = inputs.eq( i );
175155 // Different input types may occur depending on tags...
176 - if( inputs[i].name == "title" || inputs[i].name == "action" ) {
 156+ if ( input.prop( 'name' ) === "title" || input.prop( 'name' ) === "action" ) {
177157 continue; // No need to send these...
178 - } else if( inputs[i].type == "submit" ) {
179 - if( inputs[i].id == this.id ) {
180 - requestArgs.push( inputs[i].name + "|1" );
 158+ } else if ( input.prop( 'type' ) === "submit" ) {
 159+ if ( input.prop( 'id' ) === button.id ) {
 160+ requestArgs.push( input.prop( 'name' ) + "|1" );
181161 // Show that we are submitting via this button
182 - inputs[i].value = mediaWiki.msg('revreview-submitting');
 162+ input.val( mw.msg( 'revreview-submitting' ) );
183163 }
184 - } else if( inputs[i].type == "checkbox" ) {
185 - requestArgs.push( inputs[i].name + "|" +
186 - (inputs[i].checked ? inputs[i].value : 0) );
187 - } else if( inputs[i].type == "radio" ) {
188 - if( inputs[i].checked ) { // must be checked
189 - requestArgs.push( inputs[i].name + "|" + inputs[i].value );
 164+ } else if ( input.prop( 'type' ) === "checkbox" ) {
 165+ requestArgs.push( input.prop( 'name' ) + "|" + // must send a number
 166+ ( input.prop( 'checked' ) ? input.val() : 0 ) );
 167+ } else if ( input.prop( 'type' ) === "radio" ) {
 168+ if ( input.prop( 'checked' ) ) { // must be checked
 169+ requestArgs.push( input.prop( 'name' ) + "|" + input.val() );
190170 }
191171 } else {
192 - requestArgs.push( inputs[i].name + "|" + inputs[i].value ); // text/hiddens...
 172+ requestArgs.push( input.prop( 'name' ) + "|" + input.val() ); // text/hiddens...
193173 }
194174 }
195 - if( notes ) {
196 - requestArgs.push( notes.name + "|" + notes.value );
197 - }
198 - var selects = form.getElementsByTagName("select");
199 - for( var i=0; i < selects.length; i++) {
 175+ var selects = form.find( 'select' );
 176+ for ( var i=0; i < selects.length; i++ ) {
 177+ var select = selects.eq( i );
200178 // Get the selected tag level...
201 - if( selects[i].selectedIndex >= 0 ) {
202 - var soption = selects[i].getElementsByTagName("option")[selects[i].selectedIndex];
203 - requestArgs.push( selects[i].name + "|" + soption.value );
 179+ if ( select.prop( 'selectedIndex' ) >= 0 ) {
 180+ var soption = select.find( 'option' ).eq( select.prop( 'selectedIndex' ) );
 181+ requestArgs.push( select.prop( 'name' ) + "|" + soption.val() );
204182 }
205183 }
206184 // Send encoded function plus all arguments...
207185 var post_data = 'action=ajax&rs=RevisionReview::AjaxReview';
208 - for( var i=0; i<requestArgs.length; i++ ) {
 186+ for ( var i=0; i < requestArgs.length; i++ ) {
209187 post_data += '&rsargs[]=' + encodeURIComponent( requestArgs[i] );
210188 }
211189 // Send POST request via AJAX!
212 - var call = jQuery.ajax({
213 - url : wgScriptPath + '/index.php',
214 - type : "POST",
215 - data : post_data,
216 - dataType: "html", // response type
217 - success : function( response ) {
218 - FlaggedRevsReview.updateReviewForm( form, response ); },
219 - error : function( response ) {
220 - FlaggedRevsReview.unlockReviewForm( form ); }
 190+ var call = $.ajax({
 191+ url : mw.util.wikiScript( 'index' ),
 192+ type : "POST",
 193+ data : post_data,
 194+ dataType : "html", // response type
 195+ success : function( response ) {
 196+ fr.postSubmitRevisionReview( form, response );
 197+ },
 198+ error : function( response ) {
 199+ fr.unlockReviewForm( form );
 200+ }
221201 });
222 - return false; // don't do normal non-AJAX submit
223202 },
224203
225204 /*
226205 * Update form elements after AJAX review.
227206 */
228 - 'updateReviewForm': function( form, response ) {
 207+ 'postSubmitRevisionReview': function( form, response ) {
229208 var msg = response.substr(6); // remove <err#> or <suc#>
230209 // Read new "last change time" timestamp for conflict handling
231210 // @TODO: pass last-chage-time data using JSON or something not retarded
232211 var m = msg.match(/^<lct#(\d*)>(.*)/m);
233 - if( m ) msg = m[2]; // remove tag from msg
 212+ if ( m ) msg = m[2]; // remove tag from msg
234213 var changeTime = m ? m[1] : null; // MW TS
235 - // Some form elements...
236 - var asubmit = document.getElementById('mw-fr-submit-accept');
237 - var usubmit = document.getElementById('mw-fr-submit-unaccept');
238 - var legend = document.getElementById('mw-fr-reviewformlegend');
239 - var diffNotice = document.getElementById('mw-fr-difftostable');
240 - var tagBox = document.getElementById('mw-fr-revisiontag');
 214+
 215+ // Review form elements
 216+ var asubmit = $( '#mw-fr-submit-accept' ); // ACCEPT
 217+ var usubmit = $( '#mw-fr-submit-unaccept' ); // UNACCEPT
 218+ var diffNotice = $( '#mw-fr-difftostable' );
 219+ // FlaggedRevs rating box
 220+ var tagBox = $( '#mw-fr-revisiontag' );
 221+ // Diff parameters
 222+ var diffUIParams = $( '#mw-fr-diff-dataform' );
 223+
241224 // On success...
242 - if( response.indexOf('<suc#>') == 0 ) {
 225+ if ( response.indexOf('<suc#>') === 0 ) {
243226 // (a) Update document title and form buttons...
244 - document.title = mediaWiki.msg('actioncomplete');
245 - if( asubmit && usubmit ) {
 227+ if ( asubmit.length && usubmit.length ) {
246228 // Revision was flagged
247 - if( asubmit.value == mediaWiki.msg('revreview-submitting') ) {
248 - asubmit.value = mediaWiki.msg('revreview-submit-reviewed'); // done!
249 - asubmit.style.fontWeight = 'bold';
 229+ if ( asubmit.val() === mw.msg( 'revreview-submitting' ) ) {
 230+ asubmit.val( mw.msg( 'revreview-submit-reviewed' ) ); // done!
 231+ asubmit.css( 'fontWeight', 'bold' );
250232 // Unlock and reset *unflag* button
251 - usubmit.value = mediaWiki.msg('revreview-submit-unreview');
252 - usubmit.removeAttribute( 'style' ); // back to normal
253 - usubmit.disabled = '';
 233+ usubmit.val( mw.msg( 'revreview-submit-unreview' ) );
 234+ usubmit.css( 'fontWeight', '' ); // back to normal
 235+ usubmit.show(); // now available
 236+ usubmit.prop( 'disabled', '' ); // unlock
254237 // Revision was unflagged
255 - } else if( usubmit.value == mediaWiki.msg('revreview-submitting') ) {
256 - usubmit.value = mediaWiki.msg('revreview-submit-unreviewed'); // done!
257 - usubmit.style.fontWeight = 'bold';
 238+ } else if ( usubmit.val() === mw.msg( 'revreview-submitting' ) ) {
 239+ usubmit.val( mw.msg( 'revreview-submit-unreviewed' ) ); // done!
 240+ usubmit.css( 'fontWeight', 'bold' );
258241 // Unlock and reset *flag* button
259 - asubmit.value = mediaWiki.msg('revreview-submit-review');
260 - asubmit.removeAttribute( 'style' ); // back to normal
261 - asubmit.disabled = '';
 242+ asubmit.val( mw.msg( 'revreview-submit-review' ) );
 243+ asubmit.css( 'fontWeight', '' ); // back to normal
 244+ asubmit.prop( 'disabled', '' ); // unlock
262245 }
263246 }
264247 // (b) Remove review tag from drafts
265 - if( tagBox ) tagBox.style.display = 'none';
 248+ tagBox.css( 'display', 'none' );
266249 // (c) Update diff-related items...
267 - var diffUIParams = document.getElementById('mw-fr-diff-dataform');
268 - if( diffUIParams ) {
 250+ if ( diffUIParams.length ) {
269251 // Hide "review this" box on diffs
270 - if( diffNotice ) diffNotice.style.display = 'none';
 252+ diffNotice.hide();
271253 // Update the contents of the mw-fr-diff-headeritems div
272254 var requestArgs = []; // <oldid, newid>
273 - requestArgs.push( diffUIParams.getElementsByTagName('input')[0].value );
274 - requestArgs.push( diffUIParams.getElementsByTagName('input')[1].value );
 255+ requestArgs.push( diffUIParams.find( 'input' ).eq( 0 ).val() );
 256+ requestArgs.push( diffUIParams.find( 'input' ).eq( 1 ).val() );
275257 // Send encoded function plus all arguments...
276258 var url_pars = '?action=ajax&rs=FlaggablePageView::AjaxBuildDiffHeaderItems';
277 - for( var i=0; i<requestArgs.length; i++ ) {
278 - url_pars += '&rsargs[]=' + encodeURIComponent(requestArgs[i]);
 259+ for ( var i=0; i < requestArgs.length; i++ ) {
 260+ url_pars += '&rsargs[]=' + encodeURIComponent( requestArgs[i] );
279261 }
280262 // Send GET request via AJAX!
281 - var call = jQuery.ajax({
282 - url : wgScriptPath + '/index.php' + url_pars,
283 - type : "GET",
284 - dataType: "html", // response type
285 - success : FlaggedRevsReview.processDiffHeaderItemsResult
 263+ var call = $.ajax({
 264+ url : mw.util.wikiScript( 'index' ) + url_pars,
 265+ type : "GET",
 266+ dataType : "html", // response type
 267+ success : function( response ) {
 268+ // Update the contents of the mw-fr-diff-headeritems div
 269+ $( '#mw-fr-diff-headeritems' ).html( response );
 270+ }
286271 });
287272 }
288273 // On failure...
289274 } else {
290275 // (a) Update document title and form buttons...
291 - document.title = mediaWiki.msg('actionfailed');
292 - if( asubmit && usubmit ) {
 276+ if ( asubmit.length && usubmit.length ) {
293277 // Revision was flagged
294 - if( asubmit.value == mediaWiki.msg('revreview-submitting') ) {
295 - asubmit.value = mediaWiki.msg('revreview-submit-review'); // back to normal
296 - asubmit.disabled = ''; // unlock flag button
 278+ if ( asubmit.val() === mw.msg( 'revreview-submitting' ) ) {
 279+ asubmit.val( mw.msg( 'revreview-submit-review' ) ); // back to normal
 280+ asubmit.prop( 'disabled', '' ); // unlock
297281 // Revision was unflagged
298 - } else if( usubmit.value == mediaWiki.msg('revreview-submitting') ) {
299 - usubmit.value = mediaWiki.msg('revreview-submit-unreview'); // back to normal
300 - usubmit.disabled = ''; // unlock
 282+ } else if ( usubmit.value === mw.msg( 'revreview-submitting' ) ) {
 283+ usubmit.val( mw.msg( 'revreview-submit-unreview' ) ); // back to normal
 284+ usubmit.prop( 'disabled', '' ); // unlock
301285 }
302286 }
303287 // (b) Output any error response message
304 - if( response.indexOf('<err#>') == 0 ) {
 288+ if ( response.indexOf('<err#>') === 0 ) {
305289 mediaWiki.util.jsMessage( msg, 'review' ); // failure notice
306290 } else {
307291 mediaWiki.util.jsMessage( response, 'review' ); // fatal notice
308292 }
309 - window.scroll(0,0); // scroll up to notice
 293+ window.scroll( 0, 0 ); // scroll up to notice
310294 }
311295 // Update changetime for conflict handling
312 - if( changeTime != null ) {
313 - document.getElementById('mw-fr-input-changetime').value = changeTime;
 296+ if ( changeTime != null ) {
 297+ $( '#mw-fr-input-changetime' ).val( changeTime );
314298 }
315 - FlaggedRevsReview.unlockReviewForm( form );
 299+ fr.unlockReviewForm( form );
316300 },
317 -
318 - // update the contents of the mw-fr-diff-headeritems div
319 - 'processDiffHeaderItemsResult': function( response ) {
320 - var diffHeaderItems = document.getElementById("mw-fr-diff-headeritems");
321 - if( diffHeaderItems && response != '' ) {
322 - diffHeaderItems.innerHTML = response;
323 - }
324 - },
325 -
 301+
326302 /*
327303 * Enable AJAX-based functionality to set that a user is reviewing a page/diff
328304 */
329305 'enableAjaxReviewActivity': function() {
330306 // User is already reviewing in another tab...
331 - if ( $('#mw-fr-user-reviewing').val() == 1 ) {
332 - FlaggedRevsReview.isUserReviewing = 1;
333 - FlaggedRevsReview.advertiseReviewing( null, true );
 307+ if ( $('#mw-fr-user-reviewing').val() === 1 ) {
 308+ fr.isUserReviewing = 1;
 309+ fr.advertiseReviewing( null, true );
334310 // User is not already reviewing this....
335311 } else {
336 - FlaggedRevsReview.deadvertiseReviewing( null, true );
 312+ fr.deadvertiseReviewing( null, true );
337313 }
338314 $('#mw-fr-reviewing-status').show();
339315 },
@@ -342,7 +318,7 @@
343319 */
344320 'advertiseReviewing': function( e, isInitial ) {
345321 if ( isInitial !== true ) { // don't send if just setting up form
346 - if ( !FlaggedRevsReview.setReviewingStatus( 1 ) ) {
 322+ if ( !fr.setReviewingStatus( 1 ) ) {
347323 return; // failed
348324 }
349325 }
@@ -360,7 +336,7 @@
361337 { id: 'mw-fr-reviewing-stop' }, mw.msg( 'revreview-adv-stop-link' ) ) + ')' )
362338 .find( '#mw-fr-reviewing-stop')
363339 .css( 'cursor', 'pointer' )
364 - .click( FlaggedRevsReview.deadvertiseReviewing );
 340+ .click( fr.deadvertiseReviewing );
365341 },
366342
367343 /*
@@ -368,7 +344,7 @@
369345 */
370346 'deadvertiseReviewing': function( e, isInitial ) {
371347 if ( isInitial !== true ) { // don't send if just setting up form
372 - if ( !FlaggedRevsReview.setReviewingStatus( 0 ) ) {
 348+ if ( !fr.setReviewingStatus( 0 ) ) {
373349 return; // failed
374350 }
375351 }
@@ -386,7 +362,7 @@
387363 );
388364 $underReview.find( '#mw-fr-reviewing-start')
389365 .css( 'cursor', 'pointer' )
390 - .click( FlaggedRevsReview.advertiseReviewing );
 366+ .click( fr.advertiseReviewing );
391367 // Update notice to say that user is not advertising...
392368 $('#mw-fr-reviewing-status').empty().append( $underReview );
393369 },
@@ -395,32 +371,31 @@
396372 * Set reviewing status for this page/diff
397373 */
398374 'setReviewingStatus': function( value ) {
 375+ var res = false;
399376 // Get {previd,oldid} array for this page view.
400377 // The previd value will be 0 if this is not a diff view.
401378 var oRevId = $('#mw-fr-input-refid') ? $('#mw-fr-input-refid').val() : 0;
402379 var nRevId = $('#mw-fr-input-oldid') ? $('#mw-fr-input-oldid').val() : 0;
403380 if ( nRevId > 0 ) {
404381 // Send GET request via AJAX!
405 - var call = jQuery.ajax({
406 - url : wgScriptPath + '/api.php',
407 - data : {
408 - action : 'reviewactivity',
409 - previd : oRevId,
410 - oldid : nRevId,
411 - reviewing : value,
412 - token : mw.user.tokens.get('editToken'),
413 - format : 'json'
 382+ var call = $.ajax({
 383+ url : mw.util.wikiScript( 'api' ),
 384+ data : {
 385+ action : 'reviewactivity',
 386+ previd : oRevId,
 387+ oldid : nRevId,
 388+ reviewing : value,
 389+ token : mw.user.tokens.get('editToken'),
 390+ format : 'json'
414391 },
415 - type : "POST",
416 - dataType: "html", // response type
417 - timeout : 1700, // don't delay user exiting
418 - async : false
 392+ type : "POST",
 393+ dataType : "json", // response type
 394+ timeout : 1700, // don't delay user exiting
 395+ success : function( data ) { res = data; },
 396+ async : false
419397 });
420 - }
421 - if ( call.status == 200 ) {
422 - var s = jQuery.parseJSON( call.responseText );
423 - if ( s && s.reviewactivity && s.reviewactivity.result == "Success" ) {
424 - FlaggedRevsReview.isUserReviewing = value;
 398+ if ( res && res.reviewactivity && res.reviewactivity.result === "Success" ) {
 399+ fr.isUserReviewing = value;
425400 return true;
426401 }
427402 }
@@ -429,14 +404,6 @@
430405 };
431406
432407 // Perform some onload (which is when this script is included) events:
433 -FlaggedRevsReview.maybeDisableAcceptButton();
434 -FlaggedRevsReview.updateRatingFormColors();
435 -FlaggedRevsReview.enableAjaxReview();
436 -FlaggedRevsReview.enableAjaxReviewActivity();
 408+fr.init();
437409
438 -// Flag users as "no longer reviewing" on navigate-away
439 -$( window ).bind( 'beforeunload', function( e ) {
440 - if ( FlaggedRevsReview.isUserReviewing == 1 ) {
441 - FlaggedRevsReview.deadvertiseReviewing();
442 - }
443 -} );
 410+})( jQuery );

Sign-offs

UserFlagDate
😂inspected03:45, 8 March 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r101289Fixed a couple of random JS bugs, particulary one that broke the form when ra...aaron22:05, 29 October 2011

Status & tagging log