r54648 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54647‎ | r54648 | r54649 >
Date:10:49, 9 August 2009
Author:catrope
Status:deferred
Tags:
Comment:
PrefStats: Add counters to Special:PrefStats
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
@@ -19,6 +19,13 @@
2020 Click on one to view statistics about it.',
2121 'prefstats-list-elem' => '$1 = $2',
2222 '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',
2330 );
2431
2532 /** Belarusian (Taraškievica orthography) (Беларуская (тарашкевіца))
Index: trunk/extensions/UsabilityInitiative/PrefStats/PrefStats.php
@@ -35,6 +35,10 @@
3636 // Time unit to use for the graph on Special:PrefStats
3737 $wgPrefStatsTimeUnit = 60 * 60 * 24; // one day
3838
 39+// Whether to run possibly expensive COUNT(*) queries on the user_properties
 40+// table
 41+$wgPrefStatsExpensiveCounts = false;
 42+
3943 /* Setup */
4044
4145 // Right required to view Special:PrefStats
Index: trunk/extensions/UsabilityInitiative/PrefStats/SpecialPrefStats.php
@@ -51,10 +51,15 @@
5252 }
5353
5454 function displayPrefStats( $pref ) {
55 - global $wgOut, $wgRequest, $wgPrefStatsTrackPrefs;
 55+ global $wgOut, $wgRequest, $wgPrefStatsExpensiveCounts;
5656 $max = $this->getMaxDuration( $pref );
5757 $stats = $this->getPrefStats( $pref,
5858 $wgRequest->getIntOrNull( 'inc' ) );
 59+ $counters = $this->getCounters( $pref );
 60+ $message = $wgPrefStatsExpensiveCounts ?
 61+ 'prefstats-counters-expensive' :
 62+ 'prefstats-counters';
 63+ $wgOut->addWikiMsgArray( $message, $counters );
5964 $wgOut->addHTML( Xml::element( 'img', array( 'src' =>
6065 $this->getGoogleChartParams( $stats ) ) ) );
6166 }
@@ -73,6 +78,30 @@
7479 'chm' => 'N*f0zy*,000000,0,-1,11'
7580 ) );
7681 }
 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+ }
77106
78107 function getPrefStats( $pref, $inc = null ) {
79108 global $wgPrefStatsTimeUnit;

Follow-up revisions

RevisionCommit summaryAuthorDate
r54649Tweak messages added in r54648siebrand11:03, 9 August 2009
r54650Another tweak on r54648 after a lot of staring. Thanks Roan.siebrand11:19, 9 August 2009
r54752Merge a bunch of UsabilityInitiative fixes. This commit may mess up svn:merge...catrope22:12, 10 August 2009

Status & tagging log