http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72954
Revision: 72954
Author: kaldari
Date: 2010-09-14 02:30:27 +0000 (Tue, 14 Sep 2010)
Log Message:
-----------
add geotargeting to banner selection code
Modified Paths:
--------------
trunk/extensions/CentralNotice/SpecialBannerListLoader.php
trunk/extensions/CentralNotice/SpecialCentralNotice.php
Modified: trunk/extensions/CentralNotice/SpecialBannerListLoader.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialBannerListLoader.php 2010-09-14
01:51:13 UTC (rev 72953)
+++ trunk/extensions/CentralNotice/SpecialBannerListLoader.php 2010-09-14
02:30:27 UTC (rev 72954)
@@ -6,6 +6,7 @@
class SpecialBannerListLoader extends UnlistedSpecialPage {
public $project; // Project name
public $language; // Project language
+ public $location; // User country
public $centralNoticeDB;
protected $sharedMaxAge = 150; // Cache for ? minutes on the server side
protected $maxAge = 150; // Cache for ? minutes on the client side
@@ -24,11 +25,14 @@
$this->sendHeaders();
// Get project language from the query string
- $this->language = htmlspecialchars( $wgRequest->getText(
'language', 'en' ) );
+ $this->language = $wgRequest->getText( 'language', 'en' );
// Get project name from the query string
- $this->project = htmlspecialchars( $wgRequest->getText(
'project', 'wikipedia' ) );
+ $this->project = $wgRequest->getText( 'project', 'wikipedia' );
+ // Get location from the query string
+ $this->location = $wgRequest->getText( 'location' );
+
if ( $this->project && $this->language ) {
$content = $this->getJsonList();
if ( strlen( $content ) == 0 ) {
@@ -86,7 +90,7 @@
// Didn't find any preferred matches so do an old style lookup
if ( !$templates ) {
- $templates = CentralNotice::selectNoticeTemplates(
$this->project, $this->language );
+ $templates = CentralNotice::selectNoticeTemplates(
$this->project, $this->language, $this->location );
}
return 'Banners = ' . json_encode( $templates );
Modified: trunk/extensions/CentralNotice/SpecialCentralNotice.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-09-14
01:51:13 UTC (rev 72953)
+++ trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-09-14
02:30:27 UTC (rev 72954)
@@ -1005,13 +1005,15 @@
* each project.
* @return A 2D array of running banners with associated weights and
settings
*/
- static function selectNoticeTemplates( $project, $language ) {
+ static function selectNoticeTemplates( $project, $language, $location =
null ) {
+ $location = htmlspecialchars( $location );
$dbr = wfGetDB( DB_SLAVE );
$encTimestamp = $dbr->addQuotes( $dbr->timestamp() );
$res = $dbr->select(
array(
'cn_notices',
'cn_notice_languages',
+ 'cn_notice_countries',
'cn_assignments',
'cn_templates'
),
@@ -1025,6 +1027,7 @@
"not_start <= $encTimestamp",
"not_end >= $encTimestamp",
"not_enabled = 1",
+ "(not_geo = 0) OR ((not_geo = 1) AND
(nc_country = '$location'))",
'nl_notice_id = cn_notices.not_id',
'nl_language' => $language,
"not_project" => array( '', $project ),
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs