http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72950

Revision: 72950
Author:   kaldari
Date:     2010-09-14 01:19:37 +0000 (Tue, 14 Sep 2010)

Log Message:
-----------
schema changes from r72932 (futureproofing), adding basic support for saving 
geo info

Modified Paths:
--------------
    trunk/extensions/CentralNotice/CentralNotice.php
    trunk/extensions/CentralNotice/SpecialCentralNotice.php

Added Paths:
-----------
    trunk/extensions/CentralNotice/patches/patch-notice_countries.sql

Removed Paths:
-------------
    trunk/extensions/CentralNotice/patches/patch-notice_geo.sql

Modified: trunk/extensions/CentralNotice/CentralNotice.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNotice.php    2010-09-14 00:45:53 UTC 
(rev 72949)
+++ trunk/extensions/CentralNotice/CentralNotice.php    2010-09-14 01:19:37 UTC 
(rev 72950)
@@ -120,7 +120,7 @@
                $wgExtNewFields[] = array( 'cn_notices', 'not_preferred', $base 
. '/patches/patch-notice_preferred.sql' );
                $wgExtNewTables[] = array( 'cn_notice_languages', $base . 
'/patches/patch-notice_languages.sql' );
                $wgExtNewFields[] = array( 'cn_templates', 'tmp_display_anon', 
$base . '/patches/patch-template_settings.sql' );
-               $wgExtNewTables[] = array( 'cn_notice_geo', $base . 
'/patches/patch-notice_geo.sql' );
+               $wgExtNewTables[] = array( 'cn_notice_countries', $base . 
'/patches/patch-notice_countries.sql' );
        }
        return true;
 }

Modified: trunk/extensions/CentralNotice/SpecialCentralNotice.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialCentralNotice.php     2010-09-14 
00:45:53 UTC (rev 72949)
+++ trunk/extensions/CentralNotice/SpecialCentralNotice.php     2010-09-14 
01:19:37 UTC (rev 72950)
@@ -147,10 +147,12 @@
                                        $start             = 
$wgRequest->getArray( 'start' );
                                        $project_name      = 
$wgRequest->getVal( 'project_name' );
                                        $project_languages = 
$wgRequest->getArray( 'project_languages' );
+                                       $geotargeted       = 
$wgRequest->getCheck( 'geotargeted' );
+                                       $geo_countries     = 
$wgRequest->getArray( 'geo_countries' );
                                        if ( $noticeName == '' ) {
                                                $this->showError( 
'centralnotice-null-string' );
                                        } else {
-                                               $this->addNotice( $noticeName, 
'0', $start, $project_name, $project_languages );
+                                               $this->addNotice( $noticeName, 
'0', $start, $project_name, $project_languages, $geotargeted, $geo_countries );
                                        }
                                }
                                
@@ -1026,7 +1028,7 @@
                return $templates;
        }
 
-       function addNotice( $noticeName, $enabled, $start, $project_name, 
$project_languages ) {
+       function addNotice( $noticeName, $enabled, $start, $project_name, 
$project_languages, $geotargeted, $geo_countries ) {
                global $wgOut;
 
                if ( $this->noticeExists( $noticeName ) ) {
@@ -1059,7 +1061,8 @@
                                        'not_enabled' => $enabled,
                                        'not_start' => $dbw->timestamp( 
$startTs ),
                                        'not_end' => $dbw->timestamp( $endTs ),
-                                       'not_project' => $project_name
+                                       'not_project' => $project_name,
+                                       'not_geo' => $geotargeted
                                )
                        );
                        $not_id = $dbw->insertId();
@@ -1070,6 +1073,15 @@
                                $insertArray[] = array( 'nl_notice_id' => 
$not_id, 'nl_language' => $code );
                        }
                        $res = $dbw->insert( 'cn_notice_languages', 
$insertArray, __METHOD__, array( 'IGNORE' ) );
+                       
+                       if ( $geotargeted ) {
+                               // Do multi-row insert for campaign countries
+                               $insertArray = array();
+                               foreach( $geo_countries as $code ) {
+                                       $insertArray[] = array( 'nc_notice_id' 
=> $not_id, 'nc_country' => $code );
+                               }
+                               $res = $dbw->insert( 'cn_notice_countries', 
$insertArray, __METHOD__, array( 'IGNORE' ) );
+                       }
                
                        $dbw->commit();
                        return;

Copied: trunk/extensions/CentralNotice/patches/patch-notice_countries.sql (from 
rev 72932, trunk/extensions/CentralNotice/patches/patch-notice_geo.sql)
===================================================================
--- trunk/extensions/CentralNotice/patches/patch-notice_countries.sql           
                (rev 0)
+++ trunk/extensions/CentralNotice/patches/patch-notice_countries.sql   
2010-09-14 01:19:37 UTC (rev 72950)
@@ -0,0 +1,8 @@
+-- Update to allow for any number of geotargetted countries per notice.
+
+CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_countries (
+       nc_notice_id int unsigned NOT NULL,
+       nc_country varchar(2) NOT NULL
+) /*$wgDBTableOptions*/;
+CREATE UNIQUE INDEX /*i*/nc_notice_id_country ON 
/*$wgDBprefix*/cn_notice_countries (nc_notice_id, nc_country);
+ALTER TABLE /*$wgDBprefix*/cn_notices ADD not_geo BOOLEAN NOT NULL DEFAULT '0' 
AFTER not_locked; 

Deleted: trunk/extensions/CentralNotice/patches/patch-notice_geo.sql
===================================================================
--- trunk/extensions/CentralNotice/patches/patch-notice_geo.sql 2010-09-14 
00:45:53 UTC (rev 72949)
+++ trunk/extensions/CentralNotice/patches/patch-notice_geo.sql 2010-09-14 
01:19:37 UTC (rev 72950)
@@ -1,8 +0,0 @@
--- Update to allow for any number of languages per notice.
-
-CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_geo (
-       ng_notice_id int unsigned NOT NULL,
-       ng_country varchar(2) NOT NULL
-) /*$wgDBTableOptions*/;
-CREATE UNIQUE INDEX /*i*/ng_notice_id_geo ON /*$wgDBprefix*/cn_notice_geo 
(ng_notice_id, ng_country);
-ALTER TABLE /*$wgDBprefix*/cn_notices ADD not_geo BOOLEAN NOT NULL DEFAULT '0' 
AFTER not_locked; 



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to