r103998 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103997‎ | r103998 | r103999 >
Date:01:24, 23 November 2011
Author:awjrichards
Status:reverted
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/ContributionReporting (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionReporting.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionStatistics_body.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionTotal_body.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ContributionReporting/DailyTotal_body.php (added) (history)
  • /branches/wmf/1.18wmf1/extensions/ContributionReporting/FundraiserStatistics_body.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/ContributionReporting/YearlyTotal_body.php (added) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionReporting.php
@@ -41,12 +41,16 @@
4242 $wgAutoloadClasses['SpecialContributionStatistics'] = $dir . 'ContributionStatistics_body.php';
4343 $wgAutoloadClasses['SpecialFundraiserStatistics'] = $dir . 'FundraiserStatistics_body.php';
4444 $wgAutoloadClasses['SpecialContributionTrackingStatistics'] = $dir . 'ContributionTrackingStatistics_body.php';
 45+$wgAutoloadClasses['SpecialDailyTotal'] = $dir . 'DailyTotal_body.php';
 46+$wgAutoloadClasses['SpecialYearlyTotal'] = $dir . 'YearlyTotal_body.php';
4547
4648 $wgSpecialPages['ContributionHistory'] = 'ContributionHistory';
4749 $wgSpecialPages['ContributionTotal'] = 'ContributionTotal';
4850 $wgSpecialPages['ContributionStatistics'] = 'SpecialContributionStatistics';
4951 $wgSpecialPages['FundraiserStatistics'] = 'SpecialFundraiserStatistics';
5052 $wgSpecialPages['ContributionTrackingStatistics'] = 'SpecialContributionTrackingStatistics';
 53+$wgSpecialPages['DailyTotal'] = 'SpecialDailyTotal';
 54+$wgSpecialPages['YearlyTotal'] = 'SpecialYearlyTotal';
5155 $wgSpecialPageGroups['ContributionHistory'] = 'contribution';
5256 $wgSpecialPageGroups['ContributionTotal'] = 'contribution';
5357 $wgSpecialPageGroups['ContributionStatistics'] = 'contribution';
@@ -65,6 +69,7 @@
6670 $egContributionStatisticsViewDays = 7;
6771
6872 // Fundraiser dates
 73+// Please list these in chronological order
6974 $egFundraiserStatisticsFundraisers = array(
7075 array(
7176 'id' => '2007',
@@ -160,6 +165,7 @@
161166
162167 function efContributionReportingTotal( $start, $fudgeFactor ) {
163168 $db = efContributionReportingConnection();
 169+ #$db = wfGetDB( DB_MASTER );
164170
165171 $sql = 'SELECT ROUND( SUM(converted_amount) ) AS ttl FROM public_reporting';
166172
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionReporting.php
___________________________________________________________________
Modified: svn:mergeinfo
167173 Merged /trunk/extensions/ContributionReporting/ContributionReporting.php:r103884,103947,103959,103967,103991,103996
Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/FundraiserStatistics_body.php
@@ -15,7 +15,7 @@
1616 }
1717
1818 public function execute( $sub ) {
19 - global $wgRequest, $wgOut, $wgUser, $wgLang, $wgScriptPath, $egFundraiserStatisticsFundraisers;
 19+ global $wgOut, $wgLang, $wgScriptPath, $egFundraiserStatisticsFundraisers;
2020
2121 $showYear = array();
2222 foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) {
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting/FundraiserStatistics_body.php
___________________________________________________________________
Modified: svn:mergeinfo
2323 Merged /trunk/extensions/ContributionReporting/FundraiserStatistics_body.php:r75680
Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionTotal_body.php
@@ -8,8 +8,6 @@
99 function execute( $par ) {
1010 global $wgRequest, $wgOut;
1111
12 - wfLoadExtensionMessages( 'ContributionReporting' );
13 -
1412 $this->setHeaders();
1513
1614 # Get request data from, e.g.
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionTotal_body.php
___________________________________________________________________
Modified: svn:mergeinfo
1715 Merged /trunk/extensions/ContributionReporting/ContributionTotal_body.php:r75671,75680
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+}
Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionStatistics_body.php
@@ -171,7 +171,6 @@
172172 public function showCurrencyTotals() {
173173 global $wgOut, $wgLang;
174174
175 - $msg = '';
176175 if ( $this->mMode == 'range' ) {
177176 $msg = wfMsg( 'contribstats-currency-range-totals',
178177 $wgLang->date( wfTimestamp( TS_MW, $this->mStartDate ) ),
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionStatistics_body.php
___________________________________________________________________
Modified: svn:mergeinfo
179178 Merged /trunk/extensions/ContributionReporting/ContributionStatistics_body.php:r75680
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting
___________________________________________________________________
Modified: svn:mergeinfo
180179 Merged /trunk/extensions/ContributionReporting:r75671,75680,103884,103947,103959,103967,103991,103996

Follow-up revisions

RevisionCommit summaryAuthorDate
r103999Reverting r103998awjrichards01:34, 23 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r103884adding daily total reporting systemkaldari02:22, 22 November 2011
r103947follow-up to r103884, daily and yearly totalskaldari19:37, 22 November 2011
r103959fixing cachingkaldari21:26, 22 November 2011
r103967more flexiblekaldari22:05, 22 November 2011
r103991better support for timezoneskaldari00:30, 23 November 2011
r103996mapping to both name and offsetkaldari01:00, 23 November 2011

Status & tagging log