Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.i18n.php |
— | — | @@ -19,6 +19,13 @@ |
20 | 20 | Click on one to view statistics about it.', |
21 | 21 | 'prefstats-list-elem' => '$1 = $2', |
22 | 22 | 'prefstats-noprefs' => 'No preferences are currently being tracked. Configure $wgPrefStatsTrackPrefs to track preferences.', |
| 23 | + 'prefstats-counters' => '* {{PLURAL:$1|$1 user has|$1 users have}} enabled this preference since PrefStats was activated |
| 24 | +** $2 of them still have it enabled |
| 25 | +** $3 of them have disabled it', |
| 26 | + 'prefstats-counters-expensive' => '* {{PLURAL:$1|$1 user has|$1 users have}} enabled this preference since PrefStats was activated |
| 27 | +** $2 of them still have it enabled |
| 28 | +** $3 of them have disabled it |
| 29 | +* In total, $4 users have this preference set', |
23 | 30 | ); |
24 | 31 | |
25 | 32 | /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца)) |
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php |
— | — | @@ -35,6 +35,10 @@ |
36 | 36 | // Time unit to use for the graph on Special:PrefStats |
37 | 37 | $wgPrefStatsTimeUnit = 60 * 60 * 24; // one day |
38 | 38 | |
| 39 | +// Whether to run possibly expensive COUNT(*) queries on the user_properties |
| 40 | +// table |
| 41 | +$wgPrefStatsExpensiveCounts = false; |
| 42 | + |
39 | 43 | /* Setup */ |
40 | 44 | |
41 | 45 | // Right required to view Special:PrefStats |
Index: trunk/extensions/UsabilityInitiative/PrefStats/SpecialPrefStats.php |
— | — | @@ -51,10 +51,15 @@ |
52 | 52 | } |
53 | 53 | |
54 | 54 | function displayPrefStats( $pref ) { |
55 | | - global $wgOut, $wgRequest, $wgPrefStatsTrackPrefs; |
| 55 | + global $wgOut, $wgRequest, $wgPrefStatsExpensiveCounts; |
56 | 56 | $max = $this->getMaxDuration( $pref ); |
57 | 57 | $stats = $this->getPrefStats( $pref, |
58 | 58 | $wgRequest->getIntOrNull( 'inc' ) ); |
| 59 | + $counters = $this->getCounters( $pref ); |
| 60 | + $message = $wgPrefStatsExpensiveCounts ? |
| 61 | + 'prefstats-counters-expensive' : |
| 62 | + 'prefstats-counters'; |
| 63 | + $wgOut->addWikiMsgArray( $message, $counters ); |
59 | 64 | $wgOut->addHTML( Xml::element( 'img', array( 'src' => |
60 | 65 | $this->getGoogleChartParams( $stats ) ) ) ); |
61 | 66 | } |
— | — | @@ -73,6 +78,30 @@ |
74 | 79 | 'chm' => 'N*f0zy*,000000,0,-1,11' |
75 | 80 | ) ); |
76 | 81 | } |
| 82 | + |
| 83 | + function getCounters( $pref ) { |
| 84 | + global $wgPrefStatsExpensiveCounts, $wgPrefStatsTrackPrefs; |
| 85 | + $val = $wgPrefStatsTrackPrefs[$pref]; |
| 86 | + |
| 87 | + $dbr = wfGetDb( DB_SLAVE ); |
| 88 | + $c2 = $dbr->selectField( 'prefstats', 'COUNT(*)', array( |
| 89 | + 'ps_pref' => $pref, |
| 90 | + 'ps_duration IS NULL' |
| 91 | + ), __METHOD__ ); |
| 92 | + $c3 = $dbr->selectField( 'prefstats', 'COUNT(*)', array( |
| 93 | + 'ps_pref' => $pref, |
| 94 | + 'ps_duration IS NOT NULL' |
| 95 | + ), __METHOD__ ); |
| 96 | + $c1 = $c2 + $c3; |
| 97 | + if ( $wgPrefStatsExpensiveCounts ) |
| 98 | + $c4 = $dbr->selectField( 'user_properties', 'COUNT(*)', |
| 99 | + array( 'up_property' => $pref, |
| 100 | + 'up_value' => $val |
| 101 | + ), __METHOD__ ); |
| 102 | + else |
| 103 | + $c4 = 0; |
| 104 | + return array( $c1, $c2, $c3, $c4 ); |
| 105 | + } |
77 | 106 | |
78 | 107 | function getPrefStats( $pref, $inc = null ) { |
79 | 108 | global $wgPrefStatsTimeUnit; |