Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -130,6 +130,9 @@ |
131 | 131 | |
132 | 132 | $centralLoader = SpecialPage::getTitleFor( 'BannerController' )->getLocalUrl(); |
133 | 133 | |
| 134 | + // Insert the geo IP lookup into the <head> |
| 135 | + $wgOut->addScriptFile( 'http://geoiplookup.wikimedia.org/' ); |
| 136 | + |
134 | 137 | // Insert the banner controller Javascript into the <head> |
135 | 138 | $wgOut->addScriptFile( $centralLoader ); |
136 | 139 | |
— | — | @@ -138,17 +141,20 @@ |
139 | 142 | |
140 | 143 | function efCentralNoticeDefaults( &$vars ) { |
141 | 144 | global $wgNoticeProject; |
142 | | - // Initialize global Javascript variables. We initialize wgNotice to empty so if the notice |
143 | | - // script fails we don't have any surprises. |
144 | | - $vars['wgNotice'] = ''; |
| 145 | + // Initialize global Javascript variables. We initialize Geo with empty values so if the geo |
| 146 | + // IP lookup fails we don't have any surprises. |
| 147 | + $geo = (object)array(); |
| 148 | + $geo->{'city'} = ''; |
| 149 | + $geo->{'country'} = ''; |
| 150 | + $vars['Geo'] = $geo; // change this to wgGeo as soon as Mark updates on his end |
145 | 151 | $vars['wgNoticeProject'] = $wgNoticeProject; |
146 | 152 | return true; |
147 | 153 | } |
148 | 154 | |
149 | 155 | function efCentralNoticeDisplay( &$notice ) { |
150 | | - // Slip in loading of the banner (inside the siteNotice div) |
| 156 | + // setup siteNotice div |
151 | 157 | $notice = |
152 | | - Html::inlineScript( "if (wgNotice != '') document.writeln(wgNotice);" ) . |
| 158 | + '<!-- centralNotice loads here -->'. // hack for IE8 to collapse empty div |
153 | 159 | $notice; |
154 | 160 | return true; |
155 | 161 | } |
Index: trunk/extensions/CentralNotice/SpecialBannerController.php |
— | — | @@ -53,12 +53,11 @@ |
54 | 54 | }, |
55 | 55 | 'fn': { |
56 | 56 | 'loadBanner': function( bannerName ) { |
57 | | - // get the requested banner from /centralnotice/banners/<bannername>/<wgUserLanguage>.js |
| 57 | + // Get the requested banner from /centralnotice/banners/<bannername>/<wgUserLanguage>.js |
58 | 58 | var bannerPage = 'Special:BannerLoader?banner='+bannerName+'&userlang='+wgContentLanguage+'&sitename='+wgNoticeProject; |
59 | 59 | //centralized version: |
60 | 60 | //var bannerURL = 'http://meta.wikimedia.org/wiki/'+bannerPage; |
61 | | - //var bannerURL = wgArticlePath.replace( '$1', bannerPage ); |
62 | | - var bannerURL = 'http://localhost/~rkaldari/banner.html'; |
| 61 | + var bannerURL = wgArticlePath.replace( '$1', bannerPage ); |
63 | 62 | var request = $.ajax( { |
64 | 63 | url: bannerURL, |
65 | 64 | dataType: 'html', |
— | — | @@ -69,16 +68,11 @@ |
70 | 69 | }, |
71 | 70 | 'loadBannerList': function( timestamp ) { |
72 | 71 | var listURL; |
73 | | - if ( timestamp ) { |
74 | | - listURL = "TBD" |
75 | | - } else { |
76 | | - // http://geoiplookup.wikimedia.org/ |
77 | | - var geoLocation = 'US'; // Hard-coding for now |
78 | | - var bannerListPage = 'Special:BannerListLoader?language='+wgContentLanguage+'&project='+wgNoticeProject+'&location='+geoLocation; |
79 | | - //centralized version: |
80 | | - //var bannerListURL = 'http://meta.wikimedia.org/wiki/'+bannerListPage; |
81 | | - var bannerListURL = wgArticlePath.replace( '$1', bannerListPage ); |
82 | | - } |
| 72 | + var geoLocation = Geo.country; // pull the geo info |
| 73 | + var bannerListPage = 'Special:BannerListLoader?language='+wgContentLanguage+'&project='+wgNoticeProject+'&location='+geoLocation; |
| 74 | + //centralized version: |
| 75 | + //var bannerListURL = 'http://meta.wikimedia.org/wiki/'+bannerListPage; |
| 76 | + var bannerListURL = wgArticlePath.replace( '$1', bannerListPage ); |
83 | 77 | var request = $.ajax( { |
84 | 78 | url: bannerListURL, |
85 | 79 | dataType: 'json', |
— | — | @@ -86,7 +80,7 @@ |
87 | 81 | } ); |
88 | 82 | }, |
89 | 83 | 'chooseBanner': function( bannerList ) { |
90 | | - // convert the json object to a true array |
| 84 | + // Convert the json object to a true array |
91 | 85 | bannerList = Array.prototype.slice.call( bannerList ); |
92 | 86 | |
93 | 87 | // Make sure there are some banners to choose from |
— | — | @@ -95,8 +89,8 @@ |
96 | 90 | var groomedBannerList = []; |
97 | 91 | |
98 | 92 | for( var i = 0; i < bannerList.length; i++ ) { |
99 | | - // only include this banner if it's inteded for the current user |
100 | | - if( ( wgUserName ? bannerList[i].display_account == 1 : bannerList.display_anon == 1 ) ) { |
| 93 | + // Only include this banner if it's inteded for the current user |
| 94 | + if( ( wgUserName && bannerList[i].display_account ) || ( !wgUserName && bannerList[i].display_anon == 1 ) ) { |
101 | 95 | // add the banner to our list once per weight |
102 | 96 | for( var j=0; j < bannerList[i].weight; j++ ) { |
103 | 97 | groomedBannerList.push( bannerList[i] ); |
— | — | @@ -104,18 +98,18 @@ |
105 | 99 | } |
106 | 100 | } |
107 | 101 | |
108 | | - // return if there's nothing left after the grooming |
| 102 | + // Return if there's nothing left after the grooming |
109 | 103 | if( groomedBannerList.length == 0 ) return false; |
110 | | - // load a random banner from our groomed list |
111 | 104 | |
| 105 | + // Load a random banner from our groomed list |
112 | 106 | $.centralNotice.fn.loadBanner( |
113 | 107 | groomedBannerList[ Math.floor( Math.random() * groomedBannerList.length ) ].name |
114 | | - ); |
| 108 | + ); |
115 | 109 | }, |
116 | 110 | 'displayBanner': function( bannerHTML ) { |
117 | | - // inject the banner html into the page |
| 111 | + // Inject the banner html into the page |
118 | 112 | $( '#siteNotice' ) |
119 | | - .prepend( '<div id="centralnotice" class="' + ( wgNoticeToggleState ? 'expanded' : 'collapsed' ) + '">' + bannerHTML + '</div>' ); |
| 113 | + .prepend( '<div id="centralNotice" class="' + ( wgNoticeToggleState ? 'expanded' : 'collapsed' ) + '">' + bannerHTML + '</div>' ); |
120 | 114 | }, |
121 | 115 | 'getQueryStringVariables': function() { |
122 | 116 | document.location.search.replace( /\??(?:([^=]+)=([^&]*)&?)/g, function () { |
— | — | @@ -128,18 +122,10 @@ |
129 | 123 | } |
130 | 124 | } |
131 | 125 | $( document ).ready( function () { |
132 | | - // initialize the query string vars |
| 126 | + // Initialize the query string vars |
133 | 127 | $.centralNotice.fn.getQueryStringVariables(); |
134 | | - if( $.centralNotice.data.getVars['forceBanner'] ) { |
135 | | - // if we're forcing one banner |
136 | | - $.centralNotice.fn.loadBanner( $.centralNotice.data.getVars['forceBanner'] ); |
137 | | - } else if ( $.centralNotice.data.getVars['forceTimestamp'] ) { |
138 | | - // if we're forcing a future campaign time |
139 | | - $.centralNotice.fn.loadBannerList( $.centralNotice.data.getVars['forceTimestamp'] ); |
140 | | - } else { |
141 | | - // look for banners ready to go NOW |
142 | | - $.centralNotice.fn.loadBannerList( ); |
143 | | - } |
| 128 | + // Look for banners ready to go NOW |
| 129 | + $.centralNotice.fn.loadBannerList( ); |
144 | 130 | } ); //document ready |
145 | 131 | } )( jQuery ); |
146 | 132 | EOT; |
— | — | @@ -151,14 +137,8 @@ |
152 | 138 | $showStyle = <<<END |
153 | 139 | <style type="text/css"> |
154 | 140 | #centralNotice .siteNoticeSmall {display:none;} |
155 | | -#centralNotice .siteNoticeSmallAnon {display:none;} |
156 | | -#centralNotice .siteNoticeSmallUser {display:none;} |
157 | 141 | #centralNotice.collapsed .siteNoticeBig {display:none;} |
158 | 142 | #centralNotice.collapsed .siteNoticeSmall {display:block;} |
159 | | -#centralNotice.collapsed .siteNoticeSmallUser {display:block;} |
160 | | -#centralNotice.collapsed .siteNoticeSmallAnon {display:block;} |
161 | | -#centralNotice.anonnotice .siteNoticeSmallUser {display:none !important;} |
162 | | -#centralNotice.usernotice .siteNoticeSmallAnon {display:none !important;} |
163 | 143 | </style> |
164 | 144 | END; |
165 | 145 | $encShowStyle = Xml::encodeJsVar( $showStyle ); |