r42333 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42332‎ | r42333 | r42334 >
Date:10:56, 22 October 2008
Author:tomasz
Status:old
Tags:
Comment:
adding template writes. fixed bug in lang notice addition. db column name normalize. color markup on translations.
Modified paths:
  • /branches/CentralNotice-SpecialPage-Integration/CentralNotice.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/CentralNotice_body.php (deleted) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeCentral.php (added) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php (modified) (history)
  • /branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTranslate.php (modified) (history)

Diff [purge]

Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice_body.php
@@ -1,514 +0,0 @@
2 -<?php
3 -
4 -if ( !defined( 'MEDIAWIKI' ) ) {
5 - echo "CentralNotice extension\n";
6 - exit( 1 );
7 -}
8 -
9 -class CentralNotice extends SpecialPage
10 -{
11 - function CentralNotice() {
12 - SpecialPage::SpecialPage("CentralNotice");
13 - wfLoadExtensionMessages('CentralNotice');
14 - }
15 -
16 - function execute( $sub ) {
17 - global $wgOut, $wgUser, $wgRequest;
18 -
19 - $this->setHeaders();
20 - $sk = $wgUser->getSkin();
21 -
22 - if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' )) {
23 - $wgOut->permissionRequired( 'centralnotice_admin_rights' );
24 - return;
25 - }
26 -
27 - $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ));
28 - $this->printHeader();
29 -
30 -
31 - if ( $wgRequest->wasPosted() ) {
32 - $body = file_get_contents('php://input');
33 - $wgOut->addHtml("Body of post: $body");
34 -
35 - $toRemove = $wgRequest->getArray('removeNotices');
36 - if ( isset($toRemove) ){
37 - foreach ( $toRemove as $template ) {
38 - $this->removeNotice( $template );
39 - }
40 - $this->listNotices();
41 - return;
42 - }
43 -
44 - $lockedNotices = $wgRequest->getArray('locked');
45 - if ( isset( $lockedNotices ) ) {
46 - $allNotices = $this->getNoticesName();
47 - $diff_set = array_diff( $allNotices, $lockedNotices);
48 -
49 - foreach( $lockedNotices as $notice ) {
50 - $this->updateLock( $notice, 'Y' );
51 - }
52 -
53 - foreach( $diff_set as $notice ) {
54 - $this->updateLock( $notice, 'N' );
55 - }
56 - }
57 - $enabledNotices = $wgRequest->getArray('enabled');
58 - if ( isset( $enabledNotices ) ) {
59 - $allNotices = $this->getNoticesName();
60 - $diff_set = array_diff( $allNotices, $enabledNotices);
61 -
62 - foreach ( $enabledNotices as $notice) {
63 - $this->updateEnabled( $notice, 'Y');
64 - }
65 - foreach ( $diff_set as $notice) {
66 - $this->updateEnabled( $notice, 'N');
67 - }
68 - }
69 - $start_date = $wgRequest->getArray('start_date');
70 - if ( isset( $start_date ) ) {
71 - foreach( $start_date as $noticeName => $date_value ) {
72 - $updatedStartDate = '';
73 - foreach ( $date_value as $date_portion => $value) {
74 - $updatedStartDate .= $value;
75 - }
76 - $updatedStartDate .= "000000";
77 - $this->updateStartDate( $noticeName, $updatedStartDate);
78 - }
79 - }
80 - $end_date = $wgRequest->getArray('end_date');
81 - if ( isset( $end_date ) ) {
82 - foreach( $end_date as $noticeName => $date_value ) {
83 - $updatedEndDate = '';
84 - foreach ( $date_value as $date_portion => $value) {
85 - $updatedEndDate .= $value;
86 - }
87 - $updatedEndDate .= "000000";
88 - $this->updateEndDate( $noticeName, $updatedEndDate);
89 - }
90 - }
91 - $noticeName = $wgRequest->getVal('notice');
92 - $updatedWeights = $wgRequest->getArray('weight');
93 - if ( isset( $updatedWeights ) ) {
94 - foreach( $updatedWeights as $templateName => $weight) {
95 - $this->updateWeight( $noticeName, $templateName, $weight);
96 - }
97 - }
98 - }
99 -
100 - $method = $wgRequest->getVal('method');
101 - $this->showAll = $wgRequest->getVal('showAll');
102 -
103 - if ( $method == 'addNotice' ) {
104 - $noticeName = $wgRequest->getVal('noticeName');
105 - $start_day = $wgRequest->getVal('start_day');
106 - $start_month = $wgRequest->getVal('start_month');
107 - $start_year = $wgRequest->getVal('start_year');
108 - $project_name = $wgRequest->getVal('project_name');
109 - $project_language = $wgRequest->getVal('project_lang');
110 - if ( $noticeName == '') {
111 - $wgOut->addHtml("Can't add a null string");
112 - }
113 - else {
114 - $this->addNotice( $noticeName, 'N', $start_year, $start_month, $start_day, $project_name, $project_language );
115 - }
116 - }
117 - if ( $method == 'removeNotice' ) {
118 - $noticeName = $wgRequest->getVal ('noticeName');
119 - $this->removeNotice ( $noticeName );
120 - }
121 - if ( $method == 'addTemplateTo') {
122 - $noticeName = $wgRequest->getVal('noticeName');
123 - $templateName = $wgRequest->getVal('templateName');
124 - $this->addTemplateTo($noticeName, $templateName, 0);
125 - $this->listNoticeDetail( $noticeName );
126 - return;
127 - }
128 - if ( $method == 'removeTemplateFor') {
129 - $noticeName = $wgRequest->getVal ( 'noticeName');
130 - $templateName = $wgRequest->getVal ( 'templateName ');
131 - $this->removeTemplateFor( $noticeName , $templateName );
132 - }
133 - if ( $method == 'listNoticeDetail') {
134 - $notice = $wgRequest->getVal ( 'notice' );
135 - $this->listNoticeDetail( $notice );
136 - return;
137 - }
138 -
139 - $this->listNotices();
140 - }
141 -
142 - private function updateEnabled( $update_notice, $enabled) {
143 - $centralnotice_table = "central_notice_campaign";
144 - $dbw = wfGetDB( DB_MASTER );
145 - $res = $dbw->update($centralnotice_table, array( notice_enabled => $enabled ), array( notice_name => $update_notice));
146 - }
147 -
148 - static public function printHeader() {
149 - global $wgOut;
150 - $wgOut->addWikiText( '[[' . 'Special:CentralNotice/listNotices ' . '|' . wfMsg( 'centralnotice-notices') . ']]' . " | "
151 - . '[[' . 'Special:NoticeTemplate/listTemplates' . '|' . wfMsg ( 'centralnotice-templates' ) . ']]' . " | "
152 - . '[[' . 'Special:NoticeTranslate/listTranslations' . '|' . wfMsg( 'centralnotice-translate') . ']]' . " | ");
153 -
154 - }
155 -
156 - function getNoticesName() {
157 - $centralnotice_table = "central_notice_campaign";
158 - $dbr = wfGetDB( DB_SLAVE );
159 - $res = $dbr->select( $centralnotice_table,"notice_name" );
160 - $notices = array();
161 - while ( $row = $dbr->fetchObject( $res )) {
162 - array_push( $notices, $row->notice_name);
163 - }
164 - return $notices;
165 - }
166 -
167 - ####
168 - # listNotices
169 - ###
170 - # Print out all campaigns found in db
171 - ###
172 -
173 - function listNotices() {
174 - global $wgOut,$wgRequest,$wgTitle,$wgScript,$wgNoticeLang;
175 -
176 - $centralnotice_table = "central_notice_campaign";
177 - $dbr = wfGetDB( DB_SLAVE );
178 - $this->showAll = 'Y'; //temp
179 - if ( isset( $this->showAll )) {
180 - $res = $dbr->select( $centralnotice_table,
181 - "notice_name, notice_start_date, notice_end_date, notice_enabled, notice_project, notice_language, notice_locked",
182 - '',
183 - '',
184 - array('ORDER BY' => 'id'),
185 - ''
186 - );
187 - }
188 - else { //show only notices for this language
189 - $res = $dbr->select( $centralnotice_table,
190 - "notice_name, notice_start_date, notice_end_date, notice_enabled, notice_project, notice_locked",
191 - array ( "notice_language = '$wgNoticeLang'"),
192 - '',
193 - array('ORDER BY' => 'id'),
194 - ''
195 - );
196 - }
197 - $table .= "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
198 - $table .= "<fieldset><legend>" . wfMsgHtml( "centralnotice-manage" ) . "</legend>";
199 - $table .= "<table cellpadding=\"9\">";
200 - $table .= "<tr><th colspan = \"9\"></th></tr>";
201 - $table .= "<th>" . wfMsg ( 'centralnotice-notice-name') . "</th>";
202 - $table .= "<th>" . wfMsg ( 'centralnotice-project-name') . "</th>";
203 - if ( isset ( $this->showAll ) )
204 - $table .= "<th>" . wfMsg ( 'centralnotice-project-lang') . "</th>";
205 - $table .= "<th>" . wfMsg ( 'centralnotice-start-date') . "</th>";
206 - $table .= "<th>" . wfMsg ( 'centralnotice-end-date') . "</th>";
207 - $table .= "<th>" . wfMsg ( 'centralnotice-enabled') . "</th>";
208 - $table .= "<th>" . wfMsg ( 'centralnotice-locked') . "</th>";
209 - $table .= "<th>" . wfMsg ( 'centralnotice-remove') . "</th>";
210 - while ( $row = $dbr->fetchObject( $res )) {
211 - $table .= "<tr><td><a href=\"" . $this->getTitle()->getLocalUrl("method=listNoticeDetail&notice=$row->notice_name") . "\">$row->notice_name</a></td>";
212 - $table .= "<td>$row->notice_project</td>";
213 - if ( isset ( $this->showAll ))
214 - $table .= "<td>" . $row->notice_language . "</td>";
215 -
216 - $start_timestamp = $row->notice_start_date;
217 - $start_year = substr( $start_timestamp, 0 , 4);
218 - $start_month = substr( $start_timestamp, 4, 2);
219 - $start_day = substr( $start_timestamp, 6, 2);
220 - $start_hour = substr( $start_timestamp, 8, 2) . ":00";
221 -
222 - $end_timestamp = $row->notice_end_date;
223 - $end_year = substr( $end_timestamp, 0 , 4);
224 - $end_month = substr( $end_timestamp, 4, 2);
225 - $end_day = substr( $end_timestamp, 6, 2);
226 -
227 -
228 -
229 - $table .= "<td>" . Xml::listDropDown( "start_date[$row->notice_name][year]", wfMsg( 'centralnotice-years'), '', $start_year, '', 3)
230 - . Xml::listDropDown( "start_date[$row->notice_name][month]", wfMsg( 'centralnotice-months'), '', $start_month, '', 4 )
231 - . Xml::listDropDown( "start_date[$row->notice_name][day]", wfMsg( 'centralnotice-days'), '', $start_day, '', 5)
232 - . Xml::listDropDown( "start_date[$row->notice_name][hour]", wfMsg( 'centralnotice-hours'), '', $start_hour, '', 6)
233 - . "</td>";
234 - $table .= "<td>" . Xml::listDropDown( "end_date[$row->notice_name][year]", wfMsg( 'centralnotice-years'), '', $end_year, '', 7)
235 - . Xml::listDropDown( "end_date[$row->notice_name][month]", wfMsg( 'centralnotice-months'), '', $end_month, '', 8 )
236 - . Xml::listDropDown( "end_date[$row->notice_name][day]", wfMsg( 'centralnotice-days'), '', $end_day, '9')
237 - . "</td>";
238 - $enabled = ( $row->notice_enabled == 'Y' ) ? true : false;
239 - $table .= "<td>" . Xml::check( 'enabled[]', $enabled, array ( 'value' => $row->notice_name)) . "</td>";
240 - // lock down to certain users
241 - $locked = ( $row->notice_locked == 'Y' ) ? true : false;
242 - $table .= "<td>" . Xml::check( 'locked[]', $locked, array ( 'value' => $row->notice_name)) . "</td>";
243 - $table .= "<td>" . Xml::check( 'removeNotices[]', false, array( 'value' => $row->notice_name)) . "</td>";
244 - }
245 - $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify'),
246 - array('id' => 'centralnoticesubmit','name' => 'centralnoticesubmit') ) . "</td></tr>";
247 - $table .= "</table></fieldset></form>";
248 - $wgOut->addHTML( $table);
249 -
250 - $current_day = date( 'd' );
251 - $current_month = date( 'm');
252 - $current_year = date( 'o' );
253 - $action = "addNotice";
254 -
255 - global $wgNoticeProject,$wgNoticeLang;
256 -
257 - list( $sLabel, $lsSelect) = Xml::languageSelector( $wpUserLang );
258 - $form .= $this->tableRow( $lsLabel, $lsSelect) ;
259 -
260 - $wgOut->addHtml(
261 - Xml::openElement( 'form', array(
262 - 'method' => 'post',
263 - 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl())) .
264 - '<fieldset>' .
265 - Xml::element( 'legend', array(), wfMsg( 'centralnotice-add-notice' ) ) .
266 - Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
267 - Xml::hidden( 'method', $action ) .
268 - '<p>' .
269 - Xml::inputLabel( wfMsg( 'centralnotice-notice-name' ),
270 - 'noticeName', 'noticeName', 25, $this->mNoticeName) .
271 - " " . Xml::label( wfMsg('centralnotice-start-date'), 'start-date') . ": " .
272 - Xml::listDropDown( 'start_month', wfMsg( 'centralnotice-months'), '', $current_month, '', 6 ) .
273 - Xml::listDropDown( 'start_day', wfMsg( 'centralnotice-days'), '', $current_day, '', 7 ) .
274 - Xml::listDropDown( 'start_year', wfMsg( 'centralnotice-years'), '', $current_year, '', 8) .
275 - " " . wfMsg( 'centralnotice-start-hour' ) . ": " .
276 - Xml::listDropDown( 'start_hour', wfMsg( 'centralnotice-hours'), '', "00:00", '', 9) . "<p>" .
277 - " " . wfMsg( 'centralnotice-project-name' ) . ": " .
278 - Xml::listDropDown( 'project_name', wfMsg( 'centralnotice-project-name-list'), '', $wgNoticeProject, '', 10) .
279 - " " . wfMsg( 'centralnotice-project-lang') . ":" . $this->tableRow( $lsLabel, $lsSelect) .
280 - '</p>' .
281 - '<p>' .
282 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) .
283 - '</p>' .
284 - '</fieldset>' .
285 - '</form>'
286 - );
287 - }
288 -
289 - function tableRow( $td1, $td2 ) {
290 - $td3 = '';
291 - $td1 = Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
292 - $td2 = Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
293 - return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
294 - }
295 -
296 - function listNoticeDetail( $notice ) {
297 - global $wgOut,$wgRequest;
298 -
299 - $eNotice = htmlspecialchars( $notice );
300 -
301 - if ($wgRequest->wasPosted()) {
302 - $templateToRemove = $wgRequest->getArray('removeTemplates');
303 - if (isset( $templateToRemove )) {
304 - foreach ($templateToRemove as $template) {
305 - $this->removeTemplateFor( $eNotice, $template);
306 - }
307 - }
308 - $weights = $wgRequest->getArray('weights');
309 - if (isset( $weights )) {
310 - }
311 - $templatesToAdd = $wgRequest->getArray('addTemplates');
312 - if (isset( $templatesToAdd )) {
313 - foreach ($templatesToAdd as $template) {
314 - $this->addTemplateTo( $notice, $template, 0);
315 - }
316 - }
317 -
318 - }
319 -
320 - $centralnotice_table = "central_notice_campaign";
321 - $dbr = wfGetDB( DB_SLAVE );
322 - $res = $dbr->select( array ( $centralnotice_table,"central_notice_template_assignments"),
323 - "name,weight",
324 - array ( 'notice_name' => $eNotice, 'campaign_id = id'),
325 - '',
326 - array('ORDER BY' => 'id'),
327 - ''
328 - );
329 - if ( $dbr->numRows( $res ) < 1) {
330 - $wgOut->addHtml( wfMsg ("centralnotice-no-templates"));
331 - $wgOut->addHtml( $this->addTemplatesForm());
332 - return;
333 - }
334 - $table .= "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
335 - $table .= '<fieldset><legend>' . $eNotice . "</legend>";
336 - $table .= "<table cellpadding=\"9\">";
337 - $table .= "<tr><th colspan = \"3\"></th></tr>";
338 - $table .= "<th>" . wfMsg ( "centralnotice-templates" ) . "</th>";
339 - $table .= "<th>" . wfMsg ( "centralnotice-weight" ) . "</th>";
340 - $table .= "<th>" . wfMsg ( "centralnotice-remove" ) . "</th></tr>";
341 - while ( $row = $dbr->fetchObject( $res )) {
342 - $table .= "<tr><td>" . Xml::label($row->name, 'name') . "</td>";
343 - $table .= "<td>" . Xml::listDropDown( "weight[$row->name]", wfMsg( 'centralnotice-weights'), '', $row->weight, '', 1) . "</td>";
344 - $table .= "<td>" . Xml::check( 'removeTemplates[]', false, array( 'value' => $row->name)) . "</td></tr>";
345 - }
346 - $table .= "<tr><td>" . Xml::submitButton( wfMsg( 'centralnotice-modify') ) . "</td></tr>";
347 - $table .= "</table></fieldset></form>";
348 - $wgOut->addHTML( $table );
349 - $wgOut->addHTML( $this->addTemplatesForm() );
350 - }
351 -
352 - function addTemplatesForm() {
353 - $centralnotice_table = 'central_notice_templates';
354 - $dbr = wfGetDB( DB_SLAVE );
355 - $res = $dbr->select( $centralnotice_table, name, '', '', array('ORDER BY' => 'id'));
356 - $table = "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
357 - $table .= '<fieldset><legend>' . wfMsg( "centralnotice-available-templates") . '</legend>';
358 - $table .= "<table cellpadding=\"9\">";
359 - $table .= "<tr><th colspan = \"2\"></th></tr>";
360 - $table .= "<th>" . wfMsg ( 'centralnotice-template-name') . "</th>";
361 - $table .= "<th>" . wfMsg ( 'centralnotice-add' ) . "</th>";
362 - while ( $row = $dbr->fetchObject( $res )) {
363 - $table .= "<tr><td>" . $row->name . "</td>";
364 - $table .= "<td>" . Xml::check( 'addTemplates[]', '', array ( 'value' => $row->name)) . "</td></tr>";
365 - }
366 - $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify')) . "</td></tr>";
367 - $table .= "</table></fieldset></form>";
368 - return $table;
369 - }
370 -
371 -public function getTemplatesForNotice ( $noticeName ) {
372 - $dbr = wfGetDB( DB_SLAVE );
373 - $centralnotice_table = 'central_notice_template_assignments';
374 -
375 - $eNoticeName = mysql_real_escape_string( $noticeName ) ;
376 - $res = $dbr->select( array ( $centralnotice_table, "central_notice_campaign" ),
377 - "name,weight",
378 - array ( 'notice_name' => $eNoticeName, 'campaign_id = id'),
379 - '',
380 - array('ORDER BY' => 'id'),
381 - ''
382 - );
383 - $templates = array();
384 - while ( $row = $dbr->fetchObject( $res )) {
385 - $tempaltes[$row->name] = $row->weight;
386 - }
387 - return $templates;
388 -
389 - }
390 -
391 - function addNotice( $noticeName, $enabled, $start_year, $start_month, $start_day, $project_name, $project_language ) {
392 - global $wgOut;
393 - $dbr = wfGetDB( DB_SLAVE );
394 - $centralnotice_table = 'central_notice_campaign';
395 -
396 - $eNoticeName = mysql_real_escape_string( $noticeName ) ;
397 - $res = $dbr->select( $centralnotice_table, 'notice_name', "notice_name = '$eNoticeName' " );
398 - if ( $dbr->numRows( $res ) > 0 ) {
399 - $wgOut->addHTML( wfMsg( 'centralnotice-notice-exists' ) );
400 - return;
401 - }
402 - else {
403 - $dbw = wfGetDB( DB_MASTER );
404 - $start_date = wfTimeStamp( TS_MW, $start_year . $start_month . $start_day . $start_hour . "000000");
405 - $end_date = wfTimeStamp( TS_MW, $start_year . ($start_month + 1) . $start_day . $start_hour . "000000");
406 - $res = $dbw->insert( $centralnotice_table, array( notice_name => "$noticeName", notice_enabled => "$enabled", notice_start_date => "$start_date" , notice_end_date => $end_date, notice_project => $project_name, notice_language => $project_language));
407 - return;
408 - }
409 - }
410 -
411 - function removeNotice ( $noticeName ) {
412 - global $wgOut;
413 - $dbr = wfGetDB( DB_SLAVE );
414 - $centralnotice_table = 'central_notice_campaign';
415 -
416 - $eNoticeName = mysql_real_escape_string( $noticeName ) ;
417 - $res = $dbr->select( $centralnotice_table, 'notice_name', "notice_name = '$eNoticeName' " );
418 - if ( $dbr->numRows( $res ) < 1 ) {
419 - $wgOut->addHTML( wfMsg( 'centralnotice-notice-doesnt-exist' ) );
420 - return;
421 - }
422 - else {
423 - $dbw = wfGetDB( DB_MASTER );
424 - $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
425 - $res = $dbw->delete( "central_notice_template_assignments", array ( campaign_id => $noticeId));
426 - $res = $dbw->delete( $centralnotice_table, array ( notice_name => "$noticeName"));
427 - return;
428 - }
429 - }
430 -
431 - function addTemplateTo( $noticeName, $templateName, $weight) {
432 - global $wgOut;
433 - $centralnotice_table = "central_notice_template_assignments";
434 -
435 - $dbr = wfGetDB( DB_SLAVE );
436 - $eNoticeName = mysql_real_escape_string( $noticeName );
437 - $eTemplateName = mysql_real_escape_string( $templateName );
438 - $eWeight = mysql_real_escape_string ( $weight );
439 -
440 - $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
441 - $res = $dbr->select( $centralnotice_table, 'name', array( name => $eTemplateName, campaign_id => $noticeId));
442 - if ( $dbr->numRows( $res ) > 0) {
443 - $wgOut->addHTML( wfMsg( 'centralnotice-template-already-exists' ) );
444 - }
445 - else {
446 - $dbw = wfGetDB( DB_MASTER );
447 - $noticeId = htmlspecialchars($this->getNoticeId( $eNoticeName ));
448 - $res = $dbw->insert($centralnotice_table, array( name => $eTemplateName, weight => $eWeight, campaign_id => $noticeId));
449 - }
450 - }
451 -
452 - function getNoticeId ( $noticeName ) {
453 - $dbr = wfGetDB( DB_SLAVE );
454 - $centralnotice_table = 'central_notice_campaign';
455 - $eNoticeName = mysql_real_escape_string( $noticeName );
456 - $res = $dbr->select( $centralnotice_table, 'id', "notice_name = '$eNoticeName'");
457 - $row = $dbr->fetchObject( $res );
458 - return $row->id;
459 - }
460 -
461 - function removeTemplateFor( $noticeName, $templateName) {
462 - $centralnotice_table = "central_notice_template_assignments";
463 - $dbw = wfGetDB( DB_MASTER );
464 - $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
465 - $eTemplateName = mysql_real_escape_string( $templateName );
466 - $res = $dbw->delete( $centralnotice_table, array ( name => "$eTemplateName", campaign_id => $noticeId));
467 - }
468 -
469 - function updateNotice ( $noticeName, $startDate, $endDate , $enabled) {
470 - $centralnotice_table = "central_notice_template_assignments";
471 - $dbr = wfGetDB( DB_SLAVE );
472 - $res = $dbr->select( $centralnotice_table, notice_name, "notice_name = '$noticeName'" );
473 - if ($dbr->numRows( $res ) < 1) {
474 - $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist'));
475 - }
476 - else {
477 - $dbw = wfGetDB( DB_MASTER );
478 - $res = $dbw->update( $centralnotice_table, array( notice_start_date => $startDate, notice_end_Date => $endDate, notice_enabled => $enabled), "notice_name = '$noticeName'");
479 - }
480 - }
481 -
482 - function updateStartDate ( $noticeName, $startDate ) {
483 - $centralnotice_table = 'central_notice_campaign';
484 - $dbw = wfGetDB( DB_MASTER );
485 - $res = $dbw->update( $centralnotice_table, array( notice_start_date => $startDate), array( notice_name => $noticeName));
486 - }
487 -
488 -
489 - function updateEndDate ( $noticeName, $endDate ) {
490 - $centralnotice_table = 'central_notice_campaign';
491 - $dbw = wfGetDB( DB_MASTER );
492 - $res = $dbw->update( $centralnotice_table, array( notice_end_date => $endDate), array( notice_name => $noticeName));
493 - }
494 -
495 - function updateLock ( $noticeName, $isLocked ) {
496 - global $wgOut;
497 - $centralnotice_table = 'central_notice_campaign';
498 - $dbr = wfGetDB( DB_SLAVE );
499 - $res = $dbr->select( $centralnotice_table, notice_name, "notice_name = '$noticeName'" );
500 - if ($dbr->numRows( $res ) < 1) {
501 - $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist'));
502 - }
503 - else {
504 - $dbw = wfGetDB( DB_MASTER );
505 - $res = $dbw->update( $centralnotice_table, array( notice_locked => $isLocked ), array( notice_name => $noticeName));
506 - }
507 - }
508 -
509 - function updateWeight ( $noticeName, $templateName, $weight ) {
510 - $centralnotice_table = 'central_notice_template_assignments';
511 - $dbw = wfGetDB( DB_MASTER );
512 - $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
513 - $res = $dbw->update( $centralnotice_table, array ( weight => $weight ), array( name => $templateName, campaign_id => $noticeId));
514 - }
515 -}
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTemplate.php
@@ -55,12 +55,12 @@
5656 }
5757 }
5858
59 - $method = $wgRequest->getVal('method');
60 - $wgOut->addHtml("got method $method");
 59+ $method = $wgRequest->getVal('wpMethod');
6160
6261 if ( $method == 'addTemplate') {
63 - $this->addTemplate();
64 - return;
 62+ $templateName = $wgRequest->getVal('templateName');
 63+ $templateBody = $wgRequest->getVal('templateBody');
 64+ $this->addTemplate( $templateName, $templateBody);
6565 }
6666 if ( $sub == 'listTemplates' ) {
6767 $this->listTemplates();
@@ -76,18 +76,18 @@
7777 $res = $dbw->update($centralnotice_table, array( cnc_enabled => $enabled ), array( cnc_template => $update_notice));
7878 }
7979
80 - private function previewTemplate() {
 80+ public static function previewTemplate() {
8181 }
8282
8383
8484 function queryTemplates() {
8585 $centralnotice_template_table = "central_notice_templates";
8686 $dbr = wfGetDB( DB_SLAVE );
87 - $res = $dbr->select( $centralnotice_template_table, "name");
 87+ $res = $dbr->select( $centralnotice_template_table, "template_name");
8888
8989 $templates = array();
9090 while ( $row = $dbr->fetchObject( $res )) {
91 - array_push($templates, $row->name);
 91+ array_push($templates, $row->template_name);
9292 }
9393 return $templates;
9494 }
@@ -100,30 +100,30 @@
101101 function templatesForm( $templates ) {
102102 global $wgOut, $wgTitle;
103103
104 - $table .= Xml::openElement('table', array ( 'id' => 'templates')) .
 104+ $table .= Xml::fieldset( 'Available Templates' );
 105+ $table .= Xml::openElement( 'table', array ( 'id' => 'templates')) ;
105106 $templates = $this->queryTemplates();
106107 foreach ( $templates as $templateName ) {
107108 $table .= "<tr><td>" . $templateName . "</td></tr>";
108109 }
109110 $table .= Xml::closeElement( 'table' );
 111+ $table .= XML::closeElement( 'fieldset' );
110112
111113 $wgOut->addHtml( $table );
112114
113115 $wgOut->addHtml(
114116 Xml::openElement( 'form', array(
115 - 'method' => 'get',
116 - 'action' => $this->getTitle( $this->mUserName )->getLocalUrl( 'method=addTemplate' ) )) .
 117+ 'method' => 'post',
 118+ 'action' => SpecialPage::getTitleFor( 'NoticeTemplate' )->getFullUrl ) ) .
117119 '<fieldset>' .
118120 Xml::element( 'legend', array(), wfMsg( 'centralnotice-add-template' ) ) .
119 - Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
120 - Xml::hidden( 'wpMethod', $action ) .
 121+ Xml::hidden( 'wpMethod', 'addTemplate' ) .
121122 '<p>' .
122123 Xml::inputLabel( wfMsg( 'centralnotice-template-name' ),
123124 'templateName', 'templateName', 25, $this->mTemplateName) .
124125 '</p>' .
125126 '<p>' .
126 - Xml::inputLabel( wfMsg( 'centralnotice-template-body'),
127 - 'templateBody', 'templateBody', 60, $this->templateBody) .
 127+ Xml::textarea( 'templateBody', '', 60, 20) .
128128 '<p>' .
129129 Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) .
130130 Xml::submitButton( wfMsg( 'centralnotice-preview' ) ) .
@@ -153,21 +153,31 @@
154154 $wgOut->addHTML( $form );
155155 }
156156
157 - function addTemplate ( $template ) {
 157+ function addTemplate ( $templateName, $templateBody ) {
 158+ global $wgOut;
 159+
158160 $dbr = wfGetDB( DB_SLAVE );
159161 $centralnotice_table = 'central_notice_templates';
160162
161 - $eTemplateName = mysql_real_escape_string( $templateName );
 163+ $eTemplateName = htmlspecialchars ( $templateName );
162164
163 - $res = $dbr->select( $centralnotice_table, 'name', "notice_name = '$eTemplateName' " );
 165+ $res = $dbr->select( $centralnotice_table, 'template_name', "template_name = '$eTemplateName' " );
164166 if ( $dbr->numRows( $res ) > 0 ) {
165167 $wgOut->addHTML( wfMsg( 'centralnotice-template-exists' ) );
166168 return;
167169 }
168170 else {
169171 $dbw = wfGetDB( DB_MASTER );
170 - $res = $dbw->insert( $centralnotice_table, array( notice_name => "$noticeName"));
 172+ $res = $dbw->insert( $centralnotice_table, array( template_name => "$templateName"));
 173+
 174+ //perhaps these should move into the db as blob
 175+ $templatePage = "Centralnotice-" . "template-" . "$templateName";
 176+ $title = Title::newFromText( $templatePage, NS_MEDIAWIKI );
 177+ $article = new Article( $title );
 178+ $templateBody = htmlspecialchars ( $templateBody );
 179+ $article->doEdit( $templateBody, '' );
171180 return;
 181+
172182 }
173183 }
174184 }
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeTranslate.php
@@ -19,8 +19,8 @@
2020 $this->setHeaders();
2121 $sk = $wgUser->getSkin();
2222
23 - if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' )) {
24 - $wgOut->permissionRequired( 'centralnotice_admin_rights' );
 23+ if ( !$wgUser->isAllowed( 'centralnotice_translate_rights' )) {
 24+ $wgOut->permissionRequired( 'centralnotice_translate_rights' );
2525 return;
2626 }
2727
@@ -28,8 +28,8 @@
2929 CentralNotice::printHeader();
3030
3131 if ( $wgRequest->wasPosted() ) {
32 - $body = file_get_contents('php://input');
33 - $wgOut->addHtml("Body of post: $body");
 32+ //$body = file_get_contents('php://input');
 33+ //$wgOut->addHtml("Body of post: $body");
3434
3535 $previewNotice = $wgRequest->getVal('preview');
3636 if ( isset( $previewNotice ) ) {
@@ -41,15 +41,14 @@
4242 if (isset ( $update ) ) {
4343 foreach ( $update as $lang => $messages ) {
4444 foreach ( $messages as $text => $translation) {
45 - $this->updateMessage( $text, $translation, $lang, $token );
 45+ if ( $translation ) // if we actually got text
 46+ $this->updateMessage( $text, $translation, $lang, $token );
4647 }
4748 }
4849
4950 }
5051 }
5152
52 - $method = $wgRequest->getVal('method');
53 -
5453 if ( $sub == 'listTranslations' ) { // Show tranlsation text
5554 $this->showTranslateForm();
5655 return;
@@ -58,13 +57,13 @@
5958 $this->showTranslateForm();
6059 }
6160
62 - function showTranslateForm() {
 61+ private function showTranslateForm() {
6362 global $wgOut,$wgUser,$wgRequest,$wgContLanguageCode;
6463
6564 $token = $wgUser->editToken();
6665 $wpUserLang = $wgRequest->getVal('wpUserLanguage') ? $wgRequest->getVal('wpUserLanguage') : $wgContLanguageCode;
6766 $requiredFields = array( 'counter','donate','headlines');
68 - // Two column listing of : text : translation
 67+ // Four column listing of field : text : field/lang : translation
6968 $table = "<form name='centranoticetranslate' id='centralnoticetranslate' method='post'>";
7069 $table .= "<fieldset><legend>" . wfMsgHtml( "centralnotice-translate-heading" ) . "</legend>";
7170 $table .= "<table cellpadding=\"9\">";
@@ -74,10 +73,18 @@
7574 $table .= "<th>field</th>";
7675 $table .= "<th>" . $wpUserLang . "</th></tr>";
7776 foreach( $requiredFields as $field) {
 77+ $message = "Centralnotice-" . "$field" . "/" . $wpUserLang;
 78+ $title = Title::newFromText( $message, NS_MEDIAWIKI );
 79+ $text = $title->exists() ? wfMsgExt( "centralnotice-$field", array ( language => $wpUserLang ) ) : ''; // only load text if a message exists to avoild default english text display
7880 $table .= "<tr><td>". "$field/en" . "</td>";
7981 $table .= "<td>" . wfMsgExt( "centralnotice-$field", array ( language => 'en') ) . "</td>";
80 - $table .= "<td>". "$field/$wpUserLang" . "</td>"; //translations start with english
81 - $table .= "<td>" . Xml::input( "updateText[$wpUserLang][$field]", 80, wfMsgExt( "centralnotice-$field", array ( language => $wpUserLang))) . "</td></tr>";
 82+ if ( $text ) {
 83+ $table .= "<td>". "$field/$wpUserLang" . "</td>";
 84+ }
 85+ else {
 86+ $table .= "<td>" . "<font color=\"red\">" . "$field/$wpUserLang" . "</td>";
 87+ }
 88+ $table .= "<td>" . Xml::input( "updateText[$wpUserLang][$field]", 80, $text) . "</td></tr>";
8289 }
8390 $table .= Xml::hidden( token, $token );
8491 $table .= Xml::hidden( wpUserLanguage, $wpUserLang ); //keep track of set language
@@ -88,7 +95,7 @@
8996
9097 $wgOut->addHTML( $table );
9198
92 - $form = "<form name='centranoticetranslate' id='centralnoticetranslate' action=\"$action\" method='post'>";
 99+ $form = "<form name='translatelang' id='translatelang' method='post'>";
93100 $form .= "<fieldset><legend>" . wfMsgHtml( "centralnotice-change-lang" ) . "</legend>";
94101 list( $sLabel, $lsSelect) = Xml::languageSelector( $wpUserLang );
95102 $form .= $this->tableRow( $lsLabel, $lsSelect) ;
@@ -98,20 +105,21 @@
99106 $wgOut->addHTML( $form ) ;
100107 }
101108
102 - function tableRow( $td1, $td2 ) {
 109+ public function tableRow( $td1, $td2 ) {
103110 $td3 = '';
104111 $td1 = Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
105112 $td2 = Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
106113 return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
107114 }
108 - function updateMessage( $text, $translation, $lang, $token ) {
109 - global $wgUser,$wgOut;
 115+
 116+ private function updateMessage( $text, $translation, $lang, $token ) {
 117+ global $wgUser;
 118+
 119+ $saveTo = "Centralnotice-" . $text . "/$lang";
110120
111 - $saveTo = "Centralnotice-" . $text;
112 - $saveTo .= "/$lang";
113 -
114121 $title = Title::newFromText( $saveTo, NS_MEDIAWIKI );
115122 $article = new Article( $title );
 123+ $translation = htmlspecialchars ( $translation );
116124 $article->doEdit( $translation, '' );
117125 }
118126 }
Index: branches/CentralNotice-SpecialPage-Integration/CentralNotice.php
@@ -70,10 +70,11 @@
7171 $wgExtensionMessagesFiles['CentralNotice'] = dirname(__FILE__) . '/CentralNotice.i18n.php';
7272
7373 $dir = dirname(__FILE__) . '/';
74 -$wgAutoloadClasses['CentralNotice'] = dirname(__FILE__) . '/CentralNotice_body.php';
 74+$wgAutoloadClasses['CentralNotice'] = dirname(__FILE__) . '/SpecialNoticeCentral.php';
7575
7676 $wgAvailableRights[] = 'centralnotice_admin_rights';
7777 $wgGroupPermissions['sysop']['centralnotice_admin_rights'] = true; // Only sysops can make change
 78+$wgGroupPermissions['sysop']['centralnotice_translate_rights'] = true; // Only sysops can make change
7879
7980 $wgSpecialPages['CentralNotice'] = 'CentralNotice';
8081 $wgSpecialPageGroups['CentralNotice'] = 'wiki'; // Wiki data and tools"
@@ -171,13 +172,14 @@
172173
173174 $dbr = wfGetDB( DB_SLAVE );
174175 $timestamp = wfTimestampNow();
175 - $res = $dbr->select( $centralnotice_table, "id", array ( "notice_start_date <= '$timestamp'", "notice_end_date >= '$timestamp'", "notice_enabled = 'Y'", "notice_language = '$wgNoticeLang'", "notice_project = '$wgNoticeProject'"));
 176+ $res = $dbr->select( $centralnotice_table, "notice_id", array ( "notice_start_date <= '$timestamp'", "notice_end_date >= '$timestamp'", "notice_enabled = 'Y'", "notice_language = '$wgNoticeLang'", "notice_project = '$wgNoticeProject'"));
176177 if ( $dbr->numRows( $res > 1 )) {
177178 //notice overlap! not returning anything for safety
 179+ return;
178180 }
179181 else {
180182 $row = $dbr->fetchObject( $res );
181 - return $row->id;
 183+ return $row->notice_id;
182184 }
183185 }
184186
Index: branches/CentralNotice-SpecialPage-Integration/SpecialNoticeCentral.php
@@ -0,0 +1,530 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ) {
 5+ echo "CentralNotice extension\n";
 6+ exit( 1 );
 7+}
 8+
 9+class CentralNotice extends SpecialPage
 10+{
 11+ function CentralNotice() {
 12+ SpecialPage::SpecialPage("CentralNotice");
 13+ wfLoadExtensionMessages('CentralNotice');
 14+ }
 15+
 16+ function execute( $sub ) {
 17+ global $wgOut, $wgUser, $wgRequest;
 18+
 19+ $this->setHeaders();
 20+ $sk = $wgUser->getSkin();
 21+
 22+ if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' )) {
 23+ $wgOut->permissionRequired( 'centralnotice_admin_rights' );
 24+ return;
 25+ }
 26+
 27+ $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ));
 28+ $this->printHeader();
 29+
 30+
 31+ if ( $wgRequest->wasPosted() ) {
 32+ $body = file_get_contents('php://input');
 33+ $wgOut->addHtml("Body of post: $body");
 34+
 35+ $toRemove = $wgRequest->getArray('removeNotices');
 36+ if ( isset($toRemove) ){
 37+ foreach ( $toRemove as $template ) {
 38+ $this->removeNotice( $template );
 39+ }
 40+ $this->listNotices();
 41+ return;
 42+ }
 43+
 44+ $lockedNotices = $wgRequest->getArray('locked');
 45+ if ( isset( $lockedNotices ) ) {
 46+ $allNotices = $this->getNoticesName();
 47+ $diff_set = array_diff( $allNotices, $lockedNotices);
 48+
 49+ foreach( $lockedNotices as $notice ) {
 50+ $this->updateLock( $notice, 'Y' );
 51+ }
 52+
 53+ foreach( $diff_set as $notice ) {
 54+ $this->updateLock( $notice, 'N' );
 55+ }
 56+ }
 57+ $enabledNotices = $wgRequest->getArray('enabled');
 58+ if ( isset( $enabledNotices ) ) {
 59+ $allNotices = $this->getNoticesName();
 60+ $diff_set = array_diff( $allNotices, $enabledNotices);
 61+
 62+ foreach ( $enabledNotices as $notice) {
 63+ $this->updateEnabled( $notice, 'Y');
 64+ }
 65+ foreach ( $diff_set as $notice) {
 66+ $this->updateEnabled( $notice, 'N');
 67+ }
 68+ }
 69+ $start_date = $wgRequest->getArray('start_date');
 70+ if ( isset( $start_date ) ) {
 71+ foreach( $start_date as $noticeName => $date_value ) {
 72+ $updatedStartDate = '';
 73+ foreach ( $date_value as $date_portion => $value) {
 74+ $updatedStartDate .= $value;
 75+ }
 76+ $updatedStartDate .= "000000";
 77+ $this->updateStartDate( $noticeName, $updatedStartDate);
 78+ }
 79+ }
 80+ $end_date = $wgRequest->getArray('end_date');
 81+ if ( isset( $end_date ) ) {
 82+ foreach( $end_date as $noticeName => $date_value ) {
 83+ $updatedEndDate = '';
 84+ foreach ( $date_value as $date_portion => $value) {
 85+ $updatedEndDate .= $value;
 86+ }
 87+ $updatedEndDate .= "000000";
 88+ $this->updateEndDate( $noticeName, $updatedEndDate);
 89+ }
 90+ }
 91+ $noticeName = $wgRequest->getVal('notice');
 92+ $updatedWeights = $wgRequest->getArray('weight');
 93+ if ( isset( $updatedWeights ) ) {
 94+ foreach( $updatedWeights as $templateName => $weight) {
 95+ $this->updateWeight( $noticeName, $templateName, $weight);
 96+ }
 97+ }
 98+ }
 99+
 100+ $method = $wgRequest->getVal('method');
 101+ $this->showAll = $wgRequest->getVal('showAll');
 102+
 103+ if ( $method == 'addNotice' ) {
 104+ $noticeName = $wgRequest->getVal('noticeName');
 105+ $start_day = $wgRequest->getVal('start_day');
 106+ $start_month = $wgRequest->getVal('start_month');
 107+ $start_year = $wgRequest->getVal('start_year');
 108+ $project_name = $wgRequest->getVal('project_name');
 109+ $project_language = $wgRequest->getVal('wpUserLanguage');
 110+ if ( $noticeName == '') {
 111+ $wgOut->addHtml("Can't add a null string");
 112+ }
 113+ else {
 114+ $this->addNotice( $noticeName, 'N', $start_year, $start_month, $start_day, $project_name, $project_language );
 115+ }
 116+ }
 117+ if ( $method == 'removeNotice' ) {
 118+ $noticeName = $wgRequest->getVal ('noticeName');
 119+ $this->removeNotice ( $noticeName );
 120+ }
 121+ if ( $method == 'addTemplateTo') {
 122+ $noticeName = $wgRequest->getVal('noticeName');
 123+ $templateName = $wgRequest->getVal('templateName');
 124+ $this->addTemplateTo($noticeName, $templateName, 0);
 125+ $this->listNoticeDetail( $noticeName );
 126+ return;
 127+ }
 128+ if ( $method == 'removeTemplateFor') {
 129+ $noticeName = $wgRequest->getVal ( 'noticeName');
 130+ $templateName = $wgRequest->getVal ( 'templateName ');
 131+ $this->removeTemplateFor( $noticeName , $templateName );
 132+ }
 133+ if ( $method == 'listNoticeDetail') {
 134+ $notice = $wgRequest->getVal ( 'notice' );
 135+ $this->listNoticeDetail( $notice );
 136+ return;
 137+ }
 138+
 139+ $this->listNotices();
 140+ }
 141+
 142+ private function updateEnabled( $update_notice, $enabled) {
 143+ $centralnotice_table = "central_notice_campaign";
 144+ $dbw = wfGetDB( DB_MASTER );
 145+ $res = $dbw->update($centralnotice_table, array( notice_enabled => $enabled ), array( notice_name => $update_notice));
 146+ }
 147+
 148+ static public function printHeader() {
 149+ global $wgOut;
 150+ $wgOut->addWikiText( '[[' . 'Special:CentralNotice/listNotices ' . '|' . wfMsg( 'centralnotice-notices') . ']]' . " | "
 151+ . '[[' . 'Special:NoticeTemplate/listTemplates' . '|' . wfMsg ( 'centralnotice-templates' ) . ']]' . " | "
 152+ . '[[' . 'Special:NoticeTranslate/listTranslations' . '|' . wfMsg( 'centralnotice-translate') . ']]' . " | ");
 153+
 154+ }
 155+
 156+ function getNoticesName() {
 157+ $centralnotice_table = "central_notice_campaign";
 158+ $dbr = wfGetDB( DB_SLAVE );
 159+ $res = $dbr->select( $centralnotice_table,"notice_name" );
 160+ $notices = array();
 161+ while ( $row = $dbr->fetchObject( $res )) {
 162+ array_push( $notices, $row->notice_name);
 163+ }
 164+ return $notices;
 165+ }
 166+
 167+ ####
 168+ # listNotices
 169+ ###
 170+ # Print out all campaigns found in db
 171+ ###
 172+
 173+ function listNotices() {
 174+ global $wgOut,$wgRequest,$wgTitle,$wgScript,$wgNoticeLang;
 175+
 176+ $centralnotice_table = "central_notice_campaign";
 177+ $dbr = wfGetDB( DB_SLAVE );
 178+ $this->showAll = 'Y'; //temp
 179+ if ( isset( $this->showAll )) {
 180+ $res = $dbr->select( $centralnotice_table,
 181+ "notice_name, notice_start_date, notice_end_date, notice_enabled, notice_project, notice_language, notice_locked",
 182+ '',
 183+ '',
 184+ array('ORDER BY' => 'notice_id'),
 185+ ''
 186+ );
 187+ }
 188+ else { //show only notices for this language
 189+ $res = $dbr->select( $centralnotice_table,
 190+ "notice_name, notice_start_date, notice_end_date, notice_enabled, notice_project, notice_locked",
 191+ array ( "notice_language = '$wgNoticeLang'"),
 192+ '',
 193+ array('ORDER BY' => 'notice_id'),
 194+ ''
 195+ );
 196+ }
 197+ $table .= "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
 198+ $table .= "<fieldset><legend>" . wfMsgHtml( "centralnotice-manage" ) . "</legend>";
 199+ $table .= "<table cellpadding=\"9\">";
 200+ $table .= "<tr><th colspan = \"9\"></th></tr>";
 201+ $table .= "<th>" . wfMsg ( 'centralnotice-notice-name') . "</th>";
 202+ $table .= "<th>" . wfMsg ( 'centralnotice-project-name') . "</th>";
 203+ if ( isset ( $this->showAll ) )
 204+ $table .= "<th>" . wfMsg ( 'centralnotice-project-lang') . "</th>";
 205+ $table .= "<th>" . wfMsg ( 'centralnotice-start-date') . "</th>";
 206+ $table .= "<th>" . wfMsg ( 'centralnotice-end-date') . "</th>";
 207+ $table .= "<th>" . wfMsg ( 'centralnotice-enabled') . "</th>";
 208+ $table .= "<th>" . wfMsg ( 'centralnotice-locked') . "</th>";
 209+ $table .= "<th>" . wfMsg ( 'centralnotice-remove') . "</th>";
 210+ while ( $row = $dbr->fetchObject( $res )) {
 211+ $table .= "<tr><td><a href=\"" . $this->getTitle()->getLocalUrl("method=listNoticeDetail&notice=$row->notice_name") . "\">$row->notice_name</a></td>";
 212+ $table .= "<td>$row->notice_project</td>";
 213+ if ( isset ( $this->showAll ))
 214+ $table .= "<td>" . $row->notice_language . "</td>";
 215+
 216+ $start_timestamp = $row->notice_start_date;
 217+ $start_year = substr( $start_timestamp, 0 , 4);
 218+ $start_month = substr( $start_timestamp, 4, 2);
 219+ $start_day = substr( $start_timestamp, 6, 2);
 220+ $start_hour = substr( $start_timestamp, 8, 2) . ":00";
 221+
 222+ $end_timestamp = $row->notice_end_date;
 223+ $end_year = substr( $end_timestamp, 0 , 4);
 224+ $end_month = substr( $end_timestamp, 4, 2);
 225+ $end_day = substr( $end_timestamp, 6, 2);
 226+
 227+
 228+
 229+ $table .= "<td>" . Xml::listDropDown( "start_date[$row->notice_name][year]", wfMsg( 'centralnotice-years'), '', $start_year, '', 3)
 230+ . Xml::listDropDown( "start_date[$row->notice_name][month]", wfMsg( 'centralnotice-months'), '', $start_month, '', 4 )
 231+ . Xml::listDropDown( "start_date[$row->notice_name][day]", wfMsg( 'centralnotice-days'), '', $start_day, '', 5)
 232+ . Xml::listDropDown( "start_date[$row->notice_name][hour]", wfMsg( 'centralnotice-hours'), '', $start_hour, '', 6)
 233+ . "</td>";
 234+ $table .= "<td>" . Xml::listDropDown( "end_date[$row->notice_name][year]", wfMsg( 'centralnotice-years'), '', $end_year, '', 7)
 235+ . Xml::listDropDown( "end_date[$row->notice_name][month]", wfMsg( 'centralnotice-months'), '', $end_month, '', 8 )
 236+ . Xml::listDropDown( "end_date[$row->notice_name][day]", wfMsg( 'centralnotice-days'), '', $end_day, '9')
 237+ . "</td>";
 238+ $enabled = ( $row->notice_enabled == 'Y' ) ? true : false;
 239+ $table .= "<td>" . Xml::check( 'enabled[]', $enabled, array ( 'value' => $row->notice_name)) . "</td>";
 240+ // lock down to certain users
 241+ $locked = ( $row->notice_locked == 'Y' ) ? true : false;
 242+ $table .= "<td>" . Xml::check( 'locked[]', $locked, array ( 'value' => $row->notice_name)) . "</td>";
 243+ $table .= "<td>" . Xml::check( 'removeNotices[]', false, array( 'value' => $row->notice_name)) . "</td>";
 244+ }
 245+ $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify'),
 246+ array('id' => 'centralnoticesubmit','name' => 'centralnoticesubmit') ) . "</td></tr>";
 247+ $table .= "</table></fieldset></form>";
 248+ $wgOut->addHTML( $table);
 249+
 250+ $current_day = date( 'd' );
 251+ $current_month = date( 'm');
 252+ $current_year = date( 'o' );
 253+ $action = "addNotice";
 254+
 255+ global $wgNoticeProject,$wgNoticeLang;
 256+
 257+ list( $sLabel, $lsSelect) = Xml::languageSelector( $wpUserLang );
 258+ $languagebar .= $this->tableRow( $lsLabel, $lsSelect) ;
 259+
 260+ $wgOut->addHtml(
 261+ Xml::openElement( 'form', array(
 262+ 'method' => 'post',
 263+ 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl())) .
 264+ '<fieldset>' .
 265+ Xml::element( 'legend', array(), wfMsg( 'centralnotice-add-notice' ) ) .
 266+ Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
 267+ Xml::hidden( 'method', $action ) .
 268+ '<p>' .
 269+ Xml::inputLabel( wfMsg( 'centralnotice-notice-name' ),
 270+ 'noticeName', 'noticeName', 25, $this->mNoticeName) .
 271+ " " . Xml::label( wfMsg('centralnotice-start-date'), 'start-date') . ": " .
 272+ Xml::listDropDown( 'start_month', wfMsg( 'centralnotice-months'), '', $current_month, '', 6 ) .
 273+ Xml::listDropDown( 'start_day', wfMsg( 'centralnotice-days'), '', $current_day, '', 7 ) .
 274+ Xml::listDropDown( 'start_year', wfMsg( 'centralnotice-years'), '', $current_year, '', 8) .
 275+ " " . wfMsg( 'centralnotice-start-hour' ) . ": " .
 276+ Xml::listDropDown( 'start_hour', wfMsg( 'centralnotice-hours'), '', "00:00", '', 9) . "<p>" .
 277+ " " . wfMsg( 'centralnotice-project-name' ) . ": " .
 278+ Xml::listDropDown( 'project_name', wfMsg( 'centralnotice-project-name-list'), '', $wgNoticeProject, '', 10) .
 279+ " " . wfMsg( 'centralnotice-project-lang') . ":" . $languagebar .
 280+ '</p>' .
 281+ '<p>' .
 282+ Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) .
 283+ '</p>' .
 284+ '</fieldset>' .
 285+ '</form>'
 286+ );
 287+ }
 288+
 289+ function tableRow( $td1, $td2 ) {
 290+ $td3 = '';
 291+ $td1 = Xml::tags( 'td', array( 'class' => 'pref-label' ), $td1 );
 292+ $td2 = Xml::tags( 'td', array( 'class' => 'pref-input' ), $td2 );
 293+ return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
 294+ }
 295+
 296+ function listNoticeDetail( $notice ) {
 297+ global $wgOut,$wgRequest;
 298+
 299+ $eNotice = htmlspecialchars( $notice );
 300+
 301+ if ($wgRequest->wasPosted()) {
 302+ $templateToRemove = $wgRequest->getArray('removeTemplates');
 303+ if (isset( $templateToRemove )) {
 304+ foreach ($templateToRemove as $template) {
 305+ $this->removeTemplateFor( $eNotice, $template);
 306+ }
 307+ }
 308+ $weights = $wgRequest->getArray('weights');
 309+ if (isset( $weights )) {
 310+ }
 311+ $templatesToAdd = $wgRequest->getArray('addTemplates');
 312+ if (isset( $templatesToAdd )) {
 313+ foreach ($templatesToAdd as $template) {
 314+ $this->addTemplateTo( $notice, $template, 0);
 315+ }
 316+ }
 317+
 318+ }
 319+
 320+ $centralnotice_table = "central_notice_campaign";
 321+ $dbr = wfGetDB( DB_SLAVE );
 322+ $res = $dbr->select( array ( $centralnotice_table,"central_notice_template_assignments","central_notice_templates"),
 323+ "template_name,template_weight",
 324+ array ( 'notice_name' => $eNotice, 'campaign_id = notice_id', 'central_notice_template_assignments.template_id = central_notice_templates.template_id'),
 325+ '',
 326+ array('ORDER BY' => 'notice_id'),
 327+ ''
 328+ );
 329+ if ( $dbr->numRows( $res ) < 1) {
 330+ $wgOut->addHtml( wfMsg ("centralnotice-no-templates"));
 331+ $wgOut->addHtml( $this->addTemplatesForm());
 332+ return;
 333+ }
 334+ $table .= "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
 335+ $table .= '<fieldset><legend>' . $eNotice . "</legend>";
 336+ $table .= "<table cellpadding=\"9\">";
 337+ $table .= "<tr><th colspan = \"3\"></th></tr>";
 338+ $table .= "<th>" . wfMsg ( "centralnotice-templates" ) . "</th>";
 339+ $table .= "<th>" . wfMsg ( "centralnotice-weight" ) . "</th>";
 340+ $table .= "<th>" . wfMsg ( "centralnotice-remove" ) . "</th></tr>";
 341+ while ( $row = $dbr->fetchObject( $res )) {
 342+ $table .= "<tr><td>" . Xml::label($row->template_name, 'name') . "</td>";
 343+ $table .= "<td>" . Xml::listDropDown( "weight[$row->template_name]", wfMsg( 'centralnotice-weights'), '', $row->template_weight, '', 1) . "</td>";
 344+ $table .= "<td>" . Xml::check( 'removeTemplates[]', false, array( 'value' => $row->template_name)) . "</td></tr>";
 345+ }
 346+ $table .= "<tr><td>" . Xml::submitButton( wfMsg( 'centralnotice-modify') ) . "</td></tr>";
 347+ $table .= "</table></fieldset></form>";
 348+ $wgOut->addHTML( $table );
 349+ $wgOut->addHTML( $this->addTemplatesForm() );
 350+ }
 351+
 352+ function addTemplatesForm() {
 353+ $centralnotice_table = 'central_notice_templates';
 354+ $dbr = wfGetDB( DB_SLAVE );
 355+ $res = $dbr->select( $centralnotice_table,
 356+ "template_name",
 357+ '',
 358+ '',
 359+ array('ORDER BY' => 'template_id'));
 360+ $table = "<form name='centranoticeform' id='centralnoticeform' action=\"$action\" method='post'>";
 361+ $table .= '<fieldset><legend>' . wfMsg( "centralnotice-available-templates") . '</legend>';
 362+ $table .= "<table cellpadding=\"9\">";
 363+ $table .= "<tr><th colspan = \"2\"></th></tr>";
 364+ $table .= "<th>" . wfMsg ( 'centralnotice-template-name') . "</th>";
 365+ $table .= "<th>" . wfMsg ( 'centralnotice-add' ) . "</th>";
 366+ while ( $row = $dbr->fetchObject( $res )) {
 367+ $table .= "<tr><td>" . $row->template_name . "</td>";
 368+ $table .= "<td>" . Xml::check( 'addTemplates[]', '', array ( 'value' => $row->template_name)) . "</td></tr>";
 369+ }
 370+ $table .= "<tr><td>" . Xml::submitButton( wfMsgHtml('centralnotice-modify')) . "</td></tr>";
 371+ $table .= "</table></fieldset></form>";
 372+ return $table;
 373+ }
 374+
 375+ public function getTemplatesForNotice ( $noticeName ) {
 376+ $dbr = wfGetDB( DB_SLAVE );
 377+ $centralnotice_table = 'central_notice_template_assignments';
 378+
 379+ $eNoticeName = mysql_real_escape_string( $noticeName ) ;
 380+ $res = $dbr->select( array ( $centralnotice_table, "central_notice_campaign","central_notice_templates"),
 381+ "template_name,template_weight",
 382+ array ( 'notice_name' => $eNoticeName, 'campaign_id = notice_id'),
 383+ '',
 384+ array('ORDER BY' => 'notice_id'),
 385+ ''
 386+ );
 387+ $templates = array();
 388+ while ( $row = $dbr->fetchObject( $res )) {
 389+ $templates[$row->name] = $row->weight;
 390+ }
 391+ return $templates;
 392+
 393+ }
 394+
 395+ function addNotice( $noticeName, $enabled, $start_year, $start_month, $start_day, $project_name, $project_language ) {
 396+ global $wgOut;
 397+ $dbr = wfGetDB( DB_SLAVE );
 398+ $centralnotice_table = 'central_notice_campaign';
 399+
 400+ $eNoticeName = mysql_real_escape_string( $noticeName ) ;
 401+ $res = $dbr->select( $centralnotice_table, 'notice_name', "notice_name = '$eNoticeName' " );
 402+ if ( $dbr->numRows( $res ) > 0 ) {
 403+ $wgOut->addHTML( wfMsg( 'centralnotice-notice-exists' ) );
 404+ return;
 405+ }
 406+ else {
 407+ $dbw = wfGetDB( DB_MASTER );
 408+ $start_date = wfTimeStamp( TS_MW, $start_year . $start_month . $start_day . $start_hour . "000000");
 409+ $end_date = wfTimeStamp( TS_MW, $start_year . ($start_month + 1) . $start_day . $start_hour . "000000");
 410+ $res = $dbw->insert( $centralnotice_table, array( notice_name => "$noticeName", notice_enabled => "$enabled", notice_start_date => "$start_date" , notice_end_date => $end_date, notice_project => $project_name, notice_language => $project_language));
 411+ return;
 412+ }
 413+ }
 414+
 415+ function removeNotice ( $noticeName ) {
 416+ global $wgOut;
 417+ $dbr = wfGetDB( DB_SLAVE );
 418+ $centralnotice_table = 'central_notice_campaign';
 419+
 420+ $eNoticeName = mysql_real_escape_string( $noticeName ) ;
 421+ $res = $dbr->select( $centralnotice_table, 'notice_name', "notice_name = '$eNoticeName' " );
 422+ if ( $dbr->numRows( $res ) < 1 ) {
 423+ $wgOut->addHTML( wfMsg( 'centralnotice-notice-doesnt-exist' ) );
 424+ return;
 425+ }
 426+ else {
 427+ $dbw = wfGetDB( DB_MASTER );
 428+ $noticeId = htmlspecialchars($this->getNoticeId( $noticeName ));
 429+ $res = $dbw->delete( "central_notice_template_assignments", array ( campaign_id => $noticeId));
 430+ $res = $dbw->delete( $centralnotice_table, array ( notice_name => "$noticeName"));
 431+ return;
 432+ }
 433+ }
 434+
 435+ function addTemplateTo( $noticeName, $templateName, $weight) {
 436+ global $wgOut;
 437+ $centralnotice_table = "central_notice_template_assignments";
 438+
 439+ $dbr = wfGetDB( DB_SLAVE );
 440+ $eNoticeName = mysql_real_escape_string( $noticeName );
 441+ $eTemplateName = mysql_real_escape_string( $templateName );
 442+ $eWeight = mysql_real_escape_string ( $weight );
 443+
 444+ $noticeId = $this->getNoticeId( $noticeName );
 445+ $templateId = $this->getTemplateId( $templateName );
 446+ $res = $dbr->select( $centralnotice_table, 'template_assignment_id', array( template_id => $templateId, campaign_id => $noticeId));
 447+ if ( $dbr->numRows( $res ) > 0) {
 448+ $wgOut->addHTML( wfMsg( 'centralnotice-template-already-exists' ) );
 449+ }
 450+ else {
 451+ $dbw = wfGetDB( DB_MASTER );
 452+ $noticeId = $this->getNoticeId( $eNoticeName );
 453+ $res = $dbw->insert($centralnotice_table, array( template_id => $templateId, template_weight => $eWeight, campaign_id => $noticeId));
 454+ }
 455+ }
 456+
 457+ function getNoticeId ( $noticeName ) {
 458+ $dbr = wfGetDB( DB_SLAVE );
 459+ $centralnotice_table = 'central_notice_campaign';
 460+ $eNoticeName = htmlspecialchars( $noticeName );
 461+ $res = $dbr->select( $centralnotice_table, 'notice_id', "notice_name = '$eNoticeName'");
 462+ $row = $dbr->fetchObject( $res );
 463+ return $row->notice_id;
 464+ }
 465+
 466+ function getTemplateId ( $templateName ) {
 467+ $dbr = wfGetDB( DB_SLAVE );
 468+ $centralnotice_table = 'central_notice_templates';
 469+ $templateName = htmlspecialchars ( $templateName );
 470+ $res = $dbr->select( $centralnotice_table, 'template_id', "template_name = '$templateName'");
 471+ $row = $dbr->fetchObject( $res );
 472+ return $row->template_id;
 473+ }
 474+
 475+ function removeTemplateFor( $noticeName, $templateName) {
 476+ global $wgOut;
 477+ $centralnotice_table = "central_notice_template_assignments";
 478+ $dbw = wfGetDB( DB_MASTER );
 479+ $noticeId = $this->getNoticeId( $noticeName );
 480+ $templateId = $this->getTemplateId( $templateName );
 481+ $res = $dbw->delete( $centralnotice_table, array ( template_id => "$templateId", campaign_id => $noticeId));
 482+ }
 483+
 484+ function updateNotice ( $noticeName, $startDate, $endDate , $enabled) {
 485+ $centralnotice_table = "central_notice_template_assignments";
 486+ $dbr = wfGetDB( DB_SLAVE );
 487+ $res = $dbr->select( $centralnotice_table, notice_name, "notice_name = '$noticeName'" );
 488+ if ($dbr->numRows( $res ) < 1) {
 489+ $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist'));
 490+ }
 491+ else {
 492+ $dbw = wfGetDB( DB_MASTER );
 493+ $res = $dbw->update( $centralnotice_table, array( notice_start_date => $startDate, notice_end_Date => $endDate, notice_enabled => $enabled), "notice_name = '$noticeName'");
 494+ }
 495+ }
 496+
 497+ function updateStartDate ( $noticeName, $startDate ) {
 498+ $centralnotice_table = 'central_notice_campaign';
 499+ $dbw = wfGetDB( DB_MASTER );
 500+ $res = $dbw->update( $centralnotice_table, array( notice_start_date => $startDate), array( notice_name => $noticeName));
 501+ }
 502+
 503+
 504+ function updateEndDate ( $noticeName, $endDate ) {
 505+ $centralnotice_table = 'central_notice_campaign';
 506+ $dbw = wfGetDB( DB_MASTER );
 507+ $res = $dbw->update( $centralnotice_table, array( notice_end_date => $endDate), array( notice_name => $noticeName));
 508+ }
 509+
 510+ function updateLock ( $noticeName, $isLocked ) {
 511+ global $wgOut;
 512+ $centralnotice_table = 'central_notice_campaign';
 513+ $dbr = wfGetDB( DB_SLAVE );
 514+ $res = $dbr->select( $centralnotice_table, notice_name, "notice_name = '$noticeName'" );
 515+ if ($dbr->numRows( $res ) < 1) {
 516+ $wgOut->addHTML( wfMsg( 'centralnotice-doesnt-exist'));
 517+ }
 518+ else {
 519+ $dbw = wfGetDB( DB_MASTER );
 520+ $res = $dbw->update( $centralnotice_table, array( notice_locked => $isLocked ), array( notice_name => $noticeName));
 521+ }
 522+ }
 523+
 524+ function updateWeight ( $noticeName, $templateName, $weight ) {
 525+ $centralnotice_table = 'central_notice_template_assignments';
 526+ $dbw = wfGetDB( DB_MASTER );
 527+ $noticeId = $this->getNoticeId( $noticeName );
 528+ $templateId = $this->getTemplateId( $templateName );
 529+ $res = $dbw->update( $centralnotice_table, array ( template_weight => $weight ), array( template_id => $templateId, campaign_id => $noticeId));
 530+ }
 531+}

Status & tagging log