r44491 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44490‎ | r44491 | r44492 >
Date:03:48, 12 December 2008
Author:aaron
Status:deferred
Tags:
Comment:
* Allow partial reviews
* Remove 'overall' aggregate (some issues with it)
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsXML.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/flaggedrevs.js (modified) (history)
  • /trunk/extensions/FlaggedRevs/language/FlaggedRevs.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/LikedPages_body.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/ProblemPages_body.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/ReaderFeedback_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -262,7 +262,7 @@
263263 #########
264264
265265 # Bump this number every time you change flaggedrevs.css/flaggedrevs.js
266 -$wgFlaggedRevStyleVersion = 45;
 266+$wgFlaggedRevStyleVersion = 46;
267267
268268 $wgExtensionFunctions[] = 'efLoadFlaggedRevs';
269269
Index: trunk/extensions/FlaggedRevs/language/FlaggedRevs.i18n.php
@@ -174,7 +174,7 @@
175175 'readerfeedback-npov' => 'Neutrality',
176176 'readerfeedback-presentation' => 'Presentation',
177177 'readerfeedback-overall' => 'Overall',
178 - 'readerfeedback-level-none' => '(select)',
 178+ 'readerfeedback-level-none' => '(unsure)',
179179 'readerfeedback-level-0' => 'Poor',
180180 'readerfeedback-level-1' => 'Low',
181181 'readerfeedback-level-2' => 'Fair',
Index: trunk/extensions/FlaggedRevs/specialpages/ProblemPages_body.php
@@ -55,8 +55,9 @@
5656
5757 protected function showPageList() {
5858 global $wgOut;
 59+ $tags = FlaggedRevs::getFeedbackTags();
5960 $pager = new ProblemPagesPager( $this, array(), $this->namespace, $this->tag );
60 - if( $pager->getNumRows() ) {
 61+ if( isset($tags[$this->tag]) && $pager->getNumRows() ) {
6162 $wgOut->addHTML( wfMsgExt('problempages-list', array('parse') ) );
6263 $wgOut->addHTML( $pager->getNavigationBar() );
6364 $wgOut->addHTML( $pager->getBody() );
@@ -118,11 +119,6 @@
119120 $conds['page_namespace'] = $this->namespace;
120121 // Has to be bad enough
121122 $x = 2;
122 - if( $this->tag == 'overall' ) {
123 - global $wgFlaggedRevsFeedbackTags;
124 - $s = $x*array_sum($wgFlaggedRevsFeedbackTags);
125 - $x = intval( floor($s/count($wgFlaggedRevsFeedbackTags)) );
126 - }
127123 $conds[] = "rfp_ave_val < $x";
128124 // Reasonable sample
129125 $conds[] = 'rfp_count >= '.READER_FEEDBACK_SIZE;
Index: trunk/extensions/FlaggedRevs/specialpages/ReaderFeedback_body.php
@@ -49,13 +49,21 @@
5050 }
5151 # Get our rating dimensions
5252 $this->dims = array();
 53+ $unsureCount = 0;
5354 foreach( FlaggedRevs::getFeedbackTags() as $tag => $weight ) {
5455 $this->dims[$tag] = $wgRequest->getIntOrNull( "wp$tag" );
55 - if( !self::isValid($this->dims[$tag]) ) {
 56+ if( $this->dims[$tag] === NULL ) { // nothing sent at all :(
5657 $wgOut->redirect( $this->page->getLocalUrl() );
5758 return;
 59+ } else if( $this->dims[$tags] === -1 ) {
 60+ $unsureCount++;
5861 }
5962 }
 63+ # There must actually be *some* ratings
 64+ if( $unsureCount >= count($this->dims) ) {
 65+ $wgOut->redirect( $this->page->getLocalUrl() );
 66+ return;
 67+ }
6068 # Check validation key
6169 $this->validatedParams = $wgRequest->getVal('validatedParams');
6270 if( $this->validatedParams != self::validationKey( $this->oldid, $wgUser->getId() ) ) {
@@ -96,6 +104,7 @@
97105 // Make review interface object
98106 $form = new ReaderFeedback();
99107 $form->dims = array();
 108+ $unsureCount = 0;
100109 $bot = false;
101110 // Each ajax url argument is of the form param|val.
102111 // This means that there is no ugly order dependance.
@@ -135,15 +144,17 @@
136145 $p = preg_replace( '/^wp/', '', $par ); // kill any "wp" prefix
137146 if( array_key_exists( $p, $tags ) ) {
138147 $form->dims[$p] = intval($val);
139 - if( !self::isValid( $form->dims[$p] ) ) {
 148+ if( $form->dims[$p] === NULL ) { // nothing sent at all :(
140149 return '<err#>' . wfMsg('formerror'); // bad range
 150+ } else if( $form->dims[$p] === -1 ) {
 151+ $unsureCount++;
141152 }
142153 }
143154 break;
144155 }
145156 }
146157 // Missing params?
147 - if( count($form->dims) != count($tags) ) {
 158+ if( count($form->dims) != count($tags) || $unsureCount >= count($form->dims) ) {
148159 return '<err#>' . wfMsg('formerror');
149160 }
150161 // Doesn't match up?
@@ -240,6 +251,8 @@
241252 $dbw = wfGetDB( DB_MASTER );
242253 # Get date timestamp...
243254 $date = str_pad( substr( wfTimestampNow(), 0, 8 ), 14, '0' );
 255+ if( count($this->dims) == 0 )
 256+ return false;
244257 $ratings = $this->flattenRatings( $this->dims );
245258 # Make sure revision is valid!
246259 $rev = Revision::newFromId( $this->oldid );
@@ -259,10 +272,10 @@
260273 'rfb_timestamp' => $dbw->timestamp(),
261274 'rfb_ratings' => $ratings
262275 );
263 - $dbw->insert( 'reader_feedback', $insertRow, __METHOD__, 'IGNORE' );
264276 # Make sure initial page data is there to begin with...
265277 $insertRows = array();
266278 foreach( $this->dims as $tag => $val ) {
 279+ if( $val < 0 ); // don't store "unsure" votes
267280 $insertRows[] = array(
268281 'rfh_page_id' => $rev->getPage(),
269282 'rfh_tag' => $tag,
@@ -271,19 +284,23 @@
272285 'rfh_date' => $date
273286 );
274287 }
 288+ $dbw->insert( 'reader_feedback', $insertRow, __METHOD__, 'IGNORE' );
275289 $dbw->insert( 'reader_feedback_history', $insertRows, __METHOD__, 'IGNORE' );
276290 # Update aggregate data for this page over time...
277291 $touched = $dbw->timestamp( wfTimestampNow() );
278292 $overall = 0;
279293 $insertRows = array();
280294 foreach( $this->dims as $tag => $val ) {
 295+ if( $val < 0 ) continue; // don't store "unsure" votes
 296+ # Update daily averages
281297 $dbw->update( 'reader_feedback_history',
282298 array( 'rfh_total = rfh_total + '.intval($val),
283299 'rfh_count = rfh_count + 1'),
284300 array( 'rfh_page_id' => $rev->getPage(),
285301 'rfh_tag' => $tag,
286302 'rfh_date' => $date ),
287 - __METHOD__ );
 303+ __METHOD__
 304+ );
288305 # Get effective tag values for this page..
289306 list($aveVal,$n) = FlaggedRevs::getAverageRating( $article, $tag, true );
290307 $insertRows[] = array(
@@ -293,19 +310,12 @@
294311 'rfp_count' => $n,
295312 'rfp_touched' => $touched
296313 );
297 - $overall += FlaggedRevs::getFeedbackWeight( $tag ) * $aveVal;
298314 }
299 - # Get overall data for this page. Used to rank best/worst pages...
300 - if( isset($n) ) {
301 - $insertRows[] = array(
302 - 'rfp_page_id' => $rev->getPage(),
303 - 'rfp_tag' => 'overall',
304 - 'rfp_ave_val' => ($overall / count($this->dims)),
305 - 'rfp_count' => $n,
306 - 'rfp_touched' => $touched
307 - );
308 - }
 315+ # Update recent averages
309316 $dbw->replace( 'reader_feedback_pages', array( 'PRIMARY' ), $insertRows, __METHOD__ );
 317+ # Clear out any dead data
 318+ $dbw->delete( 'reader_feedback_pages', array('rfp_page_id' => $rev->getPage(),
 319+ 'rfp_tag' => 'overall'), __METHOD__ );
310320 # For logged in users, box should disappear
311321 if( $wgUser->getId() ) {
312322 $this->page->invalidateCache();
Index: trunk/extensions/FlaggedRevs/specialpages/LikedPages_body.php
@@ -55,8 +55,9 @@
5656
5757 protected function showPageList() {
5858 global $wgOut;
 59+ $tags = FlaggedRevs::getFeedbackTags();
5960 $pager = new LikedPagesPager( $this, array(), $this->namespace, $this->tag );
60 - if( $pager->getNumRows() ) {
 61+ if( isset($tags[$this->tag]) && $pager->getNumRows() ) {
6162 $wgOut->addHTML( wfMsgExt('likedpages-list', array('parse') ) );
6263 $wgOut->addHTML( $pager->getNavigationBar() );
6364 $wgOut->addHTML( $pager->getBody() );
@@ -118,11 +119,6 @@
119120 $conds['page_namespace'] = $this->namespace;
120121 // Has to be good enough
121122 $x = 3.5;
122 - if( $this->tag == 'overall' ) {
123 - global $wgFlaggedRevsFeedbackTags;
124 - $s = $x*array_sum($wgFlaggedRevsFeedbackTags);
125 - $x = intval( floor($s/count($wgFlaggedRevsFeedbackTags)) );
126 - }
127123 $conds[] = "rfp_ave_val > $x";
128124 // Reasonable sample
129125 $conds[] = 'rfp_count >= '.READER_FEEDBACK_SIZE;
Index: trunk/extensions/FlaggedRevs/FlaggedRevsXML.php
@@ -92,8 +92,6 @@
9393 foreach( FlaggedRevs::getFeedbackTags() as $tag => $weight ) {
9494 $s .= Xml::option( wfMsg( "readerfeedback-$tag" ), $tag, $selected===$tag );
9595 }
96 - # Aggregate for all tags
97 - $s .= Xml::option( wfMsg( "readerfeedback-overall" ), 'overall', $selected==='overall' );
9896 $s .= Xml::closeElement('select')."\n";
9997 return $s;
10098 }
Index: trunk/extensions/FlaggedRevs/flaggedrevs.js
@@ -94,7 +94,7 @@
9595 * Update colors when select changes (Opera already does this).
9696 */
9797 function updateFeedbackForm() {
98 - var somezero = false;
 98+ var allzero = true;
9999 var ratingform = document.getElementById('mw-feedbackselects');
100100 if( !ratingform ) return;
101101 for( tag in wgFlaggedRevsParams2.tags ) {
@@ -108,13 +108,13 @@
109109 if( navigator.appName != 'Opera') {
110110 levels[0].className = 'fr-rating-option-' + (4 - selectedlevel);
111111 }
112 - if( selectedlevel > 4 ) {
113 - somezero = true;
 112+ if( selectedlevel <= 4 ) {
 113+ allzero = false;
114114 }
115115 }
116116 }
117117 var submit = document.getElementById('submitfeedback');
118 - submit.disabled = somezero ? 'disabled' : '';
 118+ submit.disabled = allzero ? 'disabled' : '';
119119 }
120120
121121 addOnloadHook(enable_showhide);

Status & tagging log