r45626 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45625‎ | r45626 | r45627 >
Date:01:25, 10 January 2009
Author:aaron
Status:ok
Tags:
Comment:
* Get $days in the first query pass
* Make $int more consistent (x mark spacing)
Modified paths:
  • /trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php
@@ -200,16 +200,9 @@
201201 }
202202 // Define the data using the DB rows
203203 $totalVal = $totalCount = $n = 0;
204 - list($res,$u,$maxC) = $this->doQuery( $tag );
 204+ list($res,$u,$maxC,$days) = $this->doQuery( $tag );
205205 // Label spacing
206 - if( $row = $res->fetchObject() ) {
207 - $lower = wfTimestamp( TS_UNIX, $row->rfh_date );
208 - $res->seek( $res->numRows()-1 );
209 - $upper = wfTimestamp( TS_UNIX, $res->fetchObject( $res )->rfh_date );
210 - $days = intval( ($upper - $lower)/86400 );
211 - $int = intval( ceil($days/10) ); // 10 labels at most
212 - $res->seek( 0 );
213 - }
 206+ $int = intval( ceil($days/10) ); // 10 labels at most
214207 $dates = $drating = $arating = $dcount = "";
215208 while( $row = $res->fetchObject() ) {
216209 $totalVal += (int)$row->rfh_total;
@@ -267,16 +260,9 @@
268261 $data = array();
269262 $totalVal = $totalCount = $n = 0;
270263 // Define the data using the DB rows
271 - list($res,$u,$maxC) = $this->doQuery( $tag );
 264+ list($res,$u,$maxC,$days) = $this->doQuery( $tag );
272265 // Label spacing
273 - if( $row = $res->fetchObject() ) {
274 - $lower = wfTimestamp( TS_UNIX, $row->rfh_date );
275 - $res->seek( $res->numRows()-1 );
276 - $upper = wfTimestamp( TS_UNIX, $res->fetchObject()->rfh_date );
277 - $days = intval( ($upper - $lower)/86400 );
278 - $int = ($days > 31) ? 31 : intval( ceil($days/12) );
279 - $res->seek( 0 );
280 - }
 266+ $int = intval( ceil($days/10) ); // 10 labels at most
281267 while( $row = $res->fetchObject() ) {
282268 $totalVal += (int)$row->rfh_total;
283269 $totalCount += (int)$row->rfh_count;
@@ -373,16 +359,9 @@
374360 $dataX = $dave = $rave = $dcount = array();
375361 $totalVal = $totalCount = $sd = $pts = $n = 0;
376362 // Define the data using the DB rows
377 - list($res,$u,$maxC) = $this->doQuery( $tag );
 363+ list($res,$u,$maxC,$days) = $this->doQuery( $tag );
378364 // Label spacing
379 - if( $row = $res->fetchObject() ) {
380 - $lower = wfTimestamp( TS_UNIX, $row->rfh_date );
381 - $res->seek( $res->numRows()-1 );
382 - $upper = wfTimestamp( TS_UNIX, $res->fetchObject()->rfh_date );
383 - $days = intval( ($upper - $lower)/86400 );
384 - $int = ($days > 31) ? 31 : ceil($days/12);
385 - $res->seek( 0 );
386 - }
 365+ $int = intval( ceil($days/10) ); // 10 labels at most
387366 while( $row = $res->fetchObject() ) {
388367 $pts++;
389368 $totalVal += (int)$row->rfh_total;
@@ -500,17 +479,23 @@
501480 array( 'ORDER BY' => 'rfh_date ASC' )
502481 );
503482 # Get max count and average rating
504 - $total = $count = $ave = $maxC = 0;
505 - if( $dbr->numRows($res) ) {
 483+ $total = $count = $ave = $maxC = $days = 0;
 484+ if( $dbr->numRows($res) > 0 ) {
506485 while( $row = $dbr->fetchObject($res) ) {
 486+ if( !isset($lower) ) {
 487+ $lower = wfTimestamp( TS_UNIX, $row->rfh_date ); // first day
 488+ }
507489 $total += (int)$row->rfh_total;
508490 $count += (int)$row->rfh_count;
509491 if( $row->rfh_count > $maxC ) $maxC = intval($row->rfh_count);
 492+ $upper = $row->rfh_date;
510493 }
511 - $ave = 1+$total/$count; // Offset to [1,5]
512 - $res->seek( 0 );
 494+ $upper = wfTimestamp( TS_UNIX, $upper );
 495+ $days = intval( ($upper - $lower)/86400 );
 496+ $ave = 1 + $total/$count; // Offset to [1,5]
 497+ $res->seek( 0 ); // reset query row
513498 }
514 - return array($res,$ave,$maxC);
 499+ return array($res,$ave,$maxC,$days);
515500 }
516501
517502 /**

Status & tagging log