Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -228,19 +228,6 @@ |
229 | 229 | $wgOut->addHTML( Xml::closeElement( 'div' ) ); |
230 | 230 | } |
231 | 231 | |
232 | | - /** |
233 | | - * Update the enabled/disabled state of a campaign |
234 | | - */ |
235 | | - private function updateEnabled( $notice, $state ) { |
236 | | - $dbw = wfGetDB( DB_MASTER ); |
237 | | - $dbw->begin(); |
238 | | - $res = $dbw->update( 'cn_notices', |
239 | | - array( 'not_enabled' => $state ), |
240 | | - array( 'not_name' => $notice ) |
241 | | - ); |
242 | | - $dbw->commit(); |
243 | | - } |
244 | | - |
245 | 232 | public static function printHeader() { |
246 | 233 | global $wgOut, $wgTitle, $wgUser; |
247 | 234 | $sk = $wgUser->getSkin(); |
— | — | @@ -1000,9 +987,7 @@ |
1001 | 988 | function addNotice( $noticeName, $enabled, $start, $project_name, $project_languages ) { |
1002 | 989 | global $wgOut; |
1003 | 990 | |
1004 | | - $dbr = wfGetDB( DB_SLAVE ); |
1005 | | - $res = $dbr->select( 'cn_notices', 'not_name', array( 'not_name' => $noticeName ) ); |
1006 | | - if ( $dbr->numRows( $res ) > 0 ) { |
| 991 | + if ( $this->noticeExists( $noticeName ) ) { |
1007 | 992 | $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-exists' ); |
1008 | 993 | return; |
1009 | 994 | } elseif ( empty( $project_languages ) ) { |
— | — | @@ -1116,7 +1101,7 @@ |
1117 | 1102 | if ( $row ) { |
1118 | 1103 | return $row->not_id; |
1119 | 1104 | } else { |
1120 | | - return; |
| 1105 | + return null; |
1121 | 1106 | } |
1122 | 1107 | } |
1123 | 1108 | |
— | — | @@ -1171,8 +1156,7 @@ |
1172 | 1157 | } |
1173 | 1158 | |
1174 | 1159 | // Invalid campaign name |
1175 | | - $row = $dbr->selectRow( 'cn_notices', 'not_name', array( 'not_name' => $noticeName ) ); |
1176 | | - if ( !$row ) { |
| 1160 | + if ( !$this->noticeExists( $noticeName ) ) { |
1177 | 1161 | $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-doesnt-exist' ); |
1178 | 1162 | return; |
1179 | 1163 | } |
— | — | @@ -1191,23 +1175,54 @@ |
1192 | 1176 | ); |
1193 | 1177 | } |
1194 | 1178 | |
| 1179 | + /** |
| 1180 | + * Update the enabled/disabled state of a campaign |
| 1181 | + */ |
| 1182 | + private function updateEnabled( $noticeName, $isEnabled ) { |
| 1183 | + global $wgOut; |
| 1184 | + |
| 1185 | + if ( !$this->noticeExists( $noticeName ) ) { |
| 1186 | + $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' ); |
| 1187 | + } else { |
| 1188 | + $dbw = wfGetDB( DB_MASTER ); |
| 1189 | + $res = $dbw->update( 'cn_notices', |
| 1190 | + array( 'not_enabled' => $isEnabled ), |
| 1191 | + array( 'not_name' => $noticeName ) |
| 1192 | + ); |
| 1193 | + } |
| 1194 | + } |
| 1195 | + |
| 1196 | + /** |
| 1197 | + * Update the preferred/not preferred state of a campaign |
| 1198 | + */ |
| 1199 | + function updatePreferred( $noticeName, $isPreferred ) { |
| 1200 | + global $wgOut; |
| 1201 | + |
| 1202 | + if ( !$this->noticeExists( $noticeName ) ) { |
| 1203 | + $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' ); |
| 1204 | + } else { |
| 1205 | + $dbw = wfGetDB( DB_MASTER ); |
| 1206 | + $res = $dbw->update( 'cn_notices', |
| 1207 | + array( 'not_preferred' => $isPreferred ), |
| 1208 | + array( 'not_name' => $noticeName ) |
| 1209 | + ); |
| 1210 | + } |
| 1211 | + } |
| 1212 | + |
| 1213 | + /** |
| 1214 | + * Update the locked/unlocked state of a campaign |
| 1215 | + */ |
1195 | 1216 | function updateLock( $noticeName, $isLocked ) { |
1196 | 1217 | global $wgOut; |
1197 | 1218 | |
1198 | | - $dbr = wfGetDB( DB_SLAVE ); |
1199 | | - $res = $dbr->select( 'cn_notices', 'not_name', |
1200 | | - array( 'not_name' => $noticeName ) |
1201 | | - ); |
1202 | | - if ( $dbr->numRows( $res ) < 1 ) { |
| 1219 | + if ( !$this->noticeExists( $noticeName ) ) { |
1203 | 1220 | $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' ); |
1204 | 1221 | } else { |
1205 | 1222 | $dbw = wfGetDB( DB_MASTER ); |
1206 | | - $dbw->begin(); |
1207 | 1223 | $res = $dbw->update( 'cn_notices', |
1208 | 1224 | array( 'not_locked' => $isLocked ), |
1209 | 1225 | array( 'not_name' => $noticeName ) |
1210 | 1226 | ); |
1211 | | - $dbw->commit(); |
1212 | 1227 | } |
1213 | 1228 | } |
1214 | 1229 | |
— | — | @@ -1296,14 +1311,12 @@ |
1297 | 1312 | |
1298 | 1313 | function updateProjectName( $notice, $projectName ) { |
1299 | 1314 | $dbw = wfGetDB( DB_MASTER ); |
1300 | | - $dbw->begin(); |
1301 | 1315 | $res = $dbw->update( 'cn_notices', |
1302 | 1316 | array ( 'not_project' => $projectName ), |
1303 | 1317 | array( |
1304 | 1318 | 'not_name' => $notice |
1305 | 1319 | ) |
1306 | 1320 | ); |
1307 | | - $dbw->commit(); |
1308 | 1321 | } |
1309 | 1322 | |
1310 | 1323 | function updateProjectLanguages( $notice, $newLanguages ) { |
— | — | @@ -1335,6 +1348,17 @@ |
1336 | 1349 | |
1337 | 1350 | $dbw->commit(); |
1338 | 1351 | } |
| 1352 | + |
| 1353 | + public static function noticeExists( $noticeName ) { |
| 1354 | + $dbr = wfGetDB( DB_SLAVE ); |
| 1355 | + $eNoticeName = htmlspecialchars( $noticeName ); |
| 1356 | + $row = $dbr->selectRow( 'cn_notices', 'not_name', array( 'not_name' => $eNoticeName ) ); |
| 1357 | + if ( $row ) { |
| 1358 | + return true; |
| 1359 | + } else { |
| 1360 | + return false; |
| 1361 | + } |
| 1362 | + } |
1339 | 1363 | |
1340 | 1364 | public static function dropDownList( $text, $values ) { |
1341 | 1365 | $dropDown = "* {$text}\n"; |
Index: trunk/extensions/CentralNotice/CentralNotice.db.php |
— | — | @@ -118,20 +118,5 @@ |
119 | 119 | } |
120 | 120 | return $templates; |
121 | 121 | } |
122 | | - |
123 | | - public function updatePreferred( $notice, $preferred ) { |
124 | | - $dbw = wfGetDB( DB_MASTER ); |
125 | | - $dbw->begin(); |
126 | | - |
127 | | - $res = $dbw->update( 'cn_notices', |
128 | | - array( |
129 | | - 'not_preferred' => $preferred, |
130 | | - ), |
131 | | - array( |
132 | | - 'not_name' => $notice |
133 | | - ) |
134 | | - ); |
135 | | - $dbw->commit(); |
136 | | - return $res; |
137 | | - } |
| 122 | + |
138 | 123 | } |