http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73232
Revision: 73232 Author: kaldari Date: 2010-09-17 18:13:06 +0000 (Fri, 17 Sep 2010) Log Message: ----------- fixing bug in r73010, changing location param to country (futureproofing), moving location normalization inside if (in case geolookup fails), adding geo override Modified Paths: -------------- trunk/extensions/CentralNotice/SpecialBannerController.php trunk/extensions/CentralNotice/SpecialBannerListLoader.php trunk/extensions/CentralNotice/SpecialCentralNotice.php trunk/extensions/CentralNotice/newCentralNotice.js Modified: trunk/extensions/CentralNotice/SpecialBannerController.php =================================================================== --- trunk/extensions/CentralNotice/SpecialBannerController.php 2010-09-17 18:12:55 UTC (rev 73231) +++ trunk/extensions/CentralNotice/SpecialBannerController.php 2010-09-17 18:13:06 UTC (rev 73232) @@ -64,10 +64,14 @@ } }); }, - 'loadBannerList': function( timestamp ) { + 'loadBannerList': function( geoOverride ) { var bannerListURL; - var geoLocation = Geo.country; // pull the geo info - var bannerListPage = 'Special:BannerListLoader?language='+wgContentLanguage+'&project='+wgNoticeProject+'&location='+geoLocation; + if ( geoOverride ) { + var geoLocation = geoOverride; // override the geo info + } else { + var geoLocation = Geo.country; // pull the geo info + } + var bannerListPage = 'Special:BannerListLoader?language='+wgContentLanguage+'&project='+wgNoticeProject+'&country='+geoLocation; bannerListURL = wgArticlePath.replace( '$1', bannerListPage ); var request = $.ajax( { url: bannerListURL, @@ -96,7 +100,7 @@ for( var i = 0; i < bannerList.length; i++ ) { w += bannerList[i].weight; // when the weight tally exceeds the random integer, return the banner and stop the loop - if( w < pointer ) { + if( w > pointer ) { selectedBanner = bannerList[i]; break; } @@ -129,7 +133,7 @@ $.centralNotice.fn.loadBanner( $.centralNotice.data.getVars['cnbanner'] ); } else { // Look for banners ready to go NOW - $.centralNotice.fn.loadBannerList( ); + $.centralNotice.fn.loadBannerList( $.centralNotice.data.getVars['country'] ); } } ); //document ready } )( jQuery ); Modified: trunk/extensions/CentralNotice/SpecialBannerListLoader.php =================================================================== --- trunk/extensions/CentralNotice/SpecialBannerListLoader.php 2010-09-17 18:12:55 UTC (rev 73231) +++ trunk/extensions/CentralNotice/SpecialBannerListLoader.php 2010-09-17 18:13:06 UTC (rev 73232) @@ -34,7 +34,7 @@ $this->project = $wgRequest->getText( 'project', 'wikipedia' ); // Get location from the query string - $this->location = $wgRequest->getText( 'location' ); + $this->location = $wgRequest->getText( 'country' ); if ( $this->project && $this->language ) { $content = $this->getJsonList(); Modified: trunk/extensions/CentralNotice/SpecialCentralNotice.php =================================================================== --- trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-09-17 18:12:55 UTC (rev 73231) +++ trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-09-17 18:13:06 UTC (rev 73232) @@ -1004,11 +1004,6 @@ * @return A 2D array of running banners with associated weights and settings */ static function selectNoticeTemplates( $project, $language, $location = null ) { - - // Normalize location parameter (should be an uppercase 2-letter country code) - preg_match( '/[a-zA-Z][a-zA-Z]/', $location, $matches ); - $location = strtoupper( $matches[0] ); - $campaigns = array(); $dbr = wfGetDB( DB_SLAVE ); $encTimestamp = $dbr->addQuotes( $dbr->timestamp() ); @@ -1037,6 +1032,11 @@ $campaigns[] = $row->not_id; } if ( $location ) { + + // Normalize location parameter (should be an uppercase 2-letter country code) + preg_match( '/[a-zA-Z][a-zA-Z]/', $location, $matches ); + $location = strtoupper( $matches[0] ); + // Pull geotargeted campaigns $campaignResults2 = $dbr->select( array( Modified: trunk/extensions/CentralNotice/newCentralNotice.js =================================================================== --- trunk/extensions/CentralNotice/newCentralNotice.js 2010-09-17 18:12:55 UTC (rev 73231) +++ trunk/extensions/CentralNotice/newCentralNotice.js 2010-09-17 18:13:06 UTC (rev 73232) @@ -60,7 +60,7 @@ for( var i = 0; i < bannerList.length; i++ ) { w += bannerList[i].weight; // when the weight tally exceeds the random integer, return the banner and stop the loop - if( w < pointer ) { + if( w > pointer ) { selectedBanner = bannerList[i]; break; } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs