r44654 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44653‎ | r44654 | r44655 >
Date:06:24, 16 December 2008
Author:aaron
Status:deferred
Tags:
Comment:
*Fix XHTML (from subtitle message)
*Add 'view as SVG' link
*Add average and standard deviation to graphs
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
@@ -20,7 +20,8 @@
2121 'ratinghistory-3years' => 'last 3 years',
2222 'ratinghistory-chart' => 'Reader feedback rating over time',
2323 'ratinghistory-users' => 'Users who gave ratings',
24 - 'ratinghistory-graph' => '$2 of "$3" ($1 {{PLURAL:$1|review|reviews}})',
 24+ 'ratinghistory-graph' => '$2 of "$3" ($1 {{PLURAL:$1|review|reviews}}) [μ=$4; σ=$5]',
 25+ 'readerfeedback-svg' => 'View as SVG',
2526 'ratinghistory-none' => 'There is not enough reader feedback data available for graphs at this time.',
2627 'ratinghistory-legend' => 'The \'\'\'daily average rating\'\'\' <font color="blue">\'\'(blue)\'\'</font> and
2728 \'\'\'running average rating\'\'\' <font color="green">\'\'(green)\'\'</font> are graphed below, by date. The
Index: trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php
@@ -51,7 +51,7 @@
5252 $this->dScale = 20;
5353 # Thank voters
5454 if( ReaderFeedback::userAlreadyVoted( $this->page ) ) {
55 - $wgOut->setSubtitle( wfMsgExt('ratinghistory-thanks','parse') );
 55+ $wgOut->setSubtitle( wfMsgExt('ratinghistory-thanks','parseinline') );
5656 }
5757 $this->showForm();
5858 $this->showHeader();
@@ -138,7 +138,14 @@
139139 case 'png':
140140 if( $exists ) {
141141 $data = true;
142 - $wgOut->addHTML( "<h3>" . wfMsgHtml("readerfeedback-$tag") . "</h3>\n" );
 142+ // Add link for users with non-shitty browsers to see SVG itself
 143+ $viewLink = "";
 144+ if( $sExt === 'svg' ) {
 145+ $svgUrl = $this->getUrlPath( $tag, 'svg' );
 146+ $viewLink = " <small>[<a href='".$svgUrl."'>".
 147+ wfMsgHtml("readerfeedback-svg")."</a>]</small>";
 148+ }
 149+ $wgOut->addHTML( "<h3>" . wfMsgHtml("readerfeedback-$tag") . "$viewLink</h3>\n" );
143150 $wgOut->addHTML(
144151 Xml::openElement( 'div', array('class' => 'fr_reader_feedback_graph') ) .
145152 Xml::openElement( 'img', array('src' => $url,'alt' => $tag) ) .
@@ -193,7 +200,7 @@
194201 }
195202 // Define the data using the DB rows
196203 $totalVal = $totalCount = $n = 0;
197 - $res = $this->doQuery( $tag );
 204+ list($res,$u,$maxC) = $this->doQuery( $tag );
198205 // Label spacing
199206 if( $row = $res->fetchObject() ) {
200207 $lower = wfTimestamp( TS_UNIX, $row->rfh_date );
@@ -204,7 +211,6 @@
205212 $res->seek( 0 );
206213 }
207214 $dates = $drating = $arating = $dcount = "";
208 - $n = 0;
209215 while( $row = $res->fetchObject() ) {
210216 $totalVal += (int)$row->rfh_total;
211217 $totalCount += (int)$row->rfh_count;
@@ -261,7 +267,7 @@
262268 $data = array();
263269 $totalVal = $totalCount = $n = 0;
264270 // Define the data using the DB rows
265 - $res = $this->doQuery( $tag );
 271+ list($res,$u,$maxC) = $this->doQuery( $tag );
266272 // Label spacing
267273 if( $row = $res->fetchObject() ) {
268274 $lower = wfTimestamp( TS_UNIX, $row->rfh_date );
@@ -365,9 +371,9 @@
366372 $plot->maxY = 5;
367373 // Define the data using the DB rows
368374 $dataX = $dave = $rave = $dcount = array();
369 - $totalVal = $totalCount = $n = 0;
 375+ $totalVal = $totalCount = $sd = $pts = $n = 0;
370376 // Define the data using the DB rows
371 - $res = $this->doQuery( $tag );
 377+ list($res,$u,$maxC) = $this->doQuery( $tag );
372378 // Label spacing
373379 if( $row = $res->fetchObject() ) {
374380 $lower = wfTimestamp( TS_UNIX, $row->rfh_date );
@@ -378,11 +384,13 @@
379385 $res->seek( 0 );
380386 }
381387 while( $row = $res->fetchObject() ) {
 388+ $pts++;
382389 $totalVal += (int)$row->rfh_total;
383390 $totalCount += (int)$row->rfh_count;
384391 $dayCount = (real)$row->rfh_count;
385 - // Nudge values up by 1
 392+ // Nudge values up by 1 to fit [1,5]
386393 $dayAve = 1 + (real)$row->rfh_total/(real)$row->rfh_count;
 394+ $sd += pow($dayAve - $u,2);
387395 $cumAve = 1 + (real)$totalVal/(real)$totalCount;
388396 $year = intval( substr( $row->rfh_date, 0, 4 ) );
389397 $month = intval( substr( $row->rfh_date, 4, 2 ) );
@@ -417,9 +425,13 @@
418426 $lastRAve = $cumAve;
419427 }
420428 // Minimum sample size
421 - if( count($dataX) < 2 ) {
 429+ if( $pts < 2 ) {
422430 return false;
423431 }
 432+ $sd = sqrt($sd/$pts);
 433+ // Round values for display
 434+ $sd = round( $sd, 3 );
 435+ $u = round( $u, 3 );
424436 // Fit to [0,4]
425437 foreach( $dcount as $x => $c ) {
426438 $dcount[$x] = $c/$this->dScale;
@@ -434,9 +446,9 @@
435447 $plot->format['rave'] = array( 'style' => 'stroke:green; stroke-width:1;' );
436448 $plot->format['dcount'] = array( 'style' => 'stroke:red; stroke-width:1;' );
437449 #'attributes' => "marker-end='url(#circle)'");
438 - $pageText = $wgContLang->truncate( $this->page->getPrefixedText(), 70, '...' );
 450+ $pageText = $wgContLang->truncate( $this->page->getPrefixedText(), 60, '...' );
439451 $plot->title = wfMsgExt('ratinghistory-graph',array('parsemag','content'),
440 - $totalCount, wfMsgForContent("readerfeedback-$tag"), $pageText );
 452+ $totalCount, wfMsgForContent("readerfeedback-$tag"), $pageText, $u, $sd );
441453 $plot->styleTitle = 'font-family: sans-serif; font-weight: bold; font-size: 12pt;';
442454 $plot->backgroundStyle = 'fill:#F0F0F0;';
443455 // extra code for markers
@@ -487,7 +499,18 @@
488500 __METHOD__,
489501 array( 'ORDER BY' => 'rfh_date ASC' )
490502 );
491 - return $res;
 503+ # Get max count and average rating
 504+ $total = $count = $ave = $maxC = 0;
 505+ if( $dbr->numRows($res) ) {
 506+ while( $row = $dbr->fetchObject($res) ) {
 507+ $total += (int)$row->rfh_total;
 508+ $count += (int)$row->rfh_count;
 509+ if( $row->rfh_count > $maxC ) $maxC = intval($row->rfh_count);
 510+ }
 511+ $ave = 1+$total/$count; // Offset to [1,5]
 512+ $res->seek( 0 );
 513+ }
 514+ return array($res,$ave,$maxC);
492515 }
493516
494517 /**
@@ -505,11 +528,12 @@
506529 /**
507530 * Get the url to where the corresponding graph file should be
508531 * @param string $tag
 532+ * @param string $ext
509533 * @returns string
510534 */
511 - public function getUrlPath( $tag ) {
 535+ public function getUrlPath( $tag, $ext='' ) {
512536 global $wgUploadPath;
513 - $rel = self::getRelPath( $tag );
 537+ $rel = self::getRelPath( $tag, $ext );
514538 return "{$wgUploadPath}/graphs/{$rel}";
515539 }
516540

Status & tagging log