Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionReporting.php |
— | — | @@ -41,12 +41,16 @@ |
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 | +$wgAutoloadClasses['SpecialDailyTotal'] = $dir . 'DailyTotal_body.php'; |
| 46 | +$wgAutoloadClasses['SpecialYearlyTotal'] = $dir . 'YearlyTotal_body.php'; |
45 | 47 | |
46 | 48 | $wgSpecialPages['ContributionHistory'] = 'ContributionHistory'; |
47 | 49 | $wgSpecialPages['ContributionTotal'] = 'ContributionTotal'; |
48 | 50 | $wgSpecialPages['ContributionStatistics'] = 'SpecialContributionStatistics'; |
49 | 51 | $wgSpecialPages['FundraiserStatistics'] = 'SpecialFundraiserStatistics'; |
50 | 52 | $wgSpecialPages['ContributionTrackingStatistics'] = 'SpecialContributionTrackingStatistics'; |
| 53 | +$wgSpecialPages['DailyTotal'] = 'SpecialDailyTotal'; |
| 54 | +$wgSpecialPages['YearlyTotal'] = 'SpecialYearlyTotal'; |
51 | 55 | $wgSpecialPageGroups['ContributionHistory'] = 'contribution'; |
52 | 56 | $wgSpecialPageGroups['ContributionTotal'] = 'contribution'; |
53 | 57 | $wgSpecialPageGroups['ContributionStatistics'] = 'contribution'; |
— | — | @@ -65,6 +69,7 @@ |
66 | 70 | $egContributionStatisticsViewDays = 7; |
67 | 71 | |
68 | 72 | // Fundraiser dates |
| 73 | +// Please list these in chronological order |
69 | 74 | $egFundraiserStatisticsFundraisers = array( |
70 | 75 | array( |
71 | 76 | 'id' => '2007', |
— | — | @@ -160,6 +165,7 @@ |
161 | 166 | |
162 | 167 | function efContributionReportingTotal( $start, $fudgeFactor ) { |
163 | 168 | $db = efContributionReportingConnection(); |
| 169 | + #$db = wfGetDB( DB_MASTER ); |
164 | 170 | |
165 | 171 | $sql = 'SELECT ROUND( SUM(converted_amount) ) AS ttl FROM public_reporting'; |
166 | 172 | |
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionReporting.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
167 | 173 | Merged /trunk/extensions/ContributionReporting/ContributionReporting.php:r103884,103947,103959,103967,103991,103996 |
Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/DailyTotal_body.php |
— | — | @@ -0,0 +1,137 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special Page for Contribution statistics extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class SpecialDailyTotal extends IncludableSpecialPage { |
| 11 | + |
| 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 | + |
| 15 | + /* Functions */ |
| 16 | + |
| 17 | + public function __construct() { |
| 18 | + parent::__construct( 'DailyTotal' ); |
| 19 | + } |
| 20 | + |
| 21 | + public function execute( $sub ) { |
| 22 | + global $wgRequest, $wgOut; |
| 23 | + |
| 24 | + $js = $wgRequest->getBool( 'js', false ); |
| 25 | + |
| 26 | + $timezone = $wgRequest->getText( 'timezone', '0' ); |
| 27 | + |
| 28 | + /* Setup */ |
| 29 | + $wgOut->disable(); |
| 30 | + $this->sendHeaders(); |
| 31 | + |
| 32 | + $zoneList = array ( |
| 33 | + '-12' => array( 'name' => 'Kwajalein', 'offset' => '-12:00' ), |
| 34 | + '-11' => array( 'name' => 'Pacific/Midway', 'offset' => '-11:00' ), |
| 35 | + '-10' => array( 'name' => 'Pacific/Honolulu', 'offset' => '-10:00' ), |
| 36 | + '-9' => array( 'name' => 'America/Anchorage', 'offset' => '-09:00' ), |
| 37 | + '-8' => array( 'name' => 'America/Los_Angeles', 'offset' => '-08:00' ), |
| 38 | + '-7' => array( 'name' => 'America/Denver', 'offset' => '-07:00' ), |
| 39 | + '-6' => array( 'name' => 'America/Tegucigalpa', 'offset' => '-06:00' ), |
| 40 | + '-5' => array( 'name' => 'America/New_York', 'offset' => '-05:00' ), |
| 41 | + '-4.5' => array( 'name' => 'America/Caracas', 'offset' => '-04:30' ), |
| 42 | + '-4' => array( 'name' => 'America/Halifax', 'offset' => '-04:00' ), |
| 43 | + '-3.5' => array( 'name' => 'America/St_Johns', 'offset' => '-03:30' ), |
| 44 | + '-3' => array( 'name' => 'America/Sao_Paulo', 'offset' => '-03:00' ), |
| 45 | + '-2' => array( 'name' => 'Atlantic/South_Georgia', 'offset' => '-02:00' ), |
| 46 | + '-1' => array( 'name' => 'Atlantic/Azores', 'offset' => '-01:00' ), |
| 47 | + '0' => array( 'name' => 'UTC', 'offset' => '+00:00' ), |
| 48 | + '1' => array( 'name' => 'Europe/Belgrade', 'offset' => '+01:00' ), |
| 49 | + '2' => array( 'name' => 'Europe/Minsk', 'offset' => '+02:00' ), |
| 50 | + '3' => array( 'name' => 'Asia/Kuwait', 'offset' => '+03:00' ), |
| 51 | + '3.5' => array( 'name' => 'Asia/Tehran', 'offset' => '+03:30' ), |
| 52 | + '4' => array( 'name' => 'Asia/Muscat', 'offset' => '+04:00' ), |
| 53 | + '5' => array( 'name' => 'Asia/Yekaterinburg', 'offset' => '+05:00' ), |
| 54 | + '5.5' => array( 'name' => 'Asia/Kolkata', 'offset' => '+05:30' ), |
| 55 | + '5.75' => array( 'name' => 'Asia/Katmandu', 'offset' => '+05:45' ), |
| 56 | + '6' => array( 'name' => 'Asia/Dhaka', 'offset' => '+06:00' ), |
| 57 | + '6.5' => array( 'name' => 'Asia/Rangoon', 'offset' => '+06:30' ), |
| 58 | + '7' => array( 'name' => 'Asia/Krasnoyarsk', 'offset' => '+07:00' ), |
| 59 | + '8' => array( 'name' => 'Asia/Brunei', 'offset' => '+08:00' ), |
| 60 | + '9' => array( 'name' => 'Asia/Seoul', 'offset' => '+09:00' ), |
| 61 | + '9.5' => array( 'name' => 'Australia/Darwin', 'offset' => '+09:30' ), |
| 62 | + '10' => array( 'name' => 'Australia/Canberra', 'offset' => '+10:00' ), |
| 63 | + '11' => array( 'name' => 'Asia/Magadan', 'offset' => '+11:00' ), |
| 64 | + '12' => array( 'name' => 'Pacific/Fiji', 'offset' => '+12:00' ), |
| 65 | + '13' => array( 'name' => 'Pacific/Tongatapu', 'offset' => '+13:00' ), |
| 66 | + ); |
| 67 | + |
| 68 | + // Translate timezone param to timezone name for PHP |
| 69 | + if ( array_key_exists( $timezone, $zoneList ) ) { |
| 70 | + $timeZoneName = $zoneList[$timezone]['name']; |
| 71 | + } else { |
| 72 | + $timeZoneName = 'UTC'; |
| 73 | + } |
| 74 | + |
| 75 | + // Translate timezone param to timezone offset for MySQL |
| 76 | + if ( array_key_exists( $timezone, $zoneList ) ) { |
| 77 | + $timeZoneOffset = $zoneList[$timezone]['offset']; |
| 78 | + } else { |
| 79 | + $timeZoneOffset = '+00:00'; |
| 80 | + } |
| 81 | + |
| 82 | + $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; |
| 90 | + } else { |
| 91 | + echo $total; |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + /* Private Functions */ |
| 96 | + |
| 97 | + private function query( $timeZoneOffset, $start ) { |
| 98 | + global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout; |
| 99 | + |
| 100 | + $key = wfMemcKey( 'fundraiserstatistics', $timeZoneOffset, $start ); |
| 101 | + $cache = $wgMemc->get( $key ); |
| 102 | + if ( $cache != false && $cache != -1 ) { |
| 103 | + return $cache; |
| 104 | + } |
| 105 | + |
| 106 | + // Use database |
| 107 | + $dbr = efContributionReportingConnection(); |
| 108 | + #$dbr = wfGetDB( DB_MASTER ); |
| 109 | + $conditions = array( |
| 110 | + 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
| 111 | + 'converted_amount <= ' . $egFundraiserStatisticsMaximum, |
| 112 | + "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$timeZoneOffset'),'%Y-%m-%d') = '$start'" |
| 113 | + ); |
| 114 | + |
| 115 | + $select = $dbr->select( 'public_reporting', |
| 116 | + array( |
| 117 | + 'sum(converted_amount)' |
| 118 | + ), |
| 119 | + $conditions, |
| 120 | + __METHOD__, |
| 121 | + array( |
| 122 | + 'ORDER BY' => 'received' |
| 123 | + ) |
| 124 | + ); |
| 125 | + $row = $dbr->fetchRow( $select ); |
| 126 | + $total = $row['sum(converted_amount)']; |
| 127 | + if ( !$total ) $total = 0; |
| 128 | + |
| 129 | + $wgMemc->set( $key, $total, $egFundraiserStatisticsCacheTimeout ); |
| 130 | + return $total; |
| 131 | + } |
| 132 | + |
| 133 | + private function sendHeaders() { |
| 134 | + global $wgJsMimeType; |
| 135 | + header( "Content-type: $wgJsMimeType; charset=utf-8" ); |
| 136 | + header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" ); |
| 137 | + } |
| 138 | +} |
Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/YearlyTotal_body.php |
— | — | @@ -0,0 +1,77 @@ |
| 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 $wgMemc, $egFundraiserStatisticsCacheTimeout, $egFundraiserStatisticsFundraisers; |
| 51 | + |
| 52 | + $currenctFundraiserIndex = count( $egFundraiserStatisticsFundraisers ) - 1; |
| 53 | + $year = $egFundraiserStatisticsFundraisers[$currenctFundraiserIndex]['id']; |
| 54 | + |
| 55 | + $key = wfMemcKey( 'fundraiserstatistics', $year, $adjustment ); |
| 56 | + $cache = $wgMemc->get( $key ); |
| 57 | + if ( $cache != false && $cache != -1 ) { |
| 58 | + return $cache; |
| 59 | + } |
| 60 | + |
| 61 | + // Get the timestamp for the start of the current fundraiser |
| 62 | + // Note: This depends on the fundraisers being listed in chronological order |
| 63 | + $start = strtotime( $egFundraiserStatisticsFundraisers[$currenctFundraiserIndex]['start'] ); |
| 64 | + $start = intval( wfTimestampOrNull( TS_UNIX, $start ) ); |
| 65 | + |
| 66 | + $total = efContributionReportingTotal( $start, $adjustment ); |
| 67 | + if ( !$total ) $total = 0; |
| 68 | + |
| 69 | + $wgMemc->set( $key, $total, $egFundraiserStatisticsCacheTimeout ); |
| 70 | + return $total; |
| 71 | + } |
| 72 | + |
| 73 | + private function sendHeaders() { |
| 74 | + global $wgJsMimeType; |
| 75 | + header( "Content-type: $wgJsMimeType; charset=utf-8" ); |
| 76 | + header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" ); |
| 77 | + } |
| 78 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting |
___________________________________________________________________ |
Modified: svn:mergeinfo |
1 | 79 | Merged /trunk/extensions/ContributionReporting:r103884,103947,103959,103967,103991,103996 |