Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.i18n.php |
— | — | @@ -26,7 +26,15 @@ |
27 | 27 | 'prefstats-counters-expensive' => '* $1 {{PLURAL:$1|user has|users have}} enabled this preference since preference statistics were activated |
28 | 28 | ** $2 {{PLURAL:$2|user has|users have}} enabled it |
29 | 29 | ** $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', |
31 | 39 | ); |
32 | 40 | |
33 | 41 | /** Arabic (العربية) |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php |
— | — | @@ -30,11 +30,23 @@ |
31 | 31 | $wgPrefStatsTrackPrefs = array(); |
32 | 32 | |
33 | 33 | // Dimensions of the chart on Special:PrefStats |
34 | | -$wgPrefStatsChartDimensions = '1000x300'; |
| 34 | +$wgPrefStatsChartDimensions = array( 800, 300 ); |
35 | 35 | |
36 | 36 | // 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 |
38 | 39 | |
| 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 | + |
39 | 51 | // Whether to run possibly expensive COUNT(*) queries on the user_properties |
40 | 52 | // table |
41 | 53 | $wgPrefStatsExpensiveCounts = false; |
Index: trunk/extensions/UsabilityInitiative/PrefStats/SpecialPrefStats.php |
— | — | @@ -60,22 +60,44 @@ |
61 | 61 | 'prefstats-counters-expensive' : |
62 | 62 | 'prefstats-counters'; |
63 | 63 | $wgOut->addWikiMsgArray( $message, $counters ); |
| 64 | + $wgOut->addHTML( $this->incLinks( $pref ) ); |
64 | 65 | $wgOut->addHTML( Xml::element( 'img', array( 'src' => |
65 | 66 | $this->getGoogleChartParams( $stats ) ) ) ); |
66 | 67 | } |
| 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 | + } |
67 | 83 | |
68 | 84 | function getGoogleChartParams( $stats ) { |
69 | 85 | global $wgPrefStatsChartDimensions; |
| 86 | + $max = max( $stats[0] ) + max( $stats[1] ); |
| 87 | + $min = min( min( $stats[0] ), min( $stats[1] ) ); |
70 | 88 | return "http://chart.apis.google.com/chart?" . wfArrayToCGI( |
71 | 89 | array( |
72 | | - 'chs' => $wgPrefStatsChartDimensions, |
| 90 | + 'chs' => implode( 'x', $wgPrefStatsChartDimensions ), |
73 | 91 | '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' |
80 | 102 | ) ); |
81 | 103 | } |
82 | 104 | |
— | — | @@ -112,9 +134,11 @@ |
113 | 135 | for ( $i = 0; $i <= $max; $i += $inc ) { |
114 | 136 | $end = min( $max, $i + $inc ); |
115 | 137 | $key = $i . '-' . $end; |
116 | | - $retval[$key] = $this->countBetween( $pref, |
| 138 | + list( $out, $in ) = $this->countBetween( $pref, |
117 | 139 | $i * $wgPrefStatsTimeUnit, |
118 | 140 | $end * $wgPrefStatsTimeUnit ); |
| 141 | + $retval[0][$key] = $out; |
| 142 | + $retval[1][$key] = $in; |
119 | 143 | } |
120 | 144 | return $retval; |
121 | 145 | } |
— | — | @@ -136,6 +160,7 @@ |
137 | 161 | /** |
138 | 162 | * Count the number of users having $pref enabled between |
139 | 163 | * $min and $max seconds |
| 164 | + * @return array( opted out, still opted in ) |
140 | 165 | */ |
141 | 166 | function countBetween( $pref, $min, $max ) { |
142 | 167 | $dbr = wfGetDb( DB_SLAVE ); |
— | — | @@ -152,6 +177,6 @@ |
153 | 178 | 'ps_start <' . $dbr->addQuotes( $dbr->timestamp( $maxTS ) ), |
154 | 179 | 'ps_start >=' . $dbr->addQuotes( $dbr->timestamp( $minTS ) ) |
155 | 180 | ), __METHOD__ ); |
156 | | - return $count1 + $count2; |
| 181 | + return array( $count1, $count2 ); |
157 | 182 | } |
158 | 183 | } |