Index: trunk/extensions/CentralNotice/special/SpecialBannerAllocation.php |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | $this->setHeaders(); |
34 | 34 | |
35 | 35 | // Output ResourceLoader module for styling and javascript functions |
36 | | - $wgOut->addModules( 'ext.centralNotice.interface' ); |
| 36 | + $wgOut->addModules( array( 'ext.centralNotice.interface', 'ext.centralNotice.bannerStats' ) ); |
37 | 37 | |
38 | 38 | // Initialize error variable |
39 | 39 | $this->centralNoticeError = false; |
— | — | @@ -160,23 +160,34 @@ |
161 | 161 | |
162 | 162 | $bannerList = $bannerLister->getJsonList(); |
163 | 163 | $banners = FormatJson::decode( $bannerList, true ); |
| 164 | + $campaigns = array(); |
164 | 165 | $anonBanners = array(); |
165 | 166 | $accountBanners = array(); |
166 | 167 | $anonWeight = 0; |
167 | 168 | $accountWeight = 0; |
168 | 169 | |
169 | 170 | if ( $banners ) { |
| 171 | + |
170 | 172 | foreach ( $banners as $banner ) { |
171 | | - if ($banner['display_anon']) { |
| 173 | + if ( $banner['display_anon'] ) { |
172 | 174 | $anonBanners[] = $banner; |
173 | 175 | $anonWeight += $banner['weight']; |
174 | 176 | } |
175 | 177 | |
176 | | - if ($banner['display_account']) { |
| 178 | + if ( $banner['display_account'] ) { |
177 | 179 | $accountBanners[] = $banner; |
178 | 180 | $accountWeight += $banner['weight']; |
179 | 181 | } |
| 182 | + |
| 183 | + if ( $banner['campaign'] ) { |
| 184 | + $campaigns[] = "'".$banner['campaign']."'"; |
| 185 | + } |
180 | 186 | } |
| 187 | + |
| 188 | + // Build campaign list for bannerstats.js |
| 189 | + $campaignList = implode( ', ', $campaigns ); |
| 190 | + $js = "wgCentralNoticeAllocationCampaigns = array( $campaignList );"; |
| 191 | + $htmlOut .= Html::inlineScript( $js ); |
181 | 192 | |
182 | 193 | if ( $anonBanners ) { |
183 | 194 | $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-anonymous' ), $anonBanners, $anonWeight ); |
— | — | @@ -223,12 +234,16 @@ |
224 | 235 | |
225 | 236 | $htmlOut .= wfMsg ( 'percent', $wgLang->formatNum( $percentage ) ); |
226 | 237 | $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' ); |
228 | 247 | |
229 | | - $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ), |
230 | | - 'template=' . urlencode( $banner['name'] ) ) |
231 | | - ); |
232 | | - |
233 | 248 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
234 | 249 | |
235 | 250 | $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ), |
Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -88,6 +88,11 @@ |
89 | 89 | 'styles' => 'centralnotice.css', |
90 | 90 | 'messages' => 'centralnotice-documentwrite-error' |
91 | 91 | ); |
| 92 | +$wgResourceModules['ext.centralNotice.bannerStats'] = array( |
| 93 | + 'localBasePath' => dirname( __FILE__ ), |
| 94 | + 'remoteExtPath' => 'CentralNotice', |
| 95 | + 'scripts' => 'bannerstats.js', |
| 96 | +); |
92 | 97 | |
93 | 98 | function efCentralNoticeUnitTests( &$files ) { |
94 | 99 | $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 | +} ); |