Index: trunk/extensions/ContributionReporting/DailyTotal_body.php |
— | — | @@ -22,84 +22,65 @@ |
23 | 23 | |
24 | 24 | $js = $wgRequest->getBool( 'js', false ); |
25 | 25 | |
26 | | - $timezone = $wgRequest->getText( 'timezone', '0:00' ); |
| 26 | + $timezone = $wgRequest->getText( 'timezone', '0' ); |
27 | 27 | |
28 | 28 | /* Setup */ |
29 | 29 | $wgOut->disable(); |
30 | 30 | $this->sendHeaders(); |
31 | 31 | |
32 | 32 | $zoneList = array ( |
33 | | - '-12:00' => 'Kwajalein', |
34 | | - '-11:00' => 'Pacific/Midway', |
35 | | - '-10:00' => 'Pacific/Honolulu', |
36 | | - '-9:00' => 'America/Anchorage', |
37 | | - '-09:00' => 'America/Anchorage', |
38 | | - '-8:00' => 'America/Los_Angeles', |
39 | | - '-08:00' => 'America/Los_Angeles', |
40 | | - '-7:00' => 'America/Denver', |
41 | | - '-07:00' => 'America/Denver', |
42 | | - '-6:00' => 'America/Tegucigalpa', |
43 | | - '-06:00' => 'America/Tegucigalpa', |
44 | | - '-5:00' => 'America/New_York', |
45 | | - '-05:00' => 'America/New_York', |
46 | | - '-4:30' => 'America/Caracas', |
47 | | - '-04:30' => 'America/Caracas', |
48 | | - '-4:00' => 'America/Halifax', |
49 | | - '-04:00' => 'America/Halifax', |
50 | | - '-3:30' => 'America/St_Johns', |
51 | | - '-03:30' => 'America/St_Johns', |
52 | | - '-3:00' => 'America/Sao_Paulo', |
53 | | - '-03:00' => 'America/Sao_Paulo', |
54 | | - '-2:00' => 'Atlantic/South_Georgia', |
55 | | - '-02:00' => 'Atlantic/South_Georgia', |
56 | | - '-1:00' => 'Atlantic/Azores', |
57 | | - '-01:00' => 'Atlantic/Azores', |
58 | | - '0:00' => 'UTC', |
59 | | - '00:00' => 'UTC', |
60 | | - '1:00' => 'Europe/Belgrade', |
61 | | - '01:00' => 'Europe/Belgrade', |
62 | | - '2:00' => 'Europe/Minsk', |
63 | | - '02:00' => 'Europe/Minsk', |
64 | | - '3:00' => 'Asia/Kuwait', |
65 | | - '03:00' => 'Asia/Kuwait', |
66 | | - '3:30' => 'Asia/Tehran', |
67 | | - '03:30' => 'Asia/Tehran', |
68 | | - '4:00' => 'Asia/Muscat', |
69 | | - '04:00' => 'Asia/Muscat', |
70 | | - '5:00' => 'Asia/Yekaterinburg', |
71 | | - '05:00' => 'Asia/Yekaterinburg', |
72 | | - '5:30' => 'Asia/Kolkata', |
73 | | - '05:30' => 'Asia/Kolkata', |
74 | | - '5:45' => 'Asia/Katmandu', |
75 | | - '05:45' => 'Asia/Katmandu', |
76 | | - '6:00' => 'Asia/Dhaka', |
77 | | - '06:00' => 'Asia/Dhaka', |
78 | | - '6:30' => 'Asia/Rangoon', |
79 | | - '06:30' => 'Asia/Rangoon', |
80 | | - '7:00' => 'Asia/Krasnoyarsk', |
81 | | - '07:00' => 'Asia/Krasnoyarsk', |
82 | | - '8:00' => 'Asia/Brunei', |
83 | | - '08:00' => 'Asia/Brunei', |
84 | | - '9:00' => 'Asia/Seoul', |
85 | | - '09:00' => 'Asia/Seoul', |
86 | | - '9:30' => 'Australia/Darwin', |
87 | | - '09:30' => 'Australia/Darwin', |
88 | | - '10:00' => 'Australia/Canberra', |
89 | | - '11:00' => 'Asia/Magadan', |
90 | | - '12:00' => 'Pacific/Fiji', |
91 | | - '13:00' => 'Pacific/Tongatapu', |
| 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' ), |
92 | 66 | ); |
93 | 67 | |
94 | | - // Translate offset to timezone name for PHP |
| 68 | + // Translate timezone param to timezone name for PHP |
95 | 69 | if ( array_key_exists( $timezone, $zoneList ) ) { |
96 | | - $timeZoneName = $zoneList[$timezone]; |
| 70 | + $timeZoneName = $zoneList[$timezone]['name']; |
97 | 71 | } else { |
98 | 72 | $timeZoneName = 'UTC'; |
99 | 73 | } |
100 | 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 | + |
101 | 82 | $setTimeZone = date_default_timezone_set( $timeZoneName ); |
102 | 83 | $start = date( 'Y-m-d' ); // Get the current date in the requested timezone |
103 | | - $total = $this->query( $timezone, $start ); |
| 84 | + $total = $this->query( $timeZoneOffset, $start ); |
104 | 85 | |
105 | 86 | $content = "wgFundraisingDailyTotal = $total;"; |
106 | 87 | |
— | — | @@ -112,10 +93,10 @@ |
113 | 94 | |
114 | 95 | /* Private Functions */ |
115 | 96 | |
116 | | - private function query( $timezone, $start ) { |
| 97 | + private function query( $timeZoneOffset, $start ) { |
117 | 98 | global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout; |
118 | 99 | |
119 | | - $key = wfMemcKey( 'fundraiserstatistics', $timezone, $start ); |
| 100 | + $key = wfMemcKey( 'fundraiserstatistics', $timeZoneOffset, $start ); |
120 | 101 | $cache = $wgMemc->get( $key ); |
121 | 102 | if ( $cache != false && $cache != -1 ) { |
122 | 103 | return $cache; |
— | — | @@ -127,7 +108,7 @@ |
128 | 109 | $conditions = array( |
129 | 110 | 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
130 | 111 | 'converted_amount <= ' . $egFundraiserStatisticsMaximum, |
131 | | - "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$timezone'),'%Y-%m-%d') = '$start'" |
| 112 | + "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$timeZoneOffset'),'%Y-%m-%d') = '$start'" |
132 | 113 | ); |
133 | 114 | |
134 | 115 | $select = $dbr->select( 'public_reporting', |