Index: trunk/extensions/CentralNotice/special/SpecialBannerLoader.php |
— | — | @@ -120,9 +120,17 @@ |
121 | 121 | function getNoticeField( $match ) { |
122 | 122 | $field = $match[1]; |
123 | 123 | $params = array(); |
124 | | - if ( $field == 'amount' ) { |
125 | | - $params = array( $this->toMillions( $this->getDonationAmount() ) ); |
| 124 | + |
| 125 | + // Handle "magic messages" |
| 126 | + switch ( $field ) { |
| 127 | + case 'amount': // total fundraising amount |
| 128 | + $params = array( $this->toMillions( $this->getDonationAmount() ) ); |
| 129 | + break; |
| 130 | + case 'daily-amount': // daily fundraising amount |
| 131 | + $params = array( $this->toThousands( $this->getDailyDonationAmount() ) ); |
| 132 | + break; |
126 | 133 | } |
| 134 | + |
127 | 135 | $message = "centralnotice-{$this->bannerName}-$field"; |
128 | 136 | $source = $this->getMessage( $message, $params ); |
129 | 137 | return $source; |
— | — | @@ -139,6 +147,15 @@ |
140 | 148 | $lang = Language::factory( $this->language ); |
141 | 149 | return $lang->formatNum( $num ); |
142 | 150 | } |
| 151 | + |
| 152 | + /** |
| 153 | + * Convert number of dollars to thousands of dollars |
| 154 | + */ |
| 155 | + private function toThousands( $num ) { |
| 156 | + $num = sprintf( "%d", $num / 1000 ); |
| 157 | + $lang = Language::factory( $this->language ); |
| 158 | + return $lang->formatNum( $num ); |
| 159 | + } |
143 | 160 | |
144 | 161 | /** |
145 | 162 | * Retrieve a translated message |
— | — | @@ -197,6 +214,37 @@ |
198 | 215 | } |
199 | 216 | return $count; |
200 | 217 | } |
| 218 | + |
| 219 | + /** |
| 220 | + * Pull the amount raised so far today during a fundraiser |
| 221 | + * @throws SpecialBannerLoaderException |
| 222 | + */ |
| 223 | + private function getDailyDonationAmount() { |
| 224 | + global $wgNoticeDailyCounterSource, $wgMemc; |
| 225 | + // Pull short-cached amount |
| 226 | + $count = intval( $wgMemc->get( wfMemcKey( 'centralnotice', 'dailycounter' ) ) ); |
| 227 | + if ( !$count ) { |
| 228 | + // Pull from dynamic counter |
| 229 | + $counter_value = Http::get( $wgNoticeDailyCounterSource ); |
| 230 | + if( !$counter_value ) { |
| 231 | + throw new RemoteServerProblemException(); |
| 232 | + } |
| 233 | + $count = intval( $counter_value ); |
| 234 | + if ( !$count ) { |
| 235 | + // Pull long-cached amount |
| 236 | + $count = intval( $wgMemc->get( |
| 237 | + wfMemcKey( 'centralnotice', 'dailycounter', 'fallback' ) ) ); |
| 238 | + if ( !$count ) { |
| 239 | + throw new DonationAmountUnknownException(); |
| 240 | + } |
| 241 | + } |
| 242 | + // Expire in 60 seconds |
| 243 | + $wgMemc->set( wfMemcKey( 'centralnotice', 'dailycounter' ), $count, 60 ); |
| 244 | + // No expiration |
| 245 | + $wgMemc->set( wfMemcKey( 'centralnotice', 'dailycounter', 'fallback' ), $count ); |
| 246 | + } |
| 247 | + return $count; |
| 248 | + } |
201 | 249 | |
202 | 250 | function getFundraising( $bannerName ) { |
203 | 251 | global $wgCentralDBname; |
Index: trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php |
— | — | @@ -513,6 +513,7 @@ |
514 | 514 | $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-change-lang' ) ); |
515 | 515 | $htmlOut .= Html::hidden( 'template', $currentTemplate ); |
516 | 516 | $htmlOut .= Html::openElement( 'table', array ( 'cellpadding' => 9 ) ); |
| 517 | + // TODO: Change this to use CLDR |
517 | 518 | list( $lsLabel, $lsSelect ) = Xml::languageSelector( $wpUserLang ); |
518 | 519 | |
519 | 520 | $newPage = $this->getTitle( 'view' ); |
Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -47,6 +47,7 @@ |
48 | 48 | |
49 | 49 | // Source for live counter information |
50 | 50 | $wgNoticeCounterSource = 'http://wikimediafoundation.org/wiki/Special:ContributionTotal?action=raw'; |
| 51 | +$wgNoticeDailyCounterSource = 'http://wikimediafoundation.org/wiki/Special:DailyTotal?action=raw'; |
51 | 52 | |
52 | 53 | // Domain to set global cookies for. |
53 | 54 | // Example: '.wikipedia.org' |