r60168 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60167‎ | r60168 | r60169 >
Date:17:15, 17 December 2009
Author:aaron
Status:ok
Tags:
Comment:
Made JS more OOP/reduce change of name collisions
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsXML.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/flaggedrevs.js (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -291,7 +291,7 @@
292292 $wgAvailableRights[] = 'stablesettings';
293293
294294 # Bump this number every time you change flaggedrevs.css/flaggedrevs.js
295 -$wgFlaggedRevStyleVersion = 61;
 295+$wgFlaggedRevStyleVersion = 62;
296296
297297 $wgExtensionFunctions[] = 'efLoadFlaggedRevs';
298298
Index: trunk/extensions/FlaggedRevs/FlaggedRevsXML.php
@@ -240,7 +240,8 @@
241241
242242 public static function ratingToggle() {
243243 return "<a id='mw-revisiontoggle' class='flaggedrevs_toggle' style='display:none;'" .
244 - " onclick='toggleRevRatings()' title='" . wfMsgHtml('revreview-toggle-title') . "' >" .
 244+ " onclick='FlaggedRevs.toggleRevRatings()' title='" .
 245+ wfMsgHtml('revreview-toggle-title') . "' >" .
245246 wfMsg( 'revreview-toggle' ) . "</a>";
246247 }
247248
@@ -286,7 +287,7 @@
287288 # 6 is an arbitrary value choosen according to screen space and usability
288289 if( $size > 6 ) {
289290 $attribs = array( 'name' => "wp$quality", 'id' => "wp$quality",
290 - 'onchange' => "updateRatingForm()" ) + $toggle;
 291+ 'onchange' => "FlaggedRevs.updateRatingForm()" ) + $toggle;
291292 $form .= Xml::openElement( 'select', $attribs );
292293 foreach( $label as $i => $name ) {
293294 $optionClass = array( 'class' => "fr-rating-option-$i" );
@@ -298,7 +299,7 @@
299300 } elseif( $numLevels > 2 ) {
300301 foreach( $label as $i => $name ) {
301302 $attribs = array( 'class' => "fr-rating-option-$i",
302 - 'onchange' => "updateRatingForm()" );
 303+ 'onchange' => "FlaggedRevs.updateRatingForm()" );
303304 $form .= Xml::radioLabel( FlaggedRevs::getTagMsg($name), "wp$quality", $i,
304305 "wp$quality".$i, ($i == $selected), $attribs ) . "\n";
305306 }
@@ -307,7 +308,7 @@
308309 # If disable, use the current flags; if none, then use the min flag.
309310 $i = $disabled ? $selected : $minLevel;
310311 $attribs = array( 'class' => "fr-rating-option-$i",
311 - 'onchange' => "updateRatingForm()" );
 312+ 'onchange' => "FlaggedRevs.updateRatingForm()" );
312313 $attribs = $attribs + $toggle + array('value' => $minLevel);
313314 $form .= Xml::checkLabel( wfMsg( "revreview-{$label[$i]}" ), "wp$quality",
314315 "wp$quality", ($selected == $i), $attribs ) . "\n";
Index: trunk/extensions/FlaggedRevs/flaggedrevs.js
@@ -2,97 +2,99 @@
33
44 /* Every time you change this JS please bump $wgFlaggedRevStyleVersion in FlaggedRevs.php */
55
6 -/* Hide rating clutter */
7 -function enable_showhide() {
8 - var toggle = document.getElementById('mw-revisiontoggle');
9 - if( !toggle ) return;
10 - toggle.style.display = 'inline';
11 - var ratings = document.getElementById('mw-revisionratings');
12 - if( !ratings ) return;
13 - ratings.style.display = 'none';
14 -}
15 -
16 -/* Toggles ratings */
17 -function toggleRevRatings() {
18 - var ratings = document.getElementById('mw-revisionratings');
19 - if( !ratings ) return;
20 - if( ratings.style.display == 'none' ) {
21 - ratings.style.display = 'inline';
22 - } else {
 6+var FlaggedRevs = {
 7+ /* Hide rating clutter */
 8+ 'enableShowhide': function() {
 9+ var toggle = document.getElementById('mw-revisiontoggle');
 10+ if( !toggle ) return;
 11+ toggle.style.display = 'inline';
 12+ var ratings = document.getElementById('mw-revisionratings');
 13+ if( !ratings ) return;
2314 ratings.style.display = 'none';
24 - }
25 -}
26 -
27 -/*
28 -* a) Disable submit in case of invalid input.
29 -* b) Update colors when select changes (Opera already does this).
30 -* c) Also remove comment box clutter in case of invalid input.
31 -*/
32 -function updateRatingForm() {
33 - var ratingform = document.getElementById('mw-ratingselects');
34 - if( !ratingform ) return;
35 - var disabled = document.getElementById('fr-rating-controls-disabled');
36 - if( disabled ) return;
37 -
38 - var quality = true;
39 - var allzero = true;
40 - var somezero = false;
41 -
42 - for( tag in wgFlaggedRevsParams.tags ) {
43 - var controlName = "wp" + tag;
44 - var levels = document.getElementsByName(controlName);
45 - var selectedlevel = 0; // default
46 -
47 - if( levels[0].nodeName == 'SELECT' ) {
48 - selectedlevel = levels[0].selectedIndex;
49 - // Update color. Opera does this already, and doing so
50 - // seems to kill custom pretty opera skin form styling.
51 - if( navigator.appName != 'Opera') {
52 - value = levels[0].getElementsByTagName('option')[selectedlevel].value;
53 - levels[0].className = 'fr-rating-option-' + value;
54 - }
55 - } else if( levels[0].type == 'radio' ) {
56 - for( i = 0; i < levels.length; i++ ) {
57 - if( levels[i].checked ) {
58 - selectedlevel = i;
59 - break;
 15+ },
 16+
 17+ /* Toggles ratings */
 18+ 'toggleRevRatings': function() {
 19+ var ratings = document.getElementById('mw-revisionratings');
 20+ if( !ratings ) return;
 21+ if( ratings.style.display == 'none' ) {
 22+ ratings.style.display = 'inline';
 23+ } else {
 24+ ratings.style.display = 'none';
 25+ }
 26+ },
 27+
 28+ /*
 29+ * a) Disable submit in case of invalid input.
 30+ * b) Update colors when select changes (Opera already does this).
 31+ * c) Also remove comment box clutter in case of invalid input.
 32+ */
 33+ 'updateRatingForm': function() {
 34+ var ratingform = document.getElementById('mw-ratingselects');
 35+ if( !ratingform ) return;
 36+ var disabled = document.getElementById('fr-rating-controls-disabled');
 37+ if( disabled ) return;
 38+
 39+ var quality = true;
 40+ var allzero = true;
 41+ var somezero = false;
 42+
 43+ for( tag in wgFlaggedRevsParams.tags ) {
 44+ var controlName = "wp" + tag;
 45+ var levels = document.getElementsByName(controlName);
 46+ var selectedlevel = 0; // default
 47+
 48+ if( levels[0].nodeName == 'SELECT' ) {
 49+ selectedlevel = levels[0].selectedIndex;
 50+ // Update color. Opera does this already, and doing so
 51+ // seems to kill custom pretty opera skin form styling.
 52+ if( navigator.appName != 'Opera') {
 53+ value = levels[0].getElementsByTagName('option')[selectedlevel].value;
 54+ levels[0].className = 'fr-rating-option-' + value;
6055 }
 56+ } else if( levels[0].type == 'radio' ) {
 57+ for( i = 0; i < levels.length; i++ ) {
 58+ if( levels[i].checked ) {
 59+ selectedlevel = i;
 60+ break;
 61+ }
 62+ }
 63+ } else if( levels[0].type == 'checkbox' ) {
 64+ selectedlevel = (levels[0].checked) ? 1: 0;
 65+ } else {
 66+ return; // error: should not happen
6167 }
62 - } else if( levels[0].type == 'checkbox' ) {
63 - selectedlevel = (levels[0].checked) ? 1: 0;
64 - } else {
65 - return; // error: should not happen
 68+
 69+ // Get quality level for this tag
 70+ qualityLevel = wgFlaggedRevsParams.tags[tag];
 71+
 72+ if( selectedlevel < qualityLevel ) {
 73+ quality = false; // not a quality review
 74+ }
 75+ if( selectedlevel > 0 ) {
 76+ allzero = false;
 77+ } else {
 78+ somezero = true;
 79+ }
6680 }
67 -
68 - // Get quality level for this tag
69 - qualityLevel = wgFlaggedRevsParams.tags[tag];
70 -
71 - if( selectedlevel < qualityLevel ) {
72 - quality = false; // not a quality review
 81+ // Show note box only for quality revs
 82+ var notebox = document.getElementById('mw-notebox');
 83+ if( notebox ) {
 84+ notebox.style.display = quality ? 'inline' : 'none';
7385 }
74 - if( selectedlevel > 0 ) {
75 - allzero = false;
76 - } else {
77 - somezero = true;
 86+ // If only a few levels are zero, don't show submit link
 87+ var submit = document.getElementById('submitreview');
 88+ submit.disabled = ( somezero && !allzero ) ? 'disabled' : '';
 89+ // Clear note box data if not shown
 90+ var notes = document.getElementById('wpNotes');
 91+ if( notes ) {
 92+ notes.value = quality ? notes.value : '';
7893 }
7994 }
80 - // Show note box only for quality revs
81 - var notebox = document.getElementById('mw-notebox');
82 - if( notebox ) {
83 - notebox.style.display = quality ? 'inline' : 'none';
84 - }
85 - // If only a few levels are zero, don't show submit link
86 - var submit = document.getElementById('submitreview');
87 - submit.disabled = ( somezero && !allzero ) ? 'disabled' : '';
88 - // Clear note box data if not shown
89 - var notes = document.getElementById('wpNotes');
90 - if( notes ) {
91 - notes.value = quality ? notes.value : '';
92 - }
93 -}
 95+};
9496
95 -addOnloadHook(enable_showhide);
96 -addOnloadHook(updateRatingForm);
 97+addOnloadHook(FlaggedRevs.enableShowhide);
 98+addOnloadHook(FlaggedRevs.updateRatingForm);
9799
98100 // dependencies:
99101 // * ajax.js:
@@ -199,6 +201,7 @@
200202 for( var i=0; i < selects.length; i++) {
201203 selects[i].disabled = "";
202204 }
 205+ return true;
203206 };
204207
205208 wgAjaxReview.processResult = function(request) {
@@ -206,7 +209,7 @@
207210 return;
208211 }
209212 var response = request.responseText;
210 - if( msg = response.substr(6) ) {
 213+ if( (msg = response.substr(6)) ) {
211214 jsMsg( msg, 'review' ); // success notice
212215 window.scroll(0,0); // scroll up to notice
213216 tagBox = document.getElementById('mw-revisiontag');

Status & tagging log