Index: trunk/extensions/ContributionReporting/YearlyTotal_body.php |
— | — | @@ -1,69 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Special Page for Contribution statistics extension |
5 | | - * |
6 | | - * @file |
7 | | - * @ingroup Extensions |
8 | | - */ |
9 | | - |
10 | | -class SpecialYearlyTotal extends IncludableSpecialPage { |
11 | | - |
12 | | - protected $sharedMaxAge = 600; // Cache for 10 minutes on the server side |
13 | | - protected $maxAge = 600; // Cache for 10 minutes on the client side |
14 | | - |
15 | | - /* Functions */ |
16 | | - |
17 | | - public function __construct() { |
18 | | - parent::__construct( 'YearlyTotal' ); |
19 | | - } |
20 | | - |
21 | | - public function execute( $sub ) { |
22 | | - global $wgRequest, $wgOut, $egFundraiserStatisticsFundraisers; |
23 | | - |
24 | | - $js = $wgRequest->getBool( 'js', false ); |
25 | | - |
26 | | - $adjustment = $wgRequest->getVal( 'adjustment' ); |
27 | | - // Make sure it's a number |
28 | | - if ( is_nan( $adjustment ) ) { |
29 | | - $adjustment = 0; |
30 | | - } |
31 | | - |
32 | | - /* Setup */ |
33 | | - $wgOut->disable(); |
34 | | - $this->sendHeaders(); |
35 | | - |
36 | | - $total = $this->query( $adjustment ); |
37 | | - |
38 | | - $content = "wgFundraisingYearlyTotal = $total;"; |
39 | | - |
40 | | - if ( $js ) { |
41 | | - echo $content; |
42 | | - } else { |
43 | | - echo $total; |
44 | | - } |
45 | | - } |
46 | | - |
47 | | - /* Private Functions */ |
48 | | - |
49 | | - private function query( $adjustment ) { |
50 | | - global $egFundraiserStatisticsFundraisers; |
51 | | - |
52 | | - $currenctFundraiserIndex = count( $egFundraiserStatisticsFundraisers ) - 1; |
53 | | - $fundraiser = $egFundraiserStatisticsFundraisers[$currenctFundraiserIndex]['id']; |
54 | | - |
55 | | - $total = efContributionReportingTotal( $fundraiser, $adjustment ); |
56 | | - if ( !$total ) $total = 0; |
57 | | - |
58 | | - return $total; |
59 | | - } |
60 | | - |
61 | | - private function sendHeaders() { |
62 | | - global $wgJsMimeType; |
63 | | - header( "Content-type: $wgJsMimeType; charset=utf-8" ); |
64 | | - header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" ); |
65 | | - } |
66 | | - |
67 | | - public function isListed(){ |
68 | | - return false; |
69 | | - } |
70 | | -} |
Index: trunk/extensions/ContributionReporting/ContributionReporting.php |
— | — | @@ -41,9 +41,8 @@ |
42 | 42 | $wgAutoloadClasses['SpecialContributionStatistics'] = $dir . 'ContributionStatistics_body.php'; |
43 | 43 | $wgAutoloadClasses['SpecialFundraiserStatistics'] = $dir . 'FundraiserStatistics_body.php'; |
44 | 44 | $wgAutoloadClasses['SpecialContributionTrackingStatistics'] = $dir . 'ContributionTrackingStatistics_body.php'; |
45 | | -/* |
46 | 45 | $wgAutoloadClasses['SpecialDailyTotal'] = $dir . 'DailyTotal_body.php'; |
47 | | -$wgAutoloadClasses['SpecialYearlyTotal'] = $dir . 'YearlyTotal_body.php'; |
| 46 | +/* |
48 | 47 | $wgAutoloadClasses['DisabledNotice'] = $dir . 'DisabledNotice_body.php'; |
49 | 48 | */ |
50 | 49 | |
— | — | @@ -52,10 +51,7 @@ |
53 | 52 | $wgSpecialPages['ContributionStatistics'] = 'SpecialContributionStatistics'; |
54 | 53 | $wgSpecialPages['FundraiserStatistics'] = 'SpecialFundraiserStatistics'; |
55 | 54 | $wgSpecialPages['ContributionTrackingStatistics'] = 'SpecialContributionTrackingStatistics'; |
56 | | -/* |
57 | 55 | $wgSpecialPages['DailyTotal'] = 'SpecialDailyTotal'; |
58 | | -$wgSpecialPages['YearlyTotal'] = 'SpecialYearlyTotal'; |
59 | | -*/ |
60 | 56 | |
61 | 57 | $wgSpecialPageGroups['ContributionHistory'] = 'contribution'; |
62 | 58 | $wgSpecialPageGroups['ContributionTotal'] = 'contribution'; |
— | — | @@ -254,24 +250,7 @@ |
255 | 251 | if ( $row['total'] > 0 ) { |
256 | 252 | $total = $row['total']; |
257 | 253 | } else { |
258 | | - |
259 | | - // Try to get the total manually from public_reporting (more expensive) |
260 | | - $result = $dbr->select( |
261 | | - 'public_reporting', |
262 | | - 'round( sum( converted_amount ) ) AS total', |
263 | | - array( |
264 | | - 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $myFundraiser['start'] ) ) ), |
265 | | - 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $myFundraiser['end'] ) + 24 * 60 * 60 ) ), |
266 | | - ), |
267 | | - __METHOD__ |
268 | | - ); |
269 | | - $row = $dbr->fetchRow( $result ); |
270 | | - |
271 | | - if ( $row['total'] > 0 ) { |
272 | | - $total = $row['total']; |
273 | | - } else { |
274 | | - return 0; |
275 | | - } |
| 254 | + $total = 0; |
276 | 255 | } |
277 | 256 | |
278 | 257 | // Make sure the fudge factor is a number |
Index: trunk/extensions/ContributionReporting/ContributionTrackingStatistics_body.php |
— | — | @@ -19,6 +19,10 @@ |
20 | 20 | |
21 | 21 | public function execute( $sub ) { |
22 | 22 | global $wgOut, $wgRequest; |
| 23 | + |
| 24 | + # Emergecny short cut until this is back in working order |
| 25 | + $wgOut->redirect( SpecialPage::getTitleFor( 'FundraiserStatistics' )->getFullURL() ); |
| 26 | + return; |
23 | 27 | |
24 | 28 | $start = $wgRequest->getIntOrNull( 'start' ); |
25 | 29 | $end = $wgRequest->getIntOrNull( 'end' ); |
Index: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php |
— | — | @@ -328,58 +328,27 @@ |
329 | 329 | // Set timezone to UTC just in case |
330 | 330 | date_default_timezone_set( 'UTC' ); |
331 | 331 | |
332 | | - // If the summary table exists, use that, otherwise compute from scratch |
333 | | - if ( mysql_num_rows( mysql_query( "SHOW TABLES LIKE 'public_reporting_days'" ) ) ) { |
| 332 | + $conditions = array( |
| 333 | + 'prd_date >= ' . $dbr->addQuotes( wfTimestamp( TS_DB, strtotime( $start ) ) ), |
| 334 | + 'prd_date <= ' . $dbr->addQuotes( wfTimestamp( TS_DB, strtotime( $end ) ) ), |
| 335 | + ); |
334 | 336 | |
335 | | - $conditions = array( |
336 | | - 'prd_date >= ' . $dbr->addQuotes( wfTimestamp( TS_DB, strtotime( $start ) ) ), |
337 | | - 'prd_date <= ' . $dbr->addQuotes( wfTimestamp( TS_DB, strtotime( $end ) ) ), |
338 | | - ); |
339 | | - |
340 | | - // Get the data for a fundraiser |
341 | | - $select = $dbr->select( 'public_reporting_days', |
342 | | - array( |
343 | | - 'prd_date', |
344 | | - 'prd_total', |
345 | | - 'prd_number', |
346 | | - 'prd_average', |
347 | | - 'prd_maximum', |
348 | | - ), |
349 | | - $conditions, |
350 | | - __METHOD__, |
351 | | - array( |
352 | | - 'ORDER BY' => 'prd_date', |
353 | | - ) |
354 | | - ); |
355 | | - |
356 | | - } else { |
357 | | - |
358 | | - $conditions = array( |
359 | | - 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) ) ), |
360 | | - 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $end ) + 24 * 60 * 60 ) ), |
361 | | - 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
362 | | - 'converted_amount <= ' . $egFundraiserStatisticsMaximum, |
363 | | - ); |
| 337 | + // Get the data for a fundraiser |
| 338 | + $select = $dbr->select( 'public_reporting_days', |
| 339 | + array( |
| 340 | + 'prd_date', |
| 341 | + 'prd_total', |
| 342 | + 'prd_number', |
| 343 | + 'prd_average', |
| 344 | + 'prd_maximum', |
| 345 | + ), |
| 346 | + $conditions, |
| 347 | + __METHOD__, |
| 348 | + array( |
| 349 | + 'ORDER BY' => 'prd_date', |
| 350 | + ) |
| 351 | + ); |
364 | 352 | |
365 | | - // Get the data for a fundraiser |
366 | | - $select = $dbr->select( 'public_reporting', |
367 | | - array( |
368 | | - "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')", |
369 | | - 'sum(converted_amount)', |
370 | | - 'count(*)', |
371 | | - 'avg(converted_amount)', |
372 | | - 'max(converted_amount)', |
373 | | - ), |
374 | | - $conditions, |
375 | | - __METHOD__, |
376 | | - array( |
377 | | - 'ORDER BY' => 'received', |
378 | | - 'GROUP BY' => "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')" |
379 | | - ) |
380 | | - ); |
381 | | - |
382 | | - } |
383 | | - |
384 | 353 | $result = array(); |
385 | 354 | $ytd = 0; |
386 | 355 | while ( $row = $dbr->fetchRow( $select ) ) { |
Index: trunk/extensions/ContributionReporting/ContributionHistory_body.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | // Paging controls |
32 | 32 | $newer = $db->selectField( 'public_reporting', 'received', |
33 | 33 | array_merge( |
34 | | - array( 'received > ' . strtotime( 'July 1st 2008' ) ), |
| 34 | + array( 'received > ' . strtotime( 'July 1st 2011' ) ), |
35 | 35 | ( $offset !== null ? array( 'received > ' . $offset ) : array() ) |
36 | 36 | ), |
37 | 37 | __METHOD__, |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | ); |
44 | 44 | $older = $db->selectField( 'public_reporting', 'received', |
45 | 45 | array_merge( |
46 | | - array( 'received > ' . strtotime( 'July 1st 2008' ) ), |
| 46 | + array( 'received > ' . strtotime( 'July 1st 2011' ) ), |
47 | 47 | ( $offset !== null ? array( 'received <= ' . $offset ) : array() ) |
48 | 48 | ), |
49 | 49 | __METHOD__, |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | |
87 | 87 | if ( $offset == null ) { |
88 | 88 | $offset = $db->selectField( 'public_reporting', 'received', |
89 | | - array( 'received > ' . strtotime( 'July 1st 2008' ) ), |
| 89 | + array( 'received > ' . strtotime( 'July 1st 2011' ) ), |
90 | 90 | __METHOD__, |
91 | 91 | array( |
92 | 92 | 'ORDER BY' => 'received DESC', |
— | — | @@ -98,7 +98,7 @@ |
99 | 99 | |
100 | 100 | $res = $db->select( 'public_reporting', '*', |
101 | 101 | array_merge( |
102 | | - array( 'received > ' . strtotime( 'July 1st 2008' ) ), |
| 102 | + array( 'received > ' . strtotime( 'July 1st 2011' ) ), |
103 | 103 | ( $offset !== null ? array( 'received <= ' . $offset ) : array() ) |
104 | 104 | ), |
105 | 105 | __METHOD__, |
Index: trunk/extensions/ContributionReporting/ContributionTotal_body.php |
— | — | @@ -1,23 +1,33 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class ContributionTotal extends SpecialPage { |
| 4 | +class ContributionTotal extends UnlistedSpecialPage { |
| 5 | + |
| 6 | + protected $sharedMaxAge = 300; // Cache for 5 minutes on the server side |
| 7 | + protected $maxAge = 300; // Cache for 5 minutes on the client side |
| 8 | + |
5 | 9 | function __construct() { |
6 | 10 | parent::__construct( 'ContributionTotal' ); |
7 | 11 | } |
8 | 12 | |
9 | 13 | function execute( $par ) { |
10 | | - global $wgRequest, $wgOut; |
| 14 | + global $wgRequest, $wgOut, $egFundraiserStatisticsFundraisers; |
11 | 15 | |
12 | 16 | $this->setHeaders(); |
13 | 17 | |
14 | | - # Get request data |
15 | | - $fundraiser = $wgRequest->getText( 'fundraiser' ); |
| 18 | + // Get request data |
| 19 | + $fundraiserId = $wgRequest->getText( 'fundraiser' ); |
16 | 20 | $action = $wgRequest->getText( 'action' ); |
17 | | - $fudgeFactor = $wgRequest->getInt( 'fudgefactor' ); |
| 21 | + $fudgeFactor = $wgRequest->getInt( 'adjustment' ); |
| 22 | + |
| 23 | + // If no fundraiser was specified, use the most recent |
| 24 | + if ( !$fundraiserId ) { |
| 25 | + $mostRecentFundraiser = end( $egFundraiserStatisticsFundraisers ); |
| 26 | + $fundraiserId = $mostRecentFundraiser['id']; |
| 27 | + } |
18 | 28 | |
19 | | - $output = efContributionReportingTotal( $fundraiser, $fudgeFactor ); |
| 29 | + $output = efContributionReportingTotal( $fundraiserId, $fudgeFactor ); |
20 | 30 | |
21 | | - header( 'Cache-Control: max-age=300,s-maxage=300' ); |
| 31 | + header( "Cache-Control: max-age=$this->maxAge,s-maxage=$this->sharedMaxAge" ); |
22 | 32 | if ( $action == 'raw' ) { |
23 | 33 | $wgOut->disable(); |
24 | 34 | echo $output; |
Index: trunk/extensions/ContributionReporting/DailyTotal_body.php |
— | — | @@ -6,13 +6,11 @@ |
7 | 7 | * @ingroup Extensions |
8 | 8 | */ |
9 | 9 | |
10 | | -class SpecialDailyTotal extends IncludableSpecialPage { |
| 10 | +class SpecialDailyTotal extends UnlistedSpecialPage { |
11 | 11 | |
12 | | - protected $sharedMaxAge = 600; // Cache for 10 minutes on the server side |
13 | | - protected $maxAge = 600; // Cache for 10 minutes on the client side |
| 12 | + protected $sharedMaxAge = 300; // Cache for 5 minutes on the server side |
| 13 | + protected $maxAge = 300; // Cache for 5 minutes on the client side |
14 | 14 | |
15 | | - /* Functions */ |
16 | | - |
17 | 15 | public function __construct() { |
18 | 16 | parent::__construct( 'DailyTotal' ); |
19 | 17 | } |
— | — | @@ -20,13 +18,12 @@ |
21 | 19 | public function execute( $sub ) { |
22 | 20 | global $wgRequest, $wgOut; |
23 | 21 | |
24 | | - $js = $wgRequest->getBool( 'js', false ); |
25 | | - |
| 22 | + $this->setHeaders(); |
| 23 | + |
| 24 | + // Get request data |
| 25 | + $action = $wgRequest->getText( 'action' ); |
| 26 | + $fudgeFactor = $wgRequest->getInt( 'adjustment' ); |
26 | 27 | $timezone = $wgRequest->getText( 'timezone', '0' ); |
27 | | - |
28 | | - /* Setup */ |
29 | | - $wgOut->disable(); |
30 | | - $this->sendHeaders(); |
31 | 28 | |
32 | 29 | $zoneList = array ( |
33 | 30 | '-12' => array( 'name' => 'Kwajalein', 'offset' => '-12:00' ), |
— | — | @@ -79,64 +76,68 @@ |
80 | 77 | } |
81 | 78 | |
82 | 79 | $setTimeZone = date_default_timezone_set( $timeZoneName ); |
83 | | - $start = date( 'Y-m-d' ); // Get the current date in the requested timezone |
84 | | - $total = $this->query( $timeZoneOffset, $start ); |
85 | | - |
86 | | - $content = "wgFundraisingDailyTotal = $total;"; |
87 | | - |
88 | | - if ( $js ) { |
89 | | - echo $content; |
| 80 | + $today = date( 'Y-m-d' ); // Get the current date in the requested timezone |
| 81 | + $output = $this->getTodaysTotal( $timeZoneOffset, $today, $fudgeFactor ); |
| 82 | + |
| 83 | + header( "Cache-Control: max-age=$this->maxAge,s-maxage=$this->sharedMaxAge" ); |
| 84 | + if ( $action == 'raw' ) { |
| 85 | + $wgOut->disable(); |
| 86 | + echo $output; |
90 | 87 | } else { |
91 | | - echo $total; |
| 88 | + $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
| 89 | + $wgOut->addHTML( $output ); |
92 | 90 | } |
93 | 91 | } |
94 | 92 | |
95 | 93 | /* Private Functions */ |
96 | 94 | |
97 | | - private function query( $timeZoneOffset, $start ) { |
| 95 | + /** |
| 96 | + * Get the total amount of money raised for today |
| 97 | + * @param string $timeZoneOffset The timezone to request the total for |
| 98 | + * @param string $today The current date in the requested time zone, e.g. '2011-12-16' |
| 99 | + * @param int $fudgeFactor How much to adjust the total by |
| 100 | + * @return integer |
| 101 | + */ |
| 102 | + private function getTodaysTotal( $timeZoneOffset, $today, $fudgeFactor = 0 ) { |
98 | 103 | global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout; |
99 | 104 | |
100 | | - $key = wfMemcKey( 'fundraiserstatistics', $timeZoneOffset, $start ); |
| 105 | + // Delete this block once there is timezone support in the populating script |
| 106 | + $setTimeZone = date_default_timezone_set( 'UTC' ); |
| 107 | + $today = date( 'Y-m-d' ); // Get the current date in UTC |
| 108 | + $timeZoneOffset = '+00:00'; |
| 109 | + |
| 110 | + $key = wfMemcKey( 'fundraiserdailytotal', $timeZoneOffset, $today, $fudgeFactor ); |
101 | 111 | $cache = $wgMemc->get( $key ); |
102 | 112 | if ( $cache != false && $cache != -1 ) { |
103 | 113 | return $cache; |
104 | 114 | } |
105 | 115 | |
106 | | - // We're only interested in donations from the past 2 days at most |
107 | | - $recentTime = time() - 60 * 60 * 48; |
108 | | - |
109 | 116 | // Use database |
110 | 117 | $dbr = efContributionReportingConnection(); |
111 | | - #$dbr = wfGetDB( DB_MASTER ); |
112 | | - $conditions = array( |
113 | | - 'received > ' . $recentTime, |
114 | | - 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
115 | | - 'converted_amount <= ' . $egFundraiserStatisticsMaximum, |
116 | | - "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$timeZoneOffset'),'%Y-%m-%d') = '$start'" |
117 | | - ); |
118 | 118 | |
119 | | - $select = $dbr->select( 'public_reporting', |
120 | | - array( |
121 | | - 'sum(converted_amount)' |
122 | | - ), |
123 | | - $conditions, |
| 119 | + $result = $dbr->select( |
| 120 | + 'public_reporting_days', |
| 121 | + 'round( prd_total ) AS total', |
| 122 | + "prd_date = '$today'", |
124 | 123 | __METHOD__ |
125 | 124 | ); |
126 | | - $row = $dbr->fetchRow( $select ); |
127 | | - $total = $row['sum(converted_amount)']; |
128 | | - if ( !$total ) $total = 0; |
| 125 | + $row = $dbr->fetchRow( $result ); |
129 | 126 | |
| 127 | + if ( $row['total'] > 0 ) { |
| 128 | + $total = $row['total']; |
| 129 | + } else { |
| 130 | + $total = 0; |
| 131 | + } |
| 132 | + |
| 133 | + // Make sure the fudge factor is a number |
| 134 | + if ( is_nan( $fudgeFactor ) ) { |
| 135 | + $fudgeFactor = 0; |
| 136 | + } |
| 137 | + |
| 138 | + // Add the fudge factor to the total |
| 139 | + $total += $fudgeFactor; |
| 140 | + |
130 | 141 | $wgMemc->set( $key, $total, $egFundraiserStatisticsCacheTimeout ); |
131 | 142 | return $total; |
132 | 143 | } |
133 | | - |
134 | | - private function sendHeaders() { |
135 | | - global $wgJsMimeType; |
136 | | - header( "Content-type: $wgJsMimeType; charset=utf-8" ); |
137 | | - header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" ); |
138 | | - } |
139 | | - |
140 | | - public function isListed(){ |
141 | | - return false; |
142 | | - } |
143 | 144 | } |
Index: trunk/extensions/ContributionReporting/ContributionReporting.i18n.php |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | // ContributionReporting and ContributionTotal |
17 | 17 | 'contributionreporting-desc' => 'Live reporting on the Wikimedia fundraiser', |
18 | 18 | 'contributiontotal' => 'Contribution total', |
| 19 | + 'dailytotal' => 'Daily total', |
19 | 20 | |
20 | 21 | 'contribstats-header' => '', |
21 | 22 | 'contribstats-footer' => '', |
Index: trunk/extensions/ContributionReporting/ContributionStatistics_body.php |
— | — | @@ -24,6 +24,11 @@ |
25 | 25 | |
26 | 26 | public function execute( $sub ) { |
27 | 27 | global $wgOut,$egContributionStatisticsViewDays; |
| 28 | + |
| 29 | + # Emergecny short cut until this can be changed to use cron-generated data |
| 30 | + # These queries are too expensive to run on demand. |
| 31 | + $wgOut->redirect( SpecialPage::getTitleFor( 'FundraiserStatistics' )->getFullURL() ); |
| 32 | + return; |
28 | 33 | |
29 | 34 | $this->evalDateRange(); |
30 | 35 | |