Index: trunk/extensions/CentralNotice/SpecialBannerListLoader.php |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | class SpecialBannerListLoader extends UnlistedSpecialPage { |
8 | 8 | public $project; // Project name |
9 | 9 | public $language; // Project language |
| 10 | + public $location; // User country |
10 | 11 | public $centralNoticeDB; |
11 | 12 | protected $sharedMaxAge = 150; // Cache for ? minutes on the server side |
12 | 13 | protected $maxAge = 150; // Cache for ? minutes on the client side |
— | — | @@ -24,11 +25,14 @@ |
25 | 26 | $this->sendHeaders(); |
26 | 27 | |
27 | 28 | // Get project language from the query string |
28 | | - $this->language = htmlspecialchars( $wgRequest->getText( 'language', 'en' ) ); |
| 29 | + $this->language = $wgRequest->getText( 'language', 'en' ); |
29 | 30 | |
30 | 31 | // Get project name from the query string |
31 | | - $this->project = htmlspecialchars( $wgRequest->getText( 'project', 'wikipedia' ) ); |
| 32 | + $this->project = $wgRequest->getText( 'project', 'wikipedia' ); |
32 | 33 | |
| 34 | + // Get location from the query string |
| 35 | + $this->location = $wgRequest->getText( 'location' ); |
| 36 | + |
33 | 37 | if ( $this->project && $this->language ) { |
34 | 38 | $content = $this->getJsonList(); |
35 | 39 | if ( strlen( $content ) == 0 ) { |
— | — | @@ -86,7 +90,7 @@ |
87 | 91 | |
88 | 92 | // Didn't find any preferred matches so do an old style lookup |
89 | 93 | if ( !$templates ) { |
90 | | - $templates = CentralNotice::selectNoticeTemplates( $this->project, $this->language ); |
| 94 | + $templates = CentralNotice::selectNoticeTemplates( $this->project, $this->language, $this->location ); |
91 | 95 | } |
92 | 96 | |
93 | 97 | return 'Banners = ' . json_encode( $templates ); |
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -1005,13 +1005,15 @@ |
1006 | 1006 | * each project. |
1007 | 1007 | * @return A 2D array of running banners with associated weights and settings |
1008 | 1008 | */ |
1009 | | - static function selectNoticeTemplates( $project, $language ) { |
| 1009 | + static function selectNoticeTemplates( $project, $language, $location = null ) { |
| 1010 | + $location = htmlspecialchars( $location ); |
1010 | 1011 | $dbr = wfGetDB( DB_SLAVE ); |
1011 | 1012 | $encTimestamp = $dbr->addQuotes( $dbr->timestamp() ); |
1012 | 1013 | $res = $dbr->select( |
1013 | 1014 | array( |
1014 | 1015 | 'cn_notices', |
1015 | 1016 | 'cn_notice_languages', |
| 1017 | + 'cn_notice_countries', |
1016 | 1018 | 'cn_assignments', |
1017 | 1019 | 'cn_templates' |
1018 | 1020 | ), |
— | — | @@ -1025,6 +1027,7 @@ |
1026 | 1028 | "not_start <= $encTimestamp", |
1027 | 1029 | "not_end >= $encTimestamp", |
1028 | 1030 | "not_enabled = 1", |
| 1031 | + "(not_geo = 0) OR ((not_geo = 1) AND (nc_country = '$location'))", |
1029 | 1032 | 'nl_notice_id = cn_notices.not_id', |
1030 | 1033 | 'nl_language' => $language, |
1031 | 1034 | "not_project" => array( '', $project ), |