Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -185,8 +185,8 @@ |
186 | 186 | // Handle weight change |
187 | 187 | $updatedWeights = $wgRequest->getArray( 'weight' ); |
188 | 188 | if ( isset( $updatedWeights ) ) { |
189 | | - foreach ( $updatedWeights as $templateName => $weight ) { |
190 | | - $this->updateWeight( $noticeName, $templateName, $weight ); |
| 189 | + foreach ( $updatedWeights as $templateId => $weight ) { |
| 190 | + $this->updateWeight( $noticeName, $templateId, $weight ); |
191 | 191 | } |
192 | 192 | } |
193 | 193 | } |
— | — | @@ -280,12 +280,16 @@ |
281 | 281 | $wgOut->addHTML( $htmlOut ); |
282 | 282 | } |
283 | 283 | |
| 284 | + /** |
| 285 | + * Get all the campaigns in the database |
| 286 | + * @return an array of campaign names |
| 287 | + */ |
284 | 288 | function getNoticesName() { |
285 | 289 | $dbr = wfGetDB( DB_SLAVE ); |
286 | | - $res = $dbr->select( 'cn_notices', 'not_name' ); |
| 290 | + $res = $dbr->select( 'cn_notices', 'not_name', null, __METHOD__ ); |
287 | 291 | $notices = array(); |
288 | 292 | while ( $row = $dbr->fetchObject( $res ) ) { |
289 | | - array_push( $notices, $row->not_name ); |
| 293 | + $notices[] = $row->not_name; |
290 | 294 | } |
291 | 295 | return $notices; |
292 | 296 | } |
— | — | @@ -389,7 +393,7 @@ |
390 | 394 | ), |
391 | 395 | null, |
392 | 396 | __METHOD__, |
393 | | - array( 'ORDER BY' => 'not_id' ) |
| 397 | + array( 'ORDER BY' => 'not_id DESC' ) |
394 | 398 | ); |
395 | 399 | |
396 | 400 | // Begin building HTML |
— | — | @@ -624,8 +628,9 @@ |
625 | 629 | $templatesToAdd = $wgRequest->getArray( 'addTemplates' ); |
626 | 630 | if ( isset( $templatesToAdd ) ) { |
627 | 631 | $weight = $wgRequest->getArray( 'weight' ); |
628 | | - foreach ( $templatesToAdd as $template ) { |
629 | | - $this->addTemplateTo( $notice, $template, $weight[$template] ); |
| 632 | + foreach ( $templatesToAdd as $templateName ) { |
| 633 | + $templateId = $this->getTemplateId( $templateName ); |
| 634 | + $this->addTemplateTo( $notice, $templateName, $weight[$templateId] ); |
630 | 635 | } |
631 | 636 | } |
632 | 637 | $wgOut->redirect( $this->getTitle()->getLocalUrl( "method=listNoticeDetail¬ice=$notice" ) ); |
— | — | @@ -801,6 +806,7 @@ |
802 | 807 | 'cn_templates' |
803 | 808 | ), |
804 | 809 | array( |
| 810 | + 'cn_templates.tmp_id', |
805 | 811 | 'cn_templates.tmp_name', |
806 | 812 | 'cn_assignments.tmp_weight' |
807 | 813 | ), |
— | — | @@ -850,7 +856,7 @@ |
851 | 857 | |
852 | 858 | // Weight |
853 | 859 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
854 | | - $this->weightDropDown( "weight[$row->tmp_name]", $row->tmp_weight ) |
| 860 | + $this->weightDropDown( "weight[$row->tmp_id]", $row->tmp_weight ) |
855 | 861 | ); |
856 | 862 | |
857 | 863 | $viewPage = $this->getTitleFor( 'NoticeTemplate', 'view' ); |
— | — | @@ -1103,7 +1109,7 @@ |
1104 | 1110 | return $row->not_project; |
1105 | 1111 | } |
1106 | 1112 | |
1107 | | - function getTemplateId ( $templateName ) { |
| 1113 | + function getTemplateId( $templateName ) { |
1108 | 1114 | $dbr = wfGetDB( DB_SLAVE ); |
1109 | 1115 | $templateName = htmlspecialchars ( $templateName ); |
1110 | 1116 | $res = $dbr->select( 'cn_templates', 'tmp_id', array( 'tmp_name' => $templateName ) ); |
— | — | @@ -1173,11 +1179,9 @@ |
1174 | 1180 | } |
1175 | 1181 | } |
1176 | 1182 | |
1177 | | - function updateWeight ( $noticeName, $templateName, $weight ) { |
| 1183 | + function updateWeight( $noticeName, $templateId, $weight ) { |
1178 | 1184 | $dbw = wfGetDB( DB_MASTER ); |
1179 | | - $dbw->begin(); |
1180 | 1185 | $noticeId = $this->getNoticeId( $noticeName ); |
1181 | | - $templateId = $this->getTemplateId( $templateName ); |
1182 | 1186 | $dbw->update( 'cn_assignments', |
1183 | 1187 | array ( 'tmp_weight' => $weight ), |
1184 | 1188 | array( |
— | — | @@ -1185,7 +1189,6 @@ |
1186 | 1190 | 'not_id' => $noticeId |
1187 | 1191 | ) |
1188 | 1192 | ); |
1189 | | - $dbw->commit(); |
1190 | 1193 | } |
1191 | 1194 | |
1192 | 1195 | function projectDropDownList( $selected = '' ) { |
— | — | @@ -1365,7 +1368,7 @@ |
1366 | 1369 | ); |
1367 | 1370 | // Weight select |
1368 | 1371 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
1369 | | - Xml::listDropDown( "weight[$row->tmp_name]", |
| 1372 | + Xml::listDropDown( "weight[$row->tmp_id]", |
1370 | 1373 | CentralNotice::dropDownList( wfMsg( 'centralnotice-weight' ), range ( 0, 100, 5 ) ) , |
1371 | 1374 | '', |
1372 | 1375 | '25', |