r37930 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37929‎ | r37930 | r37931 >
Date:02:02, 23 July 2008
Author:aaron
Status:old
Tags:
Comment:
* Graph fixes
* Tweak default params
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -216,7 +216,7 @@
217217 # Reader feedback tags, positive and negative. [a-zA-Z] tag names only.
218218 # Each tag has five levels, which 3 being average. The tag names are
219219 # mapped to their weight. This is used to determine the "worst"/"best" pages.
220 -$wgFlaggedRevsFeedbackTags = array( 'reliability' => 2, 'completeness' => 2, 'npov' => 1.5, 'presentation' => 1 );
 220+$wgFlaggedRevsFeedbackTags = array( 'reliability' => 3, 'completeness' => 2, 'npov' => 2, 'presentation' => 1 );
221221 # How many days back should the average rating for a page be based on?
222222 $wgFlaggedRevsFeedbackAge = 7 * 24 * 3600;
223223
Index: trunk/extensions/FlaggedRevs/specialpages/RatingHistory_body.php
@@ -55,13 +55,20 @@
5656
5757 protected function showForm() {
5858 global $wgOut, $wgTitle, $wgScript;
59 - $form = Xml::openElement( 'form',
60 - array( 'name' => 'reviewedpages', 'action' => $wgScript, 'method' => 'get' ) );
 59+ $form = Xml::openElement( 'form', array( 'name' => 'reviewedpages', 'action' => $wgScript, 'method' => 'get' ) );
6160 $form .= "<fieldset><legend>".wfMsg('ratinghistory-leg')."</legend>\n";
6261 $form .= Xml::hidden( 'title', $wgTitle->getPrefixedDBKey() );
6362 $form .= Xml::hidden( 'target', $this->page->getPrefixedDBKey() );
6463 $form .= $this->getPeriodMenu( $this->period );
6564 $form .= " ".Xml::submitButton( wfMsg( 'go' ) );
 65+ // Show legend
 66+ $form .= wfMsgExt('ratinghistory-ave',array('parse'));
 67+ $form .= Xml::openElement( 'div', array('class' => 'reader_feedback_legend') );
 68+ for( $i=0; $i <= 4; $i++) {
 69+ $form .= "<b>[$i]</b> - " . wfMsgHtml( "readerfeedback-level-$i" );
 70+ $form .= "&nbsp;&nbsp;&nbsp;";
 71+ }
 72+ $form .= Xml::closeElement( 'div' );
6673 $form .= "</fieldset></form>\n";
6774 $wgOut->addHTML( $form );
6875 }
@@ -99,13 +106,6 @@
100107 Xml::openElement( 'img', array('src' => $url,'alt' => $tag) ) . Xml::closeElement( 'img' ) .
101108 Xml::closeElement( 'div' )
102109 );
103 - // Show legend
104 - $wgOut->addHTML( Xml::openElement( 'div', array('class' => 'reader_feedback_legend') ) );
105 - for( $i=0; $i <= 4; $i++) {
106 - $wgOut->addHTML( "&nbsp;&nbsp;&nbsp;" );
107 - $wgOut->addHTML( "<b>[$i]</b> - " . wfMsgHtml( "readerfeedback-level-$i" ) );
108 - }
109 - $wgOut->addHTML( Xml::closeElement( 'div' ) );
110110 }
111111 }
112112
@@ -119,7 +119,7 @@
120120 global $wgPHPlotDir;
121121 require_once( "$wgPHPlotDir/phplot.php" ); // load classes
122122 // Define the object
123 - $plot = new PHPlot(900,600);
 123+ $plot = new PHPlot(900,400);
124124 // Set file path
125125 $dir = dirname($filePath);
126126 // Make sure directory exists
@@ -132,30 +132,45 @@
133133 #$plot->SetTitle("Rating history");
134134 #$plot->SetXTitle('Date');
135135 #$plot->SetYTitle('Daily and running average');
 136+ $dbr = wfGetDB( DB_SLAVE );
 137+ // Set cutoff time for period
 138+ $cutoff_unixtime = time() - ($this->period * 24 * 3600);
 139+ $cutoff_unixtime = $cutoff_unixtime - ($cutoff_unixtime % 86400);
 140+ $cutoff = $dbr->addQuotes( $dbr->timestamp( $cutoff_unixtime ) );
136141 // Define the data using the DB rows
137142 $data = array();
138143 $totalVal = $totalCount = 0;
139 - $dbr = wfGetDB( DB_SLAVE );
 144+ $lastDay = 31; // init to not trigger first time
140145 $res = $dbr->select( 'reader_feedback_history',
141146 array( 'rfh_total', 'rfh_count', 'rfh_date' ),
142 - array( 'rfh_page_id' => $this->page->getArticleId(), 'rfh_tag' => $tag ),
 147+ array( 'rfh_page_id' => $this->page->getArticleId(),
 148+ 'rfh_tag' => $tag,
 149+ "rfh_date >= {$cutoff}"),
143150 __METHOD__,
144 - array( 'ORDER BY' => 'rfh_date DESC' ) );
 151+ array( 'ORDER BY' => 'rfh_date ASC' ) );
145152 while( $row = $dbr->fetchObject( $res ) ) {
146153 $totalVal += (int)$row->rfh_total;
147154 $totalCount += (int)$row->rfh_count;
148155 $dayAve = (real)$row->rfh_total/(real)$row->rfh_count;
149156 $cumAve = (real)$totalVal/(real)$totalCount;
150 - $month = substr( $row->rfh_date, 4, 2 );
151 - $day = substr( $row->rfh_date, 6, 2 );
 157+ $month = intval( substr( $row->rfh_date, 4, 2 ) );
 158+ $day = intval( substr( $row->rfh_date, 6, 2 ) );
 159+ # Fill in days with no votes to keep spacing even
 160+ if( $day > ($lastDay + 1) ) {
 161+ for( $i=($lastDay + 1); $i < $day; $i++ ) {
 162+ $data[] = array("{$month}/{$i}",'','');
 163+ }
 164+ }
152165 $data[] = array("{$month}/{$day}",$dayAve,$cumAve);
 166+ $lastDay = $day;
153167 }
154168 // Flip order
155 - $data = array_reverse($data);
156169 $plot->SetDataValues($data);
157170 // Turn off X axis ticks and labels because they get in the way:
158171 $plot->SetXTickLabelPos('none');
159172 $plot->SetXTickPos('none');
 173+ $plot->SetYTickIncrement( .5 );
 174+ $plot->SetPlotAreaWorld( 0, 0, null, 4.5 );
160175 // Draw it!
161176 $plot->DrawGraph();
162177 return true;

Status & tagging log