Index: trunk/extensions/FlaggedRevs/presentation/RevisionReviewFormUI.php |
— | — | @@ -305,8 +305,7 @@ |
306 | 306 | # If the sum of qualities of all flags is above 6, use drop down boxes. |
307 | 307 | # 6 is an arbitrary value choosen according to screen space and usability. |
308 | 308 | 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" ); |
311 | 310 | $item .= Xml::openElement( 'select', $attribs ) . "\n"; |
312 | 311 | foreach ( $levels as $i => $name ) { |
313 | 312 | $optionClass = array( 'class' => "fr-rating-option-$i" ); |
— | — | @@ -317,16 +316,14 @@ |
318 | 317 | # If there are more than two levels, current user gets radio buttons |
319 | 318 | } elseif ( $numLevels > 2 ) { |
320 | 319 | 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" ); |
323 | 321 | $item .= Xml::radioLabel( FlaggedRevs::getTagMsg( $name ), "wp$quality", |
324 | 322 | $i, "wp$quality" . $i, ( $i == $selected ), $attribs ) . "\n"; |
325 | 323 | } |
326 | 324 | # Otherwise make checkboxes (two levels available for current user) |
327 | 325 | } elseif ( $numLevels == 2 ) { |
328 | 326 | $i = $minLevel; |
329 | | - $attribs = array( 'class' => "fr-rating-option-$i", |
330 | | - 'onchange' => "FlaggedRevsReview.updateRatingForm()" ); |
| 327 | + $attribs = array( 'class' => "fr-rating-option-$i" ); |
331 | 328 | $attribs = $attribs + array( 'value' => $i ); |
332 | 329 | $item .= Xml::checkLabel( wfMsg( 'revreview-' . $levels[$i] ), |
333 | 330 | "wp$quality", "wp$quality", ( $selected == $i ), $attribs ) . "\n"; |
Index: trunk/extensions/FlaggedRevs/presentation/modules/ext.flaggedRevs.review.js |
— | — | @@ -3,9 +3,45 @@ |
4 | 4 | * @author Aaron Schulz |
5 | 5 | * @author Daniel Arnold 2008 |
6 | 6 | */ |
| 7 | +( function( $ ) { |
7 | 8 | |
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 | + |
10 | 46 | /* |
11 | 47 | * Updates for radios/checkboxes on patch by Daniel Arnold (bug 13744). |
12 | 48 | * Visually update the revision rating form on change. |
— | — | @@ -14,325 +50,265 @@ |
15 | 51 | * - Also remove comment box clutter in case of invalid input. |
16 | 52 | * NOTE: all buttons should exist (perhaps hidden though) |
17 | 53 | */ |
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 | + |
24 | 59 | var quality = true; |
25 | 60 | var somezero = false; |
26 | | - |
27 | 61 | // 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 | + |
33 | 66 | 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' ) ) { |
39 | 72 | selectedlevel = i; |
40 | 73 | break; |
41 | 74 | } |
42 | 75 | } |
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; |
45 | 78 | } else { |
46 | 79 | return; // error: should not happen |
47 | 80 | } |
48 | | - |
| 81 | + |
49 | 82 | // Get quality level for this tag |
50 | 83 | var qualityLevel = wgFlaggedRevsParams.tags[tag]['quality']; |
51 | | - |
52 | | - if( selectedlevel < qualityLevel ) { |
| 84 | + if ( selectedlevel < qualityLevel ) { |
53 | 85 | quality = false; // not a quality review |
54 | 86 | } |
55 | | - if( selectedlevel <= 0 ) { |
| 87 | + if ( selectedlevel <= 0 ) { |
56 | 88 | somezero = true; |
57 | 89 | } |
58 | 90 | } |
59 | | - |
| 91 | + |
60 | 92 | // (a) If only a few levels are zero ("incomplete") then disable submission. |
61 | 93 | // (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 | + |
68 | 98 | // Update colors of <select> |
69 | | - FlaggedRevsReview.updateRatingFormColors( ratingform ); |
| 99 | + fr.updateReviewFormColors( form ); |
70 | 100 | }, |
71 | | - |
| 101 | + |
72 | 102 | /* |
73 | | - * Update <select> color for the selected item |
| 103 | + * Update <select> color for the selected item/option |
74 | 104 | */ |
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 ); |
83 | 113 | // 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 ); |
86 | 116 | } |
87 | 117 | } |
88 | 118 | }, |
89 | | - |
| 119 | + |
90 | 120 | /* |
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 | | - /* |
118 | 121 | * Lock review form from submissions (using during AJAX requests) |
119 | 122 | */ |
120 | 123 | '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' ); |
133 | 125 | }, |
134 | | - |
| 126 | + |
135 | 127 | /* |
136 | 128 | * Unlock review form from submissions (using after AJAX requests) |
137 | | - */ |
| 129 | + */ |
138 | 130 | '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', '' ); |
143 | 135 | } else { |
144 | | - inputs[i].blur(); // focus off element (bug 24013) |
| 136 | + inputs.eq( i ).blur(); // focus off element (bug 24013) |
145 | 137 | } |
146 | 138 | } |
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', '' ); |
155 | 140 | }, |
156 | | - |
| 141 | + |
157 | 142 | /* |
158 | 143 | * Submit a revision review via AJAX and update form elements. |
159 | 144 | * |
160 | 145 | * Note: requestArgs build-up from radios/checkboxes |
161 | 146 | * based on patch by Daniel Arnold (bug 13744) |
162 | 147 | */ |
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 |
171 | 150 | // Build up arguments array and update submit button text... |
172 | 151 | 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 ); |
175 | 155 | // 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" ) { |
177 | 157 | 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" ); |
181 | 161 | // Show that we are submitting via this button |
182 | | - inputs[i].value = mediaWiki.msg('revreview-submitting'); |
| 162 | + input.val( mw.msg( 'revreview-submitting' ) ); |
183 | 163 | } |
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() ); |
190 | 170 | } |
191 | 171 | } else { |
192 | | - requestArgs.push( inputs[i].name + "|" + inputs[i].value ); // text/hiddens... |
| 172 | + requestArgs.push( input.prop( 'name' ) + "|" + input.val() ); // text/hiddens... |
193 | 173 | } |
194 | 174 | } |
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 ); |
200 | 178 | // 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() ); |
204 | 182 | } |
205 | 183 | } |
206 | 184 | // Send encoded function plus all arguments... |
207 | 185 | 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++ ) { |
209 | 187 | post_data += '&rsargs[]=' + encodeURIComponent( requestArgs[i] ); |
210 | 188 | } |
211 | 189 | // 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 | + } |
221 | 201 | }); |
222 | | - return false; // don't do normal non-AJAX submit |
223 | 202 | }, |
224 | 203 | |
225 | 204 | /* |
226 | 205 | * Update form elements after AJAX review. |
227 | 206 | */ |
228 | | - 'updateReviewForm': function( form, response ) { |
| 207 | + 'postSubmitRevisionReview': function( form, response ) { |
229 | 208 | var msg = response.substr(6); // remove <err#> or <suc#> |
230 | 209 | // Read new "last change time" timestamp for conflict handling |
231 | 210 | // @TODO: pass last-chage-time data using JSON or something not retarded |
232 | 211 | 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 |
234 | 213 | 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 | + |
241 | 224 | // On success... |
242 | | - if( response.indexOf('<suc#>') == 0 ) { |
| 225 | + if ( response.indexOf('<suc#>') === 0 ) { |
243 | 226 | // (a) Update document title and form buttons... |
244 | | - document.title = mediaWiki.msg('actioncomplete'); |
245 | | - if( asubmit && usubmit ) { |
| 227 | + if ( asubmit.length && usubmit.length ) { |
246 | 228 | // 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' ); |
250 | 232 | // 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 |
254 | 237 | // 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' ); |
258 | 241 | // 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 |
262 | 245 | } |
263 | 246 | } |
264 | 247 | // (b) Remove review tag from drafts |
265 | | - if( tagBox ) tagBox.style.display = 'none'; |
| 248 | + tagBox.css( 'display', 'none' ); |
266 | 249 | // (c) Update diff-related items... |
267 | | - var diffUIParams = document.getElementById('mw-fr-diff-dataform'); |
268 | | - if( diffUIParams ) { |
| 250 | + if ( diffUIParams.length ) { |
269 | 251 | // Hide "review this" box on diffs |
270 | | - if( diffNotice ) diffNotice.style.display = 'none'; |
| 252 | + diffNotice.hide(); |
271 | 253 | // Update the contents of the mw-fr-diff-headeritems div |
272 | 254 | 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() ); |
275 | 257 | // Send encoded function plus all arguments... |
276 | 258 | 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] ); |
279 | 261 | } |
280 | 262 | // 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 | + } |
286 | 271 | }); |
287 | 272 | } |
288 | 273 | // On failure... |
289 | 274 | } else { |
290 | 275 | // (a) Update document title and form buttons... |
291 | | - document.title = mediaWiki.msg('actionfailed'); |
292 | | - if( asubmit && usubmit ) { |
| 276 | + if ( asubmit.length && usubmit.length ) { |
293 | 277 | // 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 |
297 | 281 | // 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 |
301 | 285 | } |
302 | 286 | } |
303 | 287 | // (b) Output any error response message |
304 | | - if( response.indexOf('<err#>') == 0 ) { |
| 288 | + if ( response.indexOf('<err#>') === 0 ) { |
305 | 289 | mediaWiki.util.jsMessage( msg, 'review' ); // failure notice |
306 | 290 | } else { |
307 | 291 | mediaWiki.util.jsMessage( response, 'review' ); // fatal notice |
308 | 292 | } |
309 | | - window.scroll(0,0); // scroll up to notice |
| 293 | + window.scroll( 0, 0 ); // scroll up to notice |
310 | 294 | } |
311 | 295 | // 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 ); |
314 | 298 | } |
315 | | - FlaggedRevsReview.unlockReviewForm( form ); |
| 299 | + fr.unlockReviewForm( form ); |
316 | 300 | }, |
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 | + |
326 | 302 | /* |
327 | 303 | * Enable AJAX-based functionality to set that a user is reviewing a page/diff |
328 | 304 | */ |
329 | 305 | 'enableAjaxReviewActivity': function() { |
330 | 306 | // 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 ); |
334 | 310 | // User is not already reviewing this.... |
335 | 311 | } else { |
336 | | - FlaggedRevsReview.deadvertiseReviewing( null, true ); |
| 312 | + fr.deadvertiseReviewing( null, true ); |
337 | 313 | } |
338 | 314 | $('#mw-fr-reviewing-status').show(); |
339 | 315 | }, |
— | — | @@ -342,7 +318,7 @@ |
343 | 319 | */ |
344 | 320 | 'advertiseReviewing': function( e, isInitial ) { |
345 | 321 | if ( isInitial !== true ) { // don't send if just setting up form |
346 | | - if ( !FlaggedRevsReview.setReviewingStatus( 1 ) ) { |
| 322 | + if ( !fr.setReviewingStatus( 1 ) ) { |
347 | 323 | return; // failed |
348 | 324 | } |
349 | 325 | } |
— | — | @@ -360,7 +336,7 @@ |
361 | 337 | { id: 'mw-fr-reviewing-stop' }, mw.msg( 'revreview-adv-stop-link' ) ) + ')' ) |
362 | 338 | .find( '#mw-fr-reviewing-stop') |
363 | 339 | .css( 'cursor', 'pointer' ) |
364 | | - .click( FlaggedRevsReview.deadvertiseReviewing ); |
| 340 | + .click( fr.deadvertiseReviewing ); |
365 | 341 | }, |
366 | 342 | |
367 | 343 | /* |
— | — | @@ -368,7 +344,7 @@ |
369 | 345 | */ |
370 | 346 | 'deadvertiseReviewing': function( e, isInitial ) { |
371 | 347 | if ( isInitial !== true ) { // don't send if just setting up form |
372 | | - if ( !FlaggedRevsReview.setReviewingStatus( 0 ) ) { |
| 348 | + if ( !fr.setReviewingStatus( 0 ) ) { |
373 | 349 | return; // failed |
374 | 350 | } |
375 | 351 | } |
— | — | @@ -386,7 +362,7 @@ |
387 | 363 | ); |
388 | 364 | $underReview.find( '#mw-fr-reviewing-start') |
389 | 365 | .css( 'cursor', 'pointer' ) |
390 | | - .click( FlaggedRevsReview.advertiseReviewing ); |
| 366 | + .click( fr.advertiseReviewing ); |
391 | 367 | // Update notice to say that user is not advertising... |
392 | 368 | $('#mw-fr-reviewing-status').empty().append( $underReview ); |
393 | 369 | }, |
— | — | @@ -395,32 +371,31 @@ |
396 | 372 | * Set reviewing status for this page/diff |
397 | 373 | */ |
398 | 374 | 'setReviewingStatus': function( value ) { |
| 375 | + var res = false; |
399 | 376 | // Get {previd,oldid} array for this page view. |
400 | 377 | // The previd value will be 0 if this is not a diff view. |
401 | 378 | var oRevId = $('#mw-fr-input-refid') ? $('#mw-fr-input-refid').val() : 0; |
402 | 379 | var nRevId = $('#mw-fr-input-oldid') ? $('#mw-fr-input-oldid').val() : 0; |
403 | 380 | if ( nRevId > 0 ) { |
404 | 381 | // 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' |
414 | 391 | }, |
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 |
419 | 397 | }); |
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; |
425 | 400 | return true; |
426 | 401 | } |
427 | 402 | } |
— | — | @@ -429,14 +404,6 @@ |
430 | 405 | }; |
431 | 406 | |
432 | 407 | // 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(); |
437 | 409 | |
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 ); |