Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -120,7 +120,7 @@ |
121 | 121 | $wgExtNewFields[] = array( 'cn_notices', 'not_preferred', $base . '/patches/patch-notice_preferred.sql' ); |
122 | 122 | $wgExtNewTables[] = array( 'cn_notice_languages', $base . '/patches/patch-notice_languages.sql' ); |
123 | 123 | $wgExtNewFields[] = array( 'cn_templates', 'tmp_display_anon', $base . '/patches/patch-template_settings.sql' ); |
124 | | - $wgExtNewTables[] = array( 'cn_notice_geo', $base . '/patches/patch-notice_geo.sql' ); |
| 124 | + $wgExtNewTables[] = array( 'cn_notice_countries', $base . '/patches/patch-notice_countries.sql' ); |
125 | 125 | } |
126 | 126 | return true; |
127 | 127 | } |
Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -147,10 +147,12 @@ |
148 | 148 | $start = $wgRequest->getArray( 'start' ); |
149 | 149 | $project_name = $wgRequest->getVal( 'project_name' ); |
150 | 150 | $project_languages = $wgRequest->getArray( 'project_languages' ); |
| 151 | + $geotargeted = $wgRequest->getCheck( 'geotargeted' ); |
| 152 | + $geo_countries = $wgRequest->getArray( 'geo_countries' ); |
151 | 153 | if ( $noticeName == '' ) { |
152 | 154 | $this->showError( 'centralnotice-null-string' ); |
153 | 155 | } else { |
154 | | - $this->addNotice( $noticeName, '0', $start, $project_name, $project_languages ); |
| 156 | + $this->addNotice( $noticeName, '0', $start, $project_name, $project_languages, $geotargeted, $geo_countries ); |
155 | 157 | } |
156 | 158 | } |
157 | 159 | |
— | — | @@ -1026,7 +1028,7 @@ |
1027 | 1029 | return $templates; |
1028 | 1030 | } |
1029 | 1031 | |
1030 | | - function addNotice( $noticeName, $enabled, $start, $project_name, $project_languages ) { |
| 1032 | + function addNotice( $noticeName, $enabled, $start, $project_name, $project_languages, $geotargeted, $geo_countries ) { |
1031 | 1033 | global $wgOut; |
1032 | 1034 | |
1033 | 1035 | if ( $this->noticeExists( $noticeName ) ) { |
— | — | @@ -1059,7 +1061,8 @@ |
1060 | 1062 | 'not_enabled' => $enabled, |
1061 | 1063 | 'not_start' => $dbw->timestamp( $startTs ), |
1062 | 1064 | 'not_end' => $dbw->timestamp( $endTs ), |
1063 | | - 'not_project' => $project_name |
| 1065 | + 'not_project' => $project_name, |
| 1066 | + 'not_geo' => $geotargeted |
1064 | 1067 | ) |
1065 | 1068 | ); |
1066 | 1069 | $not_id = $dbw->insertId(); |
— | — | @@ -1070,6 +1073,15 @@ |
1071 | 1074 | $insertArray[] = array( 'nl_notice_id' => $not_id, 'nl_language' => $code ); |
1072 | 1075 | } |
1073 | 1076 | $res = $dbw->insert( 'cn_notice_languages', $insertArray, __METHOD__, array( 'IGNORE' ) ); |
| 1077 | + |
| 1078 | + if ( $geotargeted ) { |
| 1079 | + // Do multi-row insert for campaign countries |
| 1080 | + $insertArray = array(); |
| 1081 | + foreach( $geo_countries as $code ) { |
| 1082 | + $insertArray[] = array( 'nc_notice_id' => $not_id, 'nc_country' => $code ); |
| 1083 | + } |
| 1084 | + $res = $dbw->insert( 'cn_notice_countries', $insertArray, __METHOD__, array( 'IGNORE' ) ); |
| 1085 | + } |
1074 | 1086 | |
1075 | 1087 | $dbw->commit(); |
1076 | 1088 | return; |
Index: trunk/extensions/CentralNotice/patches/patch-notice_geo.sql |
— | — | @@ -1,8 +0,0 @@ |
2 | | - |
3 | | -CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_geo ( |
4 | | - ng_notice_id int unsigned NOT NULL, |
5 | | - ng_country varchar(2) NOT NULL |
6 | | -) /*$wgDBTableOptions*/; |
7 | | -CREATE UNIQUE INDEX /*i*/ng_notice_id_geo ON /*$wgDBprefix*/cn_notice_geo (ng_notice_id, ng_country); |
8 | | -ALTER TABLE /*$wgDBprefix*/cn_notices ADD not_geo BOOLEAN NOT NULL DEFAULT '0' AFTER not_locked; |
Index: trunk/extensions/CentralNotice/patches/patch-notice_countries.sql |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +-- Update to allow for any number of geotargetted countries per notice. |
| 3 | + |
| 4 | +CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_countries ( |
| 5 | + nc_notice_id int unsigned NOT NULL, |
| 6 | + nc_country varchar(2) NOT NULL |
| 7 | +) /*$wgDBTableOptions*/; |
| 8 | +CREATE UNIQUE INDEX /*i*/nc_notice_id_country ON /*$wgDBprefix*/cn_notice_countries (nc_notice_id, nc_country); |
| 9 | +ALTER TABLE /*$wgDBprefix*/cn_notices ADD not_geo BOOLEAN NOT NULL DEFAULT '0' AFTER not_locked; |