Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -192,7 +192,6 @@ |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Handle adding of campaign |
196 | | - $this->showAll = $wgRequest->getVal( 'showAll' ); |
197 | 196 | if ( $this->editable && $method == 'addNotice' && $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
198 | 197 | $noticeName = $wgRequest->getVal( 'noticeName' ); |
199 | 198 | $start = $wgRequest->getArray( 'start' ); |
— | — | @@ -377,43 +376,21 @@ |
378 | 377 | $readonly = array( 'disabled' => 'disabled' ); |
379 | 378 | } |
380 | 379 | |
381 | | - // This is temporarily hard-coded |
382 | | - $this->showAll = 'Y'; |
383 | | - |
384 | | - // If all languages should be shown |
385 | | - if ( isset( $this->showAll ) ) { |
386 | | - // Get campaigns for all languages |
387 | | - $res = $dbr->select( 'cn_notices', |
388 | | - array( |
389 | | - 'not_name', |
390 | | - 'not_start', |
391 | | - 'not_end', |
392 | | - 'not_enabled', |
393 | | - 'not_preferred', |
394 | | - 'not_project', |
395 | | - 'not_locked' |
396 | | - ), |
397 | | - null, |
398 | | - __METHOD__, |
399 | | - array( 'ORDER BY' => 'not_id' ) |
400 | | - ); |
401 | | - } else { |
402 | | - // Get only campaigns for this language |
403 | | - $res = $dbr->select( 'cn_notices', |
404 | | - array( |
405 | | - 'not_name', |
406 | | - 'not_start', |
407 | | - 'not_end', |
408 | | - 'not_enabled', |
409 | | - 'not_preferred', |
410 | | - 'not_project', |
411 | | - 'not_locked' |
412 | | - ), |
413 | | - array ( 'not_language' => $wgLang->getCode() ), |
414 | | - __METHOD__, |
415 | | - array( 'ORDER BY' => 'not_id' ) |
416 | | - ); |
417 | | - } |
| 380 | + // Get all campaigns from the database |
| 381 | + $res = $dbr->select( 'cn_notices', |
| 382 | + array( |
| 383 | + 'not_name', |
| 384 | + 'not_start', |
| 385 | + 'not_end', |
| 386 | + 'not_enabled', |
| 387 | + 'not_preferred', |
| 388 | + 'not_project', |
| 389 | + 'not_locked' |
| 390 | + ), |
| 391 | + null, |
| 392 | + __METHOD__, |
| 393 | + array( 'ORDER BY' => 'not_id' ) |
| 394 | + ); |
418 | 395 | |
419 | 396 | // Begin building HTML |
420 | 397 | $htmlOut = ''; |
— | — | @@ -669,9 +646,6 @@ |
670 | 647 | ); |
671 | 648 | } |
672 | 649 | |
673 | | - // Temporarily hard coded |
674 | | - $this->showAll = 'Y'; |
675 | | - |
676 | 650 | $output_detail = $this->noticeDetailForm( $notice ); |
677 | 651 | $output_assigned = $this->assignedTemplatesForm( $notice ); |
678 | 652 | $output_templates = $this->addTemplatesForm( $notice ); |
— | — | @@ -747,13 +721,13 @@ |
748 | 722 | __METHOD__ |
749 | 723 | ); |
750 | 724 | $res = $dbr->select( 'cn_notice_languages', |
751 | | - 'not_language', |
752 | | - array( 'not_id' => $row->not_id ), |
| 725 | + 'nl_language', |
| 726 | + array( 'nl_notice_id' => $row->not_id ), |
753 | 727 | __METHOD__ |
754 | 728 | ); |
755 | 729 | $project_languages = array(); |
756 | 730 | foreach ( $res as $langRow ) { |
757 | | - $project_languages[] = $langRow->not_language; |
| 731 | + $project_languages[] = $langRow->nl_language; |
758 | 732 | } |
759 | 733 | |
760 | 734 | if ( $row ) { |
— | — | @@ -972,8 +946,8 @@ |
973 | 947 | "not_start <= $encTimestamp", |
974 | 948 | "not_end >= $encTimestamp", |
975 | 949 | "not_enabled = 1", |
976 | | - 'cn_notice_languages.not_id = cn_notices.not_id', |
977 | | - 'cn_notice_languages.not_language' => $language, |
| 950 | + 'nl_notice_id = cn_notices.not_id', |
| 951 | + 'nl_language' => $language, |
978 | 952 | "not_project" => array( '', $project ), |
979 | 953 | 'cn_notices.not_id=cn_assignments.not_id', |
980 | 954 | 'cn_assignments.tmp_id=cn_templates.tmp_id' |
— | — | @@ -1033,13 +1007,14 @@ |
1034 | 1008 | ) |
1035 | 1009 | ); |
1036 | 1010 | $not_id = $dbw->insertId(); |
| 1011 | + |
| 1012 | + // Do multi-row insert for campaign languages |
| 1013 | + $insertArray = array(); |
1037 | 1014 | foreach( $project_languages as $code ) { |
1038 | | - $res = $dbw->insert( 'cn_notice_languages', |
1039 | | - array( 'not_id' => $not_id, |
1040 | | - 'not_language' => $code |
1041 | | - ) |
1042 | | - ); |
| 1015 | + $insertArray[] = array( 'nl_notice_id' => $not_id, 'nl_language' => $code ); |
1043 | 1016 | } |
| 1017 | + $res = $dbw->insert( 'cn_notice_languages', $insertArray, __METHOD__, array( 'IGNORE' ) ); |
| 1018 | + |
1044 | 1019 | $dbw->commit(); |
1045 | 1020 | return; |
1046 | 1021 | } |
— | — | @@ -1066,7 +1041,7 @@ |
1067 | 1042 | $noticeId = htmlspecialchars( $this->getNoticeId( $noticeName ) ); |
1068 | 1043 | $res = $dbw->delete( 'cn_assignments', array ( 'not_id' => $noticeId ) ); |
1069 | 1044 | $res = $dbw->delete( 'cn_notices', array ( 'not_name' => $noticeName ) ); |
1070 | | - $res = $dbw->delete( 'cn_notice_languages', array ( 'not_id' => $noticeId ) ); |
| 1045 | + $res = $dbw->delete( 'cn_notice_languages', array ( 'nl_notice_id' => $noticeId ) ); |
1071 | 1046 | $dbw->commit(); |
1072 | 1047 | return; |
1073 | 1048 | } |
— | — | @@ -1111,14 +1086,16 @@ |
1112 | 1087 | return $row->not_id; |
1113 | 1088 | } |
1114 | 1089 | |
1115 | | - function getNoticeLanguages ( $noticeName ) { |
| 1090 | + function getNoticeLanguages( $noticeName ) { |
1116 | 1091 | $dbr = wfGetDB( DB_SLAVE ); |
1117 | 1092 | $eNoticeName = htmlspecialchars( $noticeName ); |
1118 | 1093 | $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) ); |
1119 | | - $res = $dbr->select( 'cn_notice_languages', 'not_language', array( 'not_id' => $row->not_id ) ); |
1120 | 1094 | $languages = array(); |
1121 | | - foreach ( $res as $langRow ) { |
1122 | | - $languages[] = $langRow->not_language; |
| 1095 | + if ( $dbr->numRows( $row ) > 0 ) { |
| 1096 | + $res = $dbr->select( 'cn_notice_languages', 'nl_language', array( 'nl_notice_id' => $row->not_id ) ); |
| 1097 | + foreach ( $res as $langRow ) { |
| 1098 | + $languages[] = $langRow->nl_language; |
| 1099 | + } |
1123 | 1100 | } |
1124 | 1101 | return $languages; |
1125 | 1102 | } |
— | — | @@ -1314,18 +1291,17 @@ |
1315 | 1292 | $addLanguages = array_diff( $newLanguages, $oldLanguages ); |
1316 | 1293 | $insertArray = array(); |
1317 | 1294 | foreach( $addLanguages as $code ) { |
1318 | | - $insertArray[] = array( 'not_id' => $row->not_id, 'not_language' => $code ); |
| 1295 | + $insertArray[] = array( 'nl_notice_id' => $row->not_id, 'nl_language' => $code ); |
1319 | 1296 | } |
1320 | 1297 | $res = $dbw->insert( 'cn_notice_languages', $insertArray, __METHOD__, array( 'IGNORE' ) ); |
1321 | 1298 | |
1322 | 1299 | // Remove disassociated languages |
1323 | 1300 | $removeLanguages = array_diff( $oldLanguages, $newLanguages ); |
1324 | | - foreach( $removeLanguages as $code ) { |
| 1301 | + if ( !empty( $removeLanguages ) ) { |
1325 | 1302 | $res = $dbw->delete( 'cn_notice_languages', |
1326 | | - array( 'not_id' => $row->not_id, 'not_language' => $code ) |
| 1303 | + array( 'nl_notice_id' => $row->not_id, 'nl_language' => $removeLanguages ) |
1327 | 1304 | ); |
1328 | 1305 | } |
1329 | | - |
1330 | 1306 | $dbw->commit(); |
1331 | 1307 | } |
1332 | 1308 | |
Index: trunk/extensions/CentralNotice/patches/patch-notice_languages.sql |
— | — | @@ -1,8 +1,8 @@ |
2 | 2 | -- Update to allow for any number of languages per notice. |
3 | 3 | |
4 | 4 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_languages ( |
5 | | - `id` int unsigned NOT NULL PRIMARY KEY auto_increment, |
6 | | - `not_id` int unsigned NOT NULL, |
7 | | - `not_language` varchar(32) NOT NULL |
| 5 | + `nl_id` int unsigned NOT NULL PRIMARY KEY auto_increment, |
| 6 | + `nl_notice_id` int unsigned NOT NULL, |
| 7 | + `nl_language` varchar(32) NOT NULL |
8 | 8 | ) /*$wgDBTableOptions*/; |
9 | | -CREATE UNIQUE INDEX /*i*/cn_not_id_not_language ON /*$wgDBprefix*/cn_notice_languages (not_id, not_language); |
| 9 | +CREATE UNIQUE INDEX /*i*/nl_notice_id_language ON /*$wgDBprefix*/cn_notice_languages (nl_notice_id, nl_language); |
Index: trunk/extensions/CentralNotice/CentralNotice.sql |
— | — | @@ -25,8 +25,8 @@ |
26 | 26 | ) /*$wgDBTableOptions*/; |
27 | 27 | |
28 | 28 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/cn_notice_languages ( |
29 | | - `id` int unsigned NOT NULL PRIMARY KEY auto_increment, |
30 | | - `not_id` int unsigned NOT NULL, |
31 | | - `not_language` varchar(32) NOT NULL |
| 29 | + `nl_id` int unsigned NOT NULL PRIMARY KEY auto_increment, |
| 30 | + `nl_notice_id` int unsigned NOT NULL, |
| 31 | + `nl_language` varchar(32) NOT NULL |
32 | 32 | ) /*$wgDBTableOptions*/; |
33 | | -CREATE UNIQUE INDEX /*i*/cn_not_id_not_language ON /*$wgDBprefix*/cn_notice_languages (not_id, not_language); |
| 33 | +CREATE UNIQUE INDEX /*i*/nl_notice_id_language ON /*$wgDBprefix*/cn_notice_languages (nl_notice_id, nl_language); |
Index: trunk/extensions/CentralNotice/CentralNotice.db.php |
— | — | @@ -32,8 +32,8 @@ |
33 | 33 | $conds[] = "not_project =" . $dbr->addQuotes( $project ); |
34 | 34 | } |
35 | 35 | if ( $language ) { |
36 | | - $conds[] = "cn_notice_languages.not_id = cn_notices.not_id"; |
37 | | - $conds[] = "cn_notice_languages.not_language =" . $dbr->addQuotes( $language ); |
| 36 | + $conds[] = "nl_notice_id = cn_notices.not_id"; |
| 37 | + $conds[] = "nl_language =" . $dbr->addQuotes( $language ); |
38 | 38 | } |
39 | 39 | if ( $preferred ) { |
40 | 40 | $conds[] = "not_preferred = 1"; |