r73232 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73231‎ | r73232 | r73233 >
Date:18:13, 17 September 2010
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialBannerListLoader.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/newCentralNotice.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/newCentralNotice.js
@@ -60,7 +60,7 @@
6161 for( var i = 0; i < bannerList.length; i++ ) {
6262 w += bannerList[i].weight;
6363 // when the weight tally exceeds the random integer, return the banner and stop the loop
64 - if( w < pointer ) {
 64+ if( w > pointer ) {
6565 selectedBanner = bannerList[i];
6666 break;
6767 }
Index: trunk/extensions/CentralNotice/SpecialBannerListLoader.php
@@ -34,7 +34,7 @@
3535 $this->project = $wgRequest->getText( 'project', 'wikipedia' );
3636
3737 // Get location from the query string
38 - $this->location = $wgRequest->getText( 'location' );
 38+ $this->location = $wgRequest->getText( 'country' );
3939
4040 if ( $this->project && $this->language ) {
4141 $content = $this->getJsonList();
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -1004,11 +1004,6 @@
10051005 * @return A 2D array of running banners with associated weights and settings
10061006 */
10071007 static function selectNoticeTemplates( $project, $language, $location = null ) {
1008 -
1009 - // Normalize location parameter (should be an uppercase 2-letter country code)
1010 - preg_match( '/[a-zA-Z][a-zA-Z]/', $location, $matches );
1011 - $location = strtoupper( $matches[0] );
1012 -
10131008 $campaigns = array();
10141009 $dbr = wfGetDB( DB_SLAVE );
10151010 $encTimestamp = $dbr->addQuotes( $dbr->timestamp() );
@@ -1037,6 +1032,11 @@
10381033 $campaigns[] = $row->not_id;
10391034 }
10401035 if ( $location ) {
 1036+
 1037+ // Normalize location parameter (should be an uppercase 2-letter country code)
 1038+ preg_match( '/[a-zA-Z][a-zA-Z]/', $location, $matches );
 1039+ $location = strtoupper( $matches[0] );
 1040+
10411041 // Pull geotargeted campaigns
10421042 $campaignResults2 = $dbr->select(
10431043 array(
Index: trunk/extensions/CentralNotice/SpecialBannerController.php
@@ -64,10 +64,14 @@
6565 }
6666 });
6767 },
68 - 'loadBannerList': function( timestamp ) {
 68+ 'loadBannerList': function( geoOverride ) {
6969 var bannerListURL;
70 - var geoLocation = Geo.country; // pull the geo info
71 - var bannerListPage = 'Special:BannerListLoader?language='+wgContentLanguage+'&project='+wgNoticeProject+'&location='+geoLocation;
 70+ if ( geoOverride ) {
 71+ var geoLocation = geoOverride; // override the geo info
 72+ } else {
 73+ var geoLocation = Geo.country; // pull the geo info
 74+ }
 75+ var bannerListPage = 'Special:BannerListLoader?language='+wgContentLanguage+'&project='+wgNoticeProject+'&country='+geoLocation;
7276 bannerListURL = wgArticlePath.replace( '$1', bannerListPage );
7377 var request = $.ajax( {
7478 url: bannerListURL,
@@ -96,7 +100,7 @@
97101 for( var i = 0; i < bannerList.length; i++ ) {
98102 w += bannerList[i].weight;
99103 // when the weight tally exceeds the random integer, return the banner and stop the loop
100 - if( w < pointer ) {
 104+ if( w > pointer ) {
101105 selectedBanner = bannerList[i];
102106 break;
103107 }
@@ -129,7 +133,7 @@
130134 $.centralNotice.fn.loadBanner( $.centralNotice.data.getVars['cnbanner'] );
131135 } else {
132136 // Look for banners ready to go NOW
133 - $.centralNotice.fn.loadBannerList( );
 137+ $.centralNotice.fn.loadBannerList( $.centralNotice.data.getVars['country'] );
134138 }
135139 } ); //document ready
136140 } )( jQuery );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r73010Followup to r72759 - implimenting Roan's suggestionsadam19:39, 14 September 2010

Comments

#Comment by Catrope (talk | contribs)   18:35, 27 September 2010
+			$.centralNotice.fn.loadBannerList( $.centralNotice.data.getVars['country'] );

You can't just access these things without knowing they exist, see r73219 CR.

#Comment by Kaldari (talk | contribs)   19:27, 27 September 2010

since centralNotice.data is defined, centralNotice.data.getVars['country'] should be OK actually.

Status & tagging log