r104003 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104002‎ | r104003 | r104004 >
Date:04:48, 23 November 2011
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
skeleton of live banner stats system
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/bannerstats.js (added) (history)
  • /trunk/extensions/CentralNotice/special/SpecialBannerAllocation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialBannerAllocation.php
@@ -32,7 +32,7 @@
3333 $this->setHeaders();
3434
3535 // Output ResourceLoader module for styling and javascript functions
36 - $wgOut->addModules( 'ext.centralNotice.interface' );
 36+ $wgOut->addModules( array( 'ext.centralNotice.interface', 'ext.centralNotice.bannerStats' ) );
3737
3838 // Initialize error variable
3939 $this->centralNoticeError = false;
@@ -160,23 +160,34 @@
161161
162162 $bannerList = $bannerLister->getJsonList();
163163 $banners = FormatJson::decode( $bannerList, true );
 164+ $campaigns = array();
164165 $anonBanners = array();
165166 $accountBanners = array();
166167 $anonWeight = 0;
167168 $accountWeight = 0;
168169
169170 if ( $banners ) {
 171+
170172 foreach ( $banners as $banner ) {
171 - if ($banner['display_anon']) {
 173+ if ( $banner['display_anon'] ) {
172174 $anonBanners[] = $banner;
173175 $anonWeight += $banner['weight'];
174176 }
175177
176 - if ($banner['display_account']) {
 178+ if ( $banner['display_account'] ) {
177179 $accountBanners[] = $banner;
178180 $accountWeight += $banner['weight'];
179181 }
 182+
 183+ if ( $banner['campaign'] ) {
 184+ $campaigns[] = "'".$banner['campaign']."'";
 185+ }
180186 }
 187+
 188+ // Build campaign list for bannerstats.js
 189+ $campaignList = implode( ', ', $campaigns );
 190+ $js = "wgCentralNoticeAllocationCampaigns = array( $campaignList );";
 191+ $htmlOut .= Html::inlineScript( $js );
181192
182193 if ( $anonBanners ) {
183194 $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-anonymous' ), $anonBanners, $anonWeight );
@@ -223,12 +234,16 @@
224235
225236 $htmlOut .= wfMsg ( 'percent', $wgLang->formatNum( $percentage ) );
226237 $htmlOut .= Html::closeElement( 'td' );
227 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 238+
 239+ $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top' ) );
 240+ // The span class is used by bannerstats.js to find where to insert the stats
 241+ $htmlOut .= Html::openElement( 'span',
 242+ array( 'class' => 'cn-'.$banner['campaign'].'-'.$banner['name'] ) );
 243+ $htmlOut .= $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ),
 244+ 'template=' . urlencode( $banner['name'] ) );
 245+ $htmlOut .= Html::closeElement( 'span' );
 246+ $htmlOut .= Html::closeElement( 'td' );
228247
229 - $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ),
230 - 'template=' . urlencode( $banner['name'] ) )
231 - );
232 -
233248 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
234249
235250 $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ),
Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -88,6 +88,11 @@
8989 'styles' => 'centralnotice.css',
9090 'messages' => 'centralnotice-documentwrite-error'
9191 );
 92+$wgResourceModules['ext.centralNotice.bannerStats'] = array(
 93+ 'localBasePath' => dirname( __FILE__ ),
 94+ 'remoteExtPath' => 'CentralNotice',
 95+ 'scripts' => 'bannerstats.js',
 96+);
9297
9398 function efCentralNoticeUnitTests( &$files ) {
9499 $files[] = dirname( __FILE__ ) . '/tests/CentralNoticeTest.php';
Index: trunk/extensions/CentralNotice/bannerstats.js
@@ -0,0 +1,23 @@
 2+/**
 3+ * This script retrieves click-thru rates for all the banners in all the campaigns in
 4+ * wgCentralNoticeAllocationCampaigns. It then adds the rates to the allocation tables.
 5+ */
 6+$( document ).ready( function () {
 7+ $.each( wgCentralNoticeAllocationCampaigns, function( index, campaignName ) {
 8+ var statUrl = 'http://fundraising-analytics.wikimedia.org/live_stats/' + campaignName;
 9+ $.ajax( {
 10+ 'url': statUrl,
 11+ 'data': {},
 12+ 'dataType': 'json',
 13+ 'type': 'GET',
 14+ 'success': function( data ) {
 15+ console.debug( "Success" );
 16+ console.debug( data );
 17+ },
 18+ 'error': function( xhr ) {
 19+ console.debug( "Error" );
 20+ console.debug( xhr );
 21+ }
 22+ } );
 23+ } )
 24+} );

Follow-up revisions

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

Comments

#Comment by Nikerabbit (talk | contribs)   11:33, 16 December 2011

Use FormatJSON wgCentralNoticeAllocationCampaigns?

#Comment by Kaldari (talk | contribs)   20:12, 20 December 2011

Good idea. Switched it to use json_encode in r106849.

Status & tagging log