r71595 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71594‎ | r71595 | r71596 >
Date:22:23, 24 August 2010
Author:kaldari
Status:ok
Tags:
Comment:
cleaning up queries, switching weight indexes to ids (per r71057), switching campaign list to reverse chronological
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -185,8 +185,8 @@
186186 // Handle weight change
187187 $updatedWeights = $wgRequest->getArray( 'weight' );
188188 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 );
191191 }
192192 }
193193 }
@@ -280,12 +280,16 @@
281281 $wgOut->addHTML( $htmlOut );
282282 }
283283
 284+ /**
 285+ * Get all the campaigns in the database
 286+ * @return an array of campaign names
 287+ */
284288 function getNoticesName() {
285289 $dbr = wfGetDB( DB_SLAVE );
286 - $res = $dbr->select( 'cn_notices', 'not_name' );
 290+ $res = $dbr->select( 'cn_notices', 'not_name', null, __METHOD__ );
287291 $notices = array();
288292 while ( $row = $dbr->fetchObject( $res ) ) {
289 - array_push( $notices, $row->not_name );
 293+ $notices[] = $row->not_name;
290294 }
291295 return $notices;
292296 }
@@ -389,7 +393,7 @@
390394 ),
391395 null,
392396 __METHOD__,
393 - array( 'ORDER BY' => 'not_id' )
 397+ array( 'ORDER BY' => 'not_id DESC' )
394398 );
395399
396400 // Begin building HTML
@@ -624,8 +628,9 @@
625629 $templatesToAdd = $wgRequest->getArray( 'addTemplates' );
626630 if ( isset( $templatesToAdd ) ) {
627631 $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] );
630635 }
631636 }
632637 $wgOut->redirect( $this->getTitle()->getLocalUrl( "method=listNoticeDetail&notice=$notice" ) );
@@ -801,6 +806,7 @@
802807 'cn_templates'
803808 ),
804809 array(
 810+ 'cn_templates.tmp_id',
805811 'cn_templates.tmp_name',
806812 'cn_assignments.tmp_weight'
807813 ),
@@ -850,7 +856,7 @@
851857
852858 // Weight
853859 $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 )
855861 );
856862
857863 $viewPage = $this->getTitleFor( 'NoticeTemplate', 'view' );
@@ -1103,7 +1109,7 @@
11041110 return $row->not_project;
11051111 }
11061112
1107 - function getTemplateId ( $templateName ) {
 1113+ function getTemplateId( $templateName ) {
11081114 $dbr = wfGetDB( DB_SLAVE );
11091115 $templateName = htmlspecialchars ( $templateName );
11101116 $res = $dbr->select( 'cn_templates', 'tmp_id', array( 'tmp_name' => $templateName ) );
@@ -1173,11 +1179,9 @@
11741180 }
11751181 }
11761182
1177 - function updateWeight ( $noticeName, $templateName, $weight ) {
 1183+ function updateWeight( $noticeName, $templateId, $weight ) {
11781184 $dbw = wfGetDB( DB_MASTER );
1179 - $dbw->begin();
11801185 $noticeId = $this->getNoticeId( $noticeName );
1181 - $templateId = $this->getTemplateId( $templateName );
11821186 $dbw->update( 'cn_assignments',
11831187 array ( 'tmp_weight' => $weight ),
11841188 array(
@@ -1185,7 +1189,6 @@
11861190 'not_id' => $noticeId
11871191 )
11881192 );
1189 - $dbw->commit();
11901193 }
11911194
11921195 function projectDropDownList( $selected = '' ) {
@@ -1365,7 +1368,7 @@
13661369 );
13671370 // Weight select
13681371 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
1369 - Xml::listDropDown( "weight[$row->tmp_name]",
 1372+ Xml::listDropDown( "weight[$row->tmp_id]",
13701373 CentralNotice::dropDownList( wfMsg( 'centralnotice-weight' ), range ( 0, 100, 5 ) ) ,
13711374 '',
13721375 '25',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r71057implement banner pagination for edit campaign interfacekaldari23:43, 13 August 2010

Status & tagging log