r106846 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106845‎ | r106846 | r106847 >
Date:19:50, 20 December 2011
Author:kaldari
Status:ok
Tags:
Comment:
adding support for daily-amount magic message
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialBannerLoader.php (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialBannerLoader.php
@@ -120,9 +120,17 @@
121121 function getNoticeField( $match ) {
122122 $field = $match[1];
123123 $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;
126133 }
 134+
127135 $message = "centralnotice-{$this->bannerName}-$field";
128136 $source = $this->getMessage( $message, $params );
129137 return $source;
@@ -139,6 +147,15 @@
140148 $lang = Language::factory( $this->language );
141149 return $lang->formatNum( $num );
142150 }
 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+ }
143160
144161 /**
145162 * Retrieve a translated message
@@ -197,6 +214,37 @@
198215 }
199216 return $count;
200217 }
 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+ }
201249
202250 function getFundraising( $bannerName ) {
203251 global $wgCentralDBname;
Index: trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php
@@ -513,6 +513,7 @@
514514 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-change-lang' ) );
515515 $htmlOut .= Html::hidden( 'template', $currentTemplate );
516516 $htmlOut .= Html::openElement( 'table', array ( 'cellpadding' => 9 ) );
 517+ // TODO: Change this to use CLDR
517518 list( $lsLabel, $lsSelect ) = Xml::languageSelector( $wpUserLang );
518519
519520 $newPage = $this->getTitle( 'view' );
Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -47,6 +47,7 @@
4848
4949 // Source for live counter information
5050 $wgNoticeCounterSource = 'http://wikimediafoundation.org/wiki/Special:ContributionTotal?action=raw';
 51+$wgNoticeDailyCounterSource = 'http://wikimediafoundation.org/wiki/Special:DailyTotal?action=raw';
5152
5253 // Domain to set global cookies for.
5354 // Example: '.wikipedia.org'

Sign-offs

UserFlagDate
Jpostlethwaiteinspected22:36, 21 December 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r107015MFT r103297, r104003, r104210, r104999, r105015, r105740, r105800, r106166, r...awjrichards23:56, 21 December 2011

Status & tagging log