r73010 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73009‎ | r73010 | r73011 >
Date:19:39, 14 September 2010
Author:adam
Status:resolved (Comments)
Tags:
Comment:
Followup to r72759 - implimenting Roan's suggestions
Modified paths:
  • /trunk/extensions/CentralNotice/newCentralNotice.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/newCentralNotice.js
@@ -52,24 +52,22 @@
5353 // Make sure there are some banners to choose from
5454 if ( bannerList.length == 0 ) return false;
5555
56 - var groomedBannerList = [];
57 -
 56+ var totalWeight = 0;
5857 for( var i = 0; i < bannerList.length; i++ ) {
59 - // only include this banner if it's inteded for the current user
60 - if( ( wgUserName ? bannerList[i].display_account == 1 : bannerList.display_anon == 1 ) ) {
61 - // add the banner to our list once per weight
62 - for( var j=0; j < bannerList[i].weight; j++ ) {
63 - groomedBannerList.push( bannerList[i] );
64 - }
 58+ totalWeight += bannerList[i].weight;
 59+ }
 60+ var pointer = Math.floor( Math.random() * totalWeight ),
 61+ selectedBanner = bannerList[0],
 62+ w = 0;
 63+ for( var i = 0; i < bannerList.length; i++ ) {
 64+ w += bannerList[i].weight;
 65+ if( w < pointer ) {
 66+ selectedBanner = bannerList[i];
 67+ break;
6568 }
6669 }
67 -
68 - // return if there's nothing left after the grooming
69 - if( groomedBannerList.length == 0 ) return false;
70 - // load a random banner from our groomed list
71 -
7270 $.centralNotice.fn.loadBanner(
73 - groomedBannerList[ Math.floor( Math.random() * groomedBannerList.length ) ].name
 71+ selectedBanner.name
7472 );
7573 },
7674 'displayBanner': function( bannerHTML ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r73232fixing bug in r73010, changing location param to country (futureproofing), mo...kaldari18:13, 17 September 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r72759Implimenting weighted banner pickingadam21:35, 10 September 2010

Comments

#Comment by Ryan Kaldari (WMF) (talk | contribs)   18:14, 17 September 2010
if( w < pointer ) {

Should be greater than sign instead of less than, fixed in r73232.

Status & tagging log