r71982 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71981‎ | r71982 | r71983 >
Date:21:52, 30 August 2010
Author:kaldari
Status:ok
Tags:
Comment:
moving the rest of the campaign detail functions to listNoticeDetail() so that the forms are handled separately, removing array names for checkboxes where they are no longer needed, fixing DB var error
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -48,6 +48,14 @@
4949
5050 $method = $wgRequest->getVal( 'method' );
5151
 52+ // Handle showing campaign detail
 53+ if ( $method == 'listNoticeDetail' ) {
 54+ $notice = $wgRequest->getVal ( 'notice' );
 55+ $this->listNoticeDetail( $notice );
 56+ $wgOut->addHTML( Xml::closeElement( 'div' ) );
 57+ return;
 58+ }
 59+
5260 // Handle form submissions
5361 if ( $this->editable && $wgRequest->wasPosted() ) {
5462
@@ -71,121 +79,66 @@
7280 // Handle locking/unlocking campaigns
7381 $lockedNotices = $wgRequest->getArray( 'locked' );
7482 if ( $lockedNotices ) {
75 - if ( $method == 'listNoticeDetail' ) {
76 - $notice = $wgRequest->getVal ( 'notice' );
 83+ // Build list of campaigns to lock
 84+ $unlockedNotices = array_diff( $this->getNoticesName(), $lockedNotices );
 85+
 86+ // Set locked/unlocked flag accordingly
 87+ foreach ( $lockedNotices as $notice ) {
7788 $this->updateLock( $notice, '1' );
78 - } else {
79 - // Build list of campaigns to lock
80 - $unlockedNotices = array_diff( $this->getNoticesName(), $lockedNotices );
81 -
82 - // Set locked/unlocked flag accordingly
83 - foreach ( $lockedNotices as $notice ) {
84 - $this->updateLock( $notice, '1' );
85 - }
86 - foreach ( $unlockedNotices as $notice ) {
87 - $this->updateLock( $notice, '0' );
88 - }
8989 }
 90+ foreach ( $unlockedNotices as $notice ) {
 91+ $this->updateLock( $notice, '0' );
 92+ }
 93+ // Handle updates if no post content came through (all checkboxes unchecked)
 94+ } elseif ( $method !== 'addNotice' ) {
 95+ $allNotices = $this->getNoticesName();
 96+ foreach ( $allNotices as $notice ) {
 97+ $this->updateLock( $notice, '0' );
 98+ }
9099 }
91100
92101 // Handle enabling/disabling campaigns
93102 $enabledNotices = $wgRequest->getArray( 'enabled' );
94103 if ( $enabledNotices ) {
95 - if ( $method == 'listNoticeDetail' ) {
96 - $notice = $wgRequest->getVal ( 'notice' );
 104+ // Build list of campaigns to disable
 105+ $disabledNotices = array_diff( $this->getNoticesName(), $enabledNotices );
 106+
 107+ // Set enabled/disabled flag accordingly
 108+ foreach ( $enabledNotices as $notice ) {
97109 $this->updateEnabled( $notice, '1' );
98 - } else {
99 - // Build list of campaigns to disable
100 - $disabledNotices = array_diff( $this->getNoticesName(), $enabledNotices );
101 -
102 - // Set enabled/disabled flag accordingly
103 - foreach ( $enabledNotices as $notice ) {
104 - $this->updateEnabled( $notice, '1' );
105 - }
106 - foreach ( $disabledNotices as $notice ) {
107 - $this->updateEnabled( $notice, '0' );
108 - }
109110 }
 111+ foreach ( $disabledNotices as $notice ) {
 112+ $this->updateEnabled( $notice, '0' );
 113+ }
 114+ // Handle updates if no post content came through (all checkboxes unchecked)
 115+ } elseif ( $method !== 'addNotice' ) {
 116+ $allNotices = $this->getNoticesName();
 117+ foreach ( $allNotices as $notice ) {
 118+ $this->updateEnabled( $notice, '0' );
 119+ }
110120 }
111121
112122 // Handle setting preferred campaigns
113123 $preferredNotices = $wgRequest->getArray( 'preferred' );
114124 if ( $preferredNotices ) {
115 - // Set since this is a single display
116 - if ( $method == 'listNoticeDetail' ) {
117 - $notice = $wgRequest->getVal ( 'notice' );
 125+ // Build list of campaigns to unset
 126+ $unsetNotices = array_diff( $this->getNoticesName(), $preferredNotices );
 127+
 128+ // Set flag accordingly
 129+ foreach ( $preferredNotices as $notice ) {
118130 $this->updatePreferred( $notice, '1' );
119131 }
120 - else {
121 - // Build list of campaigns to unset
122 - $unsetNotices = array_diff( $this->getNoticesName(), $preferredNotices );
123 -
124 - // Set flag accordingly
125 - foreach ( $preferredNotices as $notice ) {
126 - $this->updatePreferred( $notice, '1' );
127 - }
128 - foreach ( $unsetNotices as $notice ) {
129 - $this->updatePreferred( $notice, '0' );
130 - }
 132+ foreach ( $unsetNotices as $notice ) {
 133+ $this->updatePreferred( $notice, '0' );
131134 }
132 - }
133 -
134 - $noticeName = $wgRequest->getVal( 'notice' );
135 -
136 - // Handle range setting
137 - $start = $wgRequest->getArray( 'start' );
138 - $end = $wgRequest->getArray( 'end' );
139 - if ( $start && $end ) {
140 - $updatedStart = sprintf( "%04d%02d%02d%02d%02d00",
141 - $start['year'],
142 - $start['month'],
143 - $start['day'],
144 - $start['hour'],
145 - $start['min'] );
146 - $updatedEnd = sprintf( "%04d%02d%02d000000",
147 - $end['year'],
148 - $end['month'],
149 - $end['day'] );
150 - $this->updateNoticeDate( $noticeName, $updatedStart, $updatedEnd );
151 - }
152 -
153 - // Handle updates if no post content came through
154 - if ( !$lockedNotices && $method !== 'addNotice' ) {
155 - if ( $method == 'listNoticeDetail' ) {
156 - $notice = $wgRequest->getVal ( 'notice' );
157 - $this->updateLock( $notice, 0 );
158 - } else {
159 - $allNotices = $this->getNoticesName();
160 - foreach ( $allNotices as $notice ) {
161 - $this->updateLock( $notice, '0' );
162 - }
 135+ // Handle updates if no post content came through (all checkboxes unchecked)
 136+ } elseif ( $method !== 'addNotice' ) {
 137+ $allNotices = $this->getNoticesName();
 138+ foreach ( $allNotices as $notice ) {
 139+ $this->updatePreferred( $notice, '0' );
163140 }
164141 }
165142
166 - if ( !$enabledNotices && $method !== 'addNotice' ) {
167 - if ( $method == 'listNoticeDetail' ) {
168 - $notice = $wgRequest->getVal ( 'notice' );
169 - $this->updateEnabled( $notice, 0 );
170 - } else {
171 - $allNotices = $this->getNoticesName();
172 - foreach ( $allNotices as $notice ) {
173 - $this->updateEnabled( $notice, '0' );
174 - }
175 - }
176 - }
177 -
178 - if ( !$preferredNotices && $method !== 'addNotice' ) {
179 - if ( $method == 'listNoticeDetail' ) {
180 - $notice = $wgRequest->getVal ( 'notice' );
181 - $this->updatePreferred( $notice, 0 );
182 - } else {
183 - $allNotices = $this->getNoticesName();
184 - foreach ( $allNotices as $notice ) {
185 - $this->updatePreferred( $notice, '0' );
186 - }
187 - }
188 - }
189 -
190143 // Handle adding of campaign
191144 if ( $method == 'addNotice' ) {
192145 $noticeName = $wgRequest->getVal( 'noticeName' );
@@ -205,14 +158,6 @@
206159
207160 }
208161
209 - // Handle showing campaign detail
210 - if ( $method == 'listNoticeDetail' ) {
211 - $notice = $wgRequest->getVal ( 'notice' );
212 - $this->listNoticeDetail( $notice );
213 - $wgOut->addHTML( Xml::closeElement( 'div' ) );
214 - return;
215 - }
216 -
217162 // Show list of campaigns
218163 $this->listNotices();
219164
@@ -573,7 +518,7 @@
574519
575520 function listNoticeDetail( $notice ) {
576521 global $wgOut, $wgRequest, $wgUser;
577 -
 522+
578523 // Make sure notice exists
579524 if ( !$this->noticeExists( $notice ) ) {
580525 $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-doesnt-exist' );
@@ -584,6 +529,53 @@
585530 // Check authentication token
586531 if ( $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
587532
 533+ // Handle removing campaign
 534+ if ( $wgRequest->getVal( 'remove' ) ) {
 535+ $this->removeNotice( $notice );
 536+
 537+ // Leave campaign detail interface
 538+ $wgOut->redirect( $this->getTitle()->getLocalUrl() );
 539+ return;
 540+ }
 541+
 542+ // Handle locking/unlocking campaign
 543+ if ( $wgRequest->getArray( 'locked' ) ) {
 544+ $this->updateLock( $notice, '1' );
 545+ } else {
 546+ $this->updateLock( $notice, 0 );
 547+ }
 548+
 549+ // Handle enabling/disabling campaign
 550+ if ( $wgRequest->getArray( 'enabled' ) ) {
 551+ $this->updateEnabled( $notice, '1' );
 552+ } else {
 553+ $this->updateEnabled( $notice, 0 );
 554+ }
 555+
 556+ // Handle setting campaign to preferred/not preferred
 557+ if ( $wgRequest->getArray( 'preferred' ) ) {
 558+ $this->updatePreferred( $notice, '1' );
 559+ } else {
 560+ $this->updatePreferred( $notice, 0 );
 561+ }
 562+
 563+ // Handle updating the start and end settings
 564+ $start = $wgRequest->getArray( 'start' );
 565+ $end = $wgRequest->getArray( 'end' );
 566+ if ( $start && $end ) {
 567+ $updatedStart = sprintf( "%04d%02d%02d%02d%02d00",
 568+ $start['year'],
 569+ $start['month'],
 570+ $start['day'],
 571+ $start['hour'],
 572+ $start['min'] );
 573+ $updatedEnd = sprintf( "%04d%02d%02d000000",
 574+ $end['year'],
 575+ $end['month'],
 576+ $end['day'] );
 577+ $this->updateNoticeDate( $notice, $updatedStart, $updatedEnd );
 578+ }
 579+
588580 // Handle adding of banners to the campaign
589581 $templatesToAdd = $wgRequest->getArray( 'addTemplates' );
590582 if ( $templatesToAdd ) {
@@ -774,24 +766,24 @@
775767 $htmlOut .= Xml::closeElement( 'tr' );
776768 // Enabled
777769 $htmlOut .= Xml::openElement( 'tr' );
778 - $htmlOut .= Xml::tags( 'td', array(), Xml::label( wfMsgHtml( 'centralnotice-enabled' ), 'enabled[]' ) );
779 - $htmlOut .= Xml::tags( 'td', array(), Xml::check( 'enabled[]', ( $row->not_enabled == '1' ), wfArrayMerge( $readonly, array( 'value' => $row->not_name, 'id' => 'enabled[]' ) ) ) );
 770+ $htmlOut .= Xml::tags( 'td', array(), Xml::label( wfMsgHtml( 'centralnotice-enabled' ), 'enabled' ) );
 771+ $htmlOut .= Xml::tags( 'td', array(), Xml::check( 'enabled', ( $row->not_enabled == '1' ), wfArrayMerge( $readonly, array( 'value' => $row->not_name, 'id' => 'enabled' ) ) ) );
780772 $htmlOut .= Xml::closeElement( 'tr' );
781773 // Preferred
782774 $htmlOut .= Xml::openElement( 'tr' );
783 - $htmlOut .= Xml::tags( 'td', array(), Xml::label( wfMsgHtml( 'centralnotice-preferred' ), 'preferred[]' ) );
784 - $htmlOut .= Xml::tags( 'td', array(), Xml::check( 'preferred[]', ( $row->not_preferred == '1' ), wfArrayMerge( $readonly, array( 'value' => $row->not_name, 'id' => 'preferred[]' ) ) ) );
 775+ $htmlOut .= Xml::tags( 'td', array(), Xml::label( wfMsgHtml( 'centralnotice-preferred' ), 'preferred' ) );
 776+ $htmlOut .= Xml::tags( 'td', array(), Xml::check( 'preferred', ( $row->not_preferred == '1' ), wfArrayMerge( $readonly, array( 'value' => $row->not_name, 'id' => 'preferred' ) ) ) );
785777 $htmlOut .= Xml::closeElement( 'tr' );
786778 // Locked
787779 $htmlOut .= Xml::openElement( 'tr' );
788 - $htmlOut .= Xml::tags( 'td', array(), Xml::label( wfMsgHtml( 'centralnotice-locked' ), 'locked[]' ) );
789 - $htmlOut .= Xml::tags( 'td', array(), Xml::check( 'locked[]', ( $row->not_locked == '1' ), wfArrayMerge( $readonly, array( 'value' => $row->not_name, 'id' => 'locked[]' ) ) ) );
 780+ $htmlOut .= Xml::tags( 'td', array(), Xml::label( wfMsgHtml( 'centralnotice-locked' ), 'locked' ) );
 781+ $htmlOut .= Xml::tags( 'td', array(), Xml::check( 'locked', ( $row->not_locked == '1' ), wfArrayMerge( $readonly, array( 'value' => $row->not_name, 'id' => 'locked' ) ) ) );
790782 $htmlOut .= Xml::closeElement( 'tr' );
791783 if ( $this->editable ) {
792784 // Locked
793785 $htmlOut .= Xml::openElement( 'tr' );
794 - $htmlOut .= Xml::tags( 'td', array(), Xml::label( wfMsgHtml( 'centralnotice-remove' ), 'removeNotices[]' ) );
795 - $htmlOut .= Xml::tags( 'td', array(), Xml::check( 'removeNotices[]', false, array( 'value' => $row->not_name, 'id' => 'removeNotices[]' ) ) );
 786+ $htmlOut .= Xml::tags( 'td', array(), Xml::label( wfMsgHtml( 'centralnotice-remove' ), 'remove' ) );
 787+ $htmlOut .= Xml::tags( 'td', array(), Xml::check( 'remove', false, array( 'value' => $row->not_name, 'id' => 'remove' ) ) );
796788 $htmlOut .= Xml::closeElement( 'tr' );
797789 }
798790 $htmlOut .= Xml::closeElement( 'table' );
@@ -1010,8 +1002,8 @@
10111003 $res = $dbw->insert( 'cn_notices',
10121004 array( 'not_name' => $noticeName,
10131005 'not_enabled' => $enabled,
1014 - 'not_start' => $dbr->timestamp( $startTs ),
1015 - 'not_end' => $dbr->timestamp( $endTs ),
 1006+ 'not_start' => $dbw->timestamp( $startTs ),
 1007+ 'not_end' => $dbw->timestamp( $endTs ),
10161008 'not_project' => $project_name
10171009 )
10181010 );

Status & tagging log