Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -48,6 +48,14 @@ |
49 | 49 | |
50 | 50 | $method = $wgRequest->getVal( 'method' ); |
51 | 51 | |
| 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 | + |
52 | 60 | // Handle form submissions |
53 | 61 | if ( $this->editable && $wgRequest->wasPosted() ) { |
54 | 62 | |
— | — | @@ -71,121 +79,66 @@ |
72 | 80 | // Handle locking/unlocking campaigns |
73 | 81 | $lockedNotices = $wgRequest->getArray( 'locked' ); |
74 | 82 | 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 ) { |
77 | 88 | $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 | | - } |
89 | 89 | } |
| 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 | + } |
90 | 99 | } |
91 | 100 | |
92 | 101 | // Handle enabling/disabling campaigns |
93 | 102 | $enabledNotices = $wgRequest->getArray( 'enabled' ); |
94 | 103 | 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 ) { |
97 | 109 | $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 | | - } |
109 | 110 | } |
| 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 | + } |
110 | 120 | } |
111 | 121 | |
112 | 122 | // Handle setting preferred campaigns |
113 | 123 | $preferredNotices = $wgRequest->getArray( 'preferred' ); |
114 | 124 | 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 ) { |
118 | 130 | $this->updatePreferred( $notice, '1' ); |
119 | 131 | } |
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' ); |
131 | 134 | } |
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' ); |
163 | 140 | } |
164 | 141 | } |
165 | 142 | |
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 | | - |
190 | 143 | // Handle adding of campaign |
191 | 144 | if ( $method == 'addNotice' ) { |
192 | 145 | $noticeName = $wgRequest->getVal( 'noticeName' ); |
— | — | @@ -205,14 +158,6 @@ |
206 | 159 | |
207 | 160 | } |
208 | 161 | |
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 | | - |
217 | 162 | // Show list of campaigns |
218 | 163 | $this->listNotices(); |
219 | 164 | |
— | — | @@ -573,7 +518,7 @@ |
574 | 519 | |
575 | 520 | function listNoticeDetail( $notice ) { |
576 | 521 | global $wgOut, $wgRequest, $wgUser; |
577 | | - |
| 522 | + |
578 | 523 | // Make sure notice exists |
579 | 524 | if ( !$this->noticeExists( $notice ) ) { |
580 | 525 | $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-doesnt-exist' ); |
— | — | @@ -584,6 +529,53 @@ |
585 | 530 | // Check authentication token |
586 | 531 | if ( $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) { |
587 | 532 | |
| 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 | + |
588 | 580 | // Handle adding of banners to the campaign |
589 | 581 | $templatesToAdd = $wgRequest->getArray( 'addTemplates' ); |
590 | 582 | if ( $templatesToAdd ) { |
— | — | @@ -774,24 +766,24 @@ |
775 | 767 | $htmlOut .= Xml::closeElement( 'tr' ); |
776 | 768 | // Enabled |
777 | 769 | $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' ) ) ) ); |
780 | 772 | $htmlOut .= Xml::closeElement( 'tr' ); |
781 | 773 | // Preferred |
782 | 774 | $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' ) ) ) ); |
785 | 777 | $htmlOut .= Xml::closeElement( 'tr' ); |
786 | 778 | // Locked |
787 | 779 | $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' ) ) ) ); |
790 | 782 | $htmlOut .= Xml::closeElement( 'tr' ); |
791 | 783 | if ( $this->editable ) { |
792 | 784 | // Locked |
793 | 785 | $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' ) ) ); |
796 | 788 | $htmlOut .= Xml::closeElement( 'tr' ); |
797 | 789 | } |
798 | 790 | $htmlOut .= Xml::closeElement( 'table' ); |
— | — | @@ -1010,8 +1002,8 @@ |
1011 | 1003 | $res = $dbw->insert( 'cn_notices', |
1012 | 1004 | array( 'not_name' => $noticeName, |
1013 | 1005 | '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 ), |
1016 | 1008 | 'not_project' => $project_name |
1017 | 1009 | ) |
1018 | 1010 | ); |