r54738 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54737‎ | r54738 | r54739 >
Date:20:38, 10 August 2009
Author:catrope
Status:deferred
Tags:
Comment:
PrefStats:
* Make the chart stacked
* Add a label to the x axis (not to the y axis, looks ugly)
* Add some &inc= convenience links for viewing per hour, day, etc.
* Set $wgPrefStatsTimeUnit to an hour instead of a day by default
* Set the chart size to 800x300 instead of 1000x300 by default
* Make the chart expand to fill the 800x300 rectangle
Modified paths:
  • /trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.i18n.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/PrefStats/SpecialPrefStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.i18n.php
@@ -26,7 +26,15 @@
2727 'prefstats-counters-expensive' => '* $1 {{PLURAL:$1|user has|users have}} enabled this preference since preference statistics were activated
2828 ** $2 {{PLURAL:$2|user has|users have}} enabled it
2929 ** $3 {{PLURAL:$3|user has|users have}} disabled it
30 -* In total, $4 {{PLURAL:$4|user has|users have}} this preference set',
 30+* In total, $4 {{PLURAL:$4|user has|users have}} this preference set',
 31+ 'prefstats-xaxis' => 'Duration (hours)',
 32+ 'prefstats-factors' => 'View per: $1',
 33+ 'prefstats-factor-hour' => 'hour',
 34+ 'prefstats-factor-day' => 'day',
 35+ 'prefstats-factor-week' => 'week',
 36+ 'prefstats-factor-twoweeks' => 'two weeks',
 37+ 'prefstats-factor-fourweeks' => 'four weeks',
 38+ 'prefstats-factor-default' => 'back to default scale',
3139 );
3240
3341 /** Arabic (العربية)
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php
@@ -30,11 +30,23 @@
3131 $wgPrefStatsTrackPrefs = array();
3232
3333 // Dimensions of the chart on Special:PrefStats
34 -$wgPrefStatsChartDimensions = '1000x300';
 34+$wgPrefStatsChartDimensions = array( 800, 300 );
3535
3636 // Time unit to use for the graph on Special:PrefStats
37 -$wgPrefStatsTimeUnit = 60 * 60 * 24; // one day
 37+// Don't change this unless you know what you're doing
 38+$wgPrefStatsTimeUnit = 60 * 60; // one hour
3839
 40+// Multiples of $wgPrefStatsTimeUnit to offer
 41+// array( messagekey => factor )
 42+$wgPrefStatsTimeFactors = array(
 43+ 'prefstats-factor-hour' => 1,
 44+ 'prefstats-factor-day' => 24,
 45+ 'prefstats-factor-week' => 7*24,
 46+ 'prefstats-factor-twoweeks' => 2*7*24,
 47+ 'prefstats-factor-fourweeks' => 4*7*24,
 48+ 'prefstats-factor-default' => null,
 49+);
 50+
3951 // Whether to run possibly expensive COUNT(*) queries on the user_properties
4052 // table
4153 $wgPrefStatsExpensiveCounts = false;
Index: trunk/extensions/UsabilityInitiative/PrefStats/SpecialPrefStats.php
@@ -60,22 +60,44 @@
6161 'prefstats-counters-expensive' :
6262 'prefstats-counters';
6363 $wgOut->addWikiMsgArray( $message, $counters );
 64+ $wgOut->addHTML( $this->incLinks( $pref ) );
6465 $wgOut->addHTML( Xml::element( 'img', array( 'src' =>
6566 $this->getGoogleChartParams( $stats ) ) ) );
6667 }
 68+
 69+ function incLinks( $pref ) {
 70+ global $wgPrefStatsTimeFactors, $wgLang;
 71+ $factors = array();
 72+ foreach ( $wgPrefStatsTimeFactors as $message => $factor ) {
 73+ $attrs = array();
 74+ if ( !is_null( $factor ) )
 75+ $attrs['inc'] = $factor;
 76+ $factors[] = Xml::element( 'a', array( 'href' =>
 77+ $this->getTitle( $pref )->getFullURL( $attrs )
 78+ ), wfMsg( $message ) );
 79+ }
 80+ return wfMsg( 'prefstats-factors',
 81+ $wgLang->pipeList( $factors ) );
 82+ }
6783
6884 function getGoogleChartParams( $stats ) {
6985 global $wgPrefStatsChartDimensions;
 86+ $max = max( $stats[0] ) + max( $stats[1] );
 87+ $min = min( min( $stats[0] ), min( $stats[1] ) );
7088 return "http://chart.apis.google.com/chart?" . wfArrayToCGI(
7189 array(
72 - 'chs' => $wgPrefStatsChartDimensions,
 90+ 'chs' => implode( 'x', $wgPrefStatsChartDimensions ),
7391 'cht' => 'bvs',
74 - 'chds' => '0,' . max( $stats ),
75 - 'chd' => 't:' . implode( ',', $stats ),
76 - 'chxt' => 'x,y',
77 - 'chxr' => '1,' . min( $stats ) . ',' . max( $stats ),
78 - 'chxl' => '0:|' . implode( '|', array_keys( $stats ) ),
79 - 'chm' => 'N*f0zy*,000000,0,-1,11'
 92+ 'chds' => '0,' . $max,
 93+ 'chd' => 't:' . implode( ',', $stats[0] ) . '|' .
 94+ implode( ',', $stats[1] ),
 95+ 'chxt' => 'x,y,x',
 96+ 'chxr' => '1,' . $min . ',' . $max,
 97+ 'chxl' => '2:|' . wfMsg( 'prefstats-xaxis' ) .
 98+ '|0:|' . implode( '|', array_keys( $stats[0] ) ),
 99+ 'chm' => 'N*f0zy*,000000,0,-1,11|N*f0zy*,000000,1,-1,11',
 100+ 'chco' => '4D89F9,C6D9FD',
 101+ 'chbh' => 'a'
80102 ) );
81103 }
82104
@@ -112,9 +134,11 @@
113135 for ( $i = 0; $i <= $max; $i += $inc ) {
114136 $end = min( $max, $i + $inc );
115137 $key = $i . '-' . $end;
116 - $retval[$key] = $this->countBetween( $pref,
 138+ list( $out, $in ) = $this->countBetween( $pref,
117139 $i * $wgPrefStatsTimeUnit,
118140 $end * $wgPrefStatsTimeUnit );
 141+ $retval[0][$key] = $out;
 142+ $retval[1][$key] = $in;
119143 }
120144 return $retval;
121145 }
@@ -136,6 +160,7 @@
137161 /**
138162 * Count the number of users having $pref enabled between
139163 * $min and $max seconds
 164+ * @return array( opted out, still opted in )
140165 */
141166 function countBetween( $pref, $min, $max ) {
142167 $dbr = wfGetDb( DB_SLAVE );
@@ -152,6 +177,6 @@
153178 'ps_start <' . $dbr->addQuotes( $dbr->timestamp( $maxTS ) ),
154179 'ps_start >=' . $dbr->addQuotes( $dbr->timestamp( $minTS ) )
155180 ), __METHOD__ );
156 - return $count1 + $count2;
 181+ return array( $count1, $count2 );
157182 }
158183 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r54752Merge a bunch of UsabilityInitiative fixes. This commit may mess up svn:merge...catrope22:12, 10 August 2009

Status & tagging log