r46004 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46003‎ | r46004 | r46005 >
Date:05:52, 22 January 2009
Author:aaron
Status:ok
Tags:
Comment:
* Pretty up quick table overview
* Added table to ratinghistory
* Division by zero notice fixes
Modified paths:
  • /trunk/extensions/FlaggedRevs/language/RatingHistory.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/language/RatingHistory.i18n.php
@@ -19,9 +19,12 @@
2020 'ratinghistory-year' => 'last year',
2121 'ratinghistory-3years' => 'last 3 years',
2222 'ratinghistory-chart' => 'Reader feedback rating over time',
 23+ 'ratinghistory-table' => 'Overview of last month',
2324 'ratinghistory-users' => 'Users who gave ratings',
2425 'ratinghistory-graph' => '$2 of "$3" ($1 {{PLURAL:$1|review|reviews}})',
2526 'readerfeedback-svg' => 'View as SVG',
 27+ 'ratinghistory-table-rating' => 'Rating',
 28+ 'ratinghistory-table-votes' => 'Votes',
2629 'ratinghistory-none' => 'There is not enough reader feedback data available for graphs at this time.',
2730 'ratinghistory-legend' => 'The \'\'\'daily average rating\'\'\' <font color="blue">\'\'(blue)\'\'</font> and
2831 \'\'\'running average rating\'\'\' <font color="green">\'\'(green)\'\'</font> are graphed below, by date. The
Index: trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php
@@ -63,9 +63,19 @@
6464 } else {
6565 $wgOut->enableClientCache( false ); // don't show stale graphs
6666 }
 67+ $this->showTable();
6768 $this->showGraphs();
6869 }
6970
 71+ protected function showTable() {
 72+ global $wgOut;
 73+ # Show latest month of results
 74+ $html = $this->getVoteAggregates( 31 );
 75+ if( $html ) {
 76+ $wgOut->addHTML( '<h2>'.wfMsgHtml('ratinghistory-table')."</h2>\n".$html );
 77+ }
 78+ }
 79+
7080 protected function showHeader() {
7181 global $wgOut;
7282 $wgOut->addWikiText( wfMsg('ratinghistory-legend',$this->dScale) );
@@ -269,6 +279,7 @@
270280 $totalVal += (int)$row->rfh_total;
271281 $totalCount += (int)$row->rfh_count;
272282 $dayCount = (real)$row->rfh_count;
 283+ if( !$row->rfh_count ) continue; // bad data
273284 // Nudge values up by 1
274285 $dayAve = 1 + (real)$row->rfh_total/(real)$row->rfh_count;
275286 $cumAve = 1 + (real)$totalVal/(real)$totalCount;
@@ -371,6 +382,7 @@
372383 $totalVal += (int)$row->rfh_total;
373384 $totalCount += (int)$row->rfh_count;
374385 $dayCount = (real)$row->rfh_count;
 386+ if( !$row->rfh_count ) continue; // bad data
375387 // Nudge values up by 1 to fit [1,5]
376388 $dayAve = 1 + (real)$row->rfh_total/(real)$row->rfh_count;
377389 $sd += pow($dayAve - $u,2);
@@ -446,7 +458,7 @@
447459 </defs>';
448460 */
449461 # Create the graph
450 - $plot->init();
 462+ @$plot->init();
451463 $plot->drawGraph();
452464 $plot->polyLine('dave');
453465 $plot->polyLine('rave');
@@ -607,13 +619,10 @@
608620 return $html;
609621 }
610622
611 - public function getVoteAggregates() {
612 - if( $this->period > 93 ) {
613 - return ''; // too big
614 - }
 623+ public function getVoteAggregates( $period ) {
615624 // Set cutoff time for period
616625 $dbr = wfGetDB( DB_SLAVE );
617 - $cutoff_unixtime = time() - ($this->period * 24 * 3600);
 626+ $cutoff_unixtime = time() - ($period * 24 * 3600);
618627 $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
619628 $cutoff = $dbr->addQuotes( wfTimestamp( TS_MW, $cutoff_unixtime ) );
620629 // Get the first revision possibly voted on in the range
@@ -649,19 +658,27 @@
650659 }
651660 }
652661 // Output multi-column list
653 - $html = "<table class='fr_reader_feedback_stats'><tr>";
654 - $html .= '<tr><th></th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th></tr>';
 662+ $html = "<table class='fr_reader_feedback_stats wikitable' cellspacing='0'><tr>";
 663+ foreach( FlaggedRevs::getFeedbackTags() as $tag => $w ) {
 664+ $html .= '<th>'.wfMsgHtml("readerfeedback-$tag").'</th>';
 665+ }
 666+ $html .= '</tr><tr>';
655667 foreach( $votes as $tag => $dist ) {
656 - $html .= '<tr>';
657 - $html .= '<td>'.wfMsgHtml("readerfeedback-$tag") . '</td>';
 668+ $html .= '<td><table>';
 669+ $html .= '<tr><th align="left">'.wfMsgHtml('ratinghistory-table-rating').'</th>';
 670+ for( $i = 1; $i <= 5; $i++ ) {
 671+ $html .= "<td class='fr-rating-option-".($i-1)."'>$i</td>";
 672+ }
 673+ $html .= '</tr><tr>';
 674+ $html .= '<th align="left">'.wfMsgHtml("ratinghistory-table-votes").'</th>';
658675 $html .= '<td>'.$dist[0].'</td>';
659676 $html .= '<td>'.$dist[1].'</td>';
660677 $html .= '<td>'.$dist[2].'</td>';
661678 $html .= '<td>'.$dist[3].'</td>';
662679 $html .= '<td>'.$dist[4].'</td>';
663 - $html .= "</tr>\n";
 680+ $html .= "</tr></table></td>\n";
664681 }
665 - $html .= "</tr></table>\n";
 682+ $html .= '</tr></table>';
666683 return $html;
667684 }
668685

Status & tagging log