Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php |
— | — | @@ -27,10 +27,7 @@ |
28 | 28 | $sk = $wgUser->getSkin(); |
29 | 29 | |
30 | 30 | // Check permissions |
31 | | - if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' ) ) { |
32 | | - $wgOut->permissionRequired( 'centralnotice_admin_rights' ); |
33 | | - return; |
34 | | - } |
| 31 | + $this->editable = $wgUser->isAllowed( 'centralnotice_admin_rights' ); |
35 | 32 | |
36 | 33 | // Show summary |
37 | 34 | $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ) ); |
— | — | @@ -39,7 +36,7 @@ |
40 | 37 | $this->printHeader( $sub ); |
41 | 38 | |
42 | 39 | // Handle form sumissions |
43 | | - if ( $wgRequest->wasPosted() ) { |
| 40 | + if ( $this->editable && $wgRequest->wasPosted() ) { |
44 | 41 | |
45 | 42 | // Handle removing |
46 | 43 | $toRemove = $wgRequest->getArray( 'removeNotices' ); |
— | — | @@ -130,7 +127,7 @@ |
131 | 128 | // Handle adding |
132 | 129 | $method = $wgRequest->getVal( 'method' ); |
133 | 130 | $this->showAll = $wgRequest->getVal( 'showAll' ); |
134 | | - if ( $method == 'addNotice' ) { |
| 131 | + if ( $this->editable && $method == 'addNotice' ) { |
135 | 132 | $noticeName = $wgRequest->getVal( 'noticeName' ); |
136 | 133 | $start = $wgRequest->getArray( 'start' ); |
137 | 134 | $project_name = $wgRequest->getVal( 'project_name' ); |
— | — | @@ -144,13 +141,13 @@ |
145 | 142 | } |
146 | 143 | |
147 | 144 | // Handle removing |
148 | | - if ( $method == 'removeNotice' ) { |
| 145 | + if ( $this->editable && $method == 'removeNotice' ) { |
149 | 146 | $noticeName = $wgRequest->getVal ( 'noticeName' ); |
150 | 147 | $this->removeNotice ( $noticeName ); |
151 | 148 | } |
152 | 149 | |
153 | 150 | // Handle adding of template |
154 | | - if ( $method == 'addTemplateTo' ) { |
| 151 | + if ( $this->editable && $method == 'addTemplateTo' ) { |
155 | 152 | $noticeName = $wgRequest->getVal( 'noticeName' ); |
156 | 153 | $templateName = $wgRequest->getVal( 'templateName' ); |
157 | 154 | $templateWeight = $wgRequest->getVal ( 'weight' ); |
— | — | @@ -160,7 +157,7 @@ |
161 | 158 | } |
162 | 159 | |
163 | 160 | // Handle removing of template |
164 | | - if ( $method == 'removeTemplateFor' ) { |
| 161 | + if ( $this->editable && $method == 'removeTemplateFor' ) { |
165 | 162 | $noticeName = $wgRequest->getVal ( 'noticeName' ); |
166 | 163 | $templateName = $wgRequest->getVal ( 'templateName ' ); |
167 | 164 | $this->removeTemplateFor( $noticeName , $templateName ); |
— | — | @@ -233,41 +230,51 @@ |
234 | 231 | } |
235 | 232 | |
236 | 233 | function dateSelector( $prefix, $timestamp = null ) { |
237 | | - // Default ranges... |
238 | | - $years = range( 2007, 2012 ); |
239 | | - $months = range( 1, 12 ); |
240 | | - $months = array_map( array( $this, 'addZero' ), $months ); |
241 | | - $days = range( 1 , 31 ); |
242 | | - $days = array_map( array( $this, 'addZero' ), $days ); |
243 | | - |
244 | | - // Normalize timestamp format... |
245 | | - $ts = wfTimestamp( TS_MW, $timestamp ); |
246 | | - |
247 | | - $fields = array( |
248 | | - array( "month", "centralnotice-month", $months, substr( $ts, 4, 2 ) ), |
249 | | - array( "day", "centralnotice-day", $days, substr( $ts, 6, 2 ) ), |
250 | | - array( "year", "centralnotice-year", $years, substr( $ts, 0, 4 ) ), |
251 | | - ); |
252 | | - |
253 | | - return $this->genSelector( $prefix, $fields ); |
| 234 | + if( $this->editable ) { |
| 235 | + // Default ranges... |
| 236 | + $years = range( 2007, 2012 ); |
| 237 | + $months = range( 1, 12 ); |
| 238 | + $months = array_map( array( $this, 'addZero' ), $months ); |
| 239 | + $days = range( 1 , 31 ); |
| 240 | + $days = array_map( array( $this, 'addZero' ), $days ); |
| 241 | + |
| 242 | + // Normalize timestamp format... |
| 243 | + $ts = wfTimestamp( TS_MW, $timestamp ); |
| 244 | + |
| 245 | + $fields = array( |
| 246 | + array( "month", "centralnotice-month", $months, substr( $ts, 4, 2 ) ), |
| 247 | + array( "day", "centralnotice-day", $days, substr( $ts, 6, 2 ) ), |
| 248 | + array( "year", "centralnotice-year", $years, substr( $ts, 0, 4 ) ), |
| 249 | + ); |
| 250 | + |
| 251 | + return $this->genSelector( $prefix, $fields ); |
| 252 | + } else { |
| 253 | + global $wgLang; |
| 254 | + return $wgLang->date( $timestamp ); |
| 255 | + } |
254 | 256 | } |
255 | 257 | |
256 | 258 | function timeSelector( $prefix, $timestamp = null ) { |
257 | | - // Default ranges... |
258 | | - $minutes = range( 0, 59 ); // formerly in 15-minute increments |
259 | | - $minutes = array_map( array( $this, 'addZero' ), $minutes ); |
260 | | - $hours = range( 0 , 23 ); |
261 | | - $hours = array_map( array( $this, 'addZero' ), $hours ); |
262 | | - |
263 | | - // Normalize timestamp format... |
264 | | - $ts = wfTimestamp( TS_MW, $timestamp ); |
265 | | - |
266 | | - $fields = array( |
267 | | - array( "hour", "centralnotice-hours", $hours, substr( $ts, 8, 2 ) ), |
268 | | - array( "min", "centralnotice-min", $minutes, substr( $ts, 10, 2 ) ), |
269 | | - ); |
270 | | - |
271 | | - return $this->genSelector( $prefix, $fields ); |
| 259 | + if( $this->editable ) { |
| 260 | + // Default ranges... |
| 261 | + $minutes = range( 0, 59 ); // formerly in 15-minute increments |
| 262 | + $minutes = array_map( array( $this, 'addZero' ), $minutes ); |
| 263 | + $hours = range( 0 , 23 ); |
| 264 | + $hours = array_map( array( $this, 'addZero' ), $hours ); |
| 265 | + |
| 266 | + // Normalize timestamp format... |
| 267 | + $ts = wfTimestamp( TS_MW, $timestamp ); |
| 268 | + |
| 269 | + $fields = array( |
| 270 | + array( "hour", "centralnotice-hours", $hours, substr( $ts, 8, 2 ) ), |
| 271 | + array( "min", "centralnotice-min", $minutes, substr( $ts, 10, 2 ) ), |
| 272 | + ); |
| 273 | + |
| 274 | + return $this->genSelector( $prefix, $fields ); |
| 275 | + } else { |
| 276 | + global $wgLang; |
| 277 | + return $wgLang->time( $timestamp ); |
| 278 | + } |
272 | 279 | } |
273 | 280 | |
274 | 281 | private function genSelector( $prefix, $fields ) { |
— | — | @@ -295,6 +302,11 @@ |
296 | 303 | // Get connection |
297 | 304 | $dbr = wfGetDB( DB_SLAVE ); |
298 | 305 | $sk = $wgUser->getSkin(); |
| 306 | + if( $this->editable ) { |
| 307 | + $readonly = array(); |
| 308 | + } else { |
| 309 | + $readonly = array( 'disabled' => 'disabled' ); |
| 310 | + } |
299 | 311 | |
300 | 312 | /* |
301 | 313 | * This is temporarily hard-coded |
— | — | @@ -336,12 +348,15 @@ |
337 | 349 | } |
338 | 350 | |
339 | 351 | // Build HTML |
340 | | - $htmlOut = Xml::openElement( 'form', |
341 | | - array( |
342 | | - 'method' => 'post', |
343 | | - 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getFullUrl() |
344 | | - ) |
345 | | - ); |
| 352 | + $htmlOut = ''; |
| 353 | + if( $this->editable ) { |
| 354 | + $htmlOut .= Xml::openElement( 'form', |
| 355 | + array( |
| 356 | + 'method' => 'post', |
| 357 | + 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getFullUrl() |
| 358 | + ) |
| 359 | + ); |
| 360 | + } |
346 | 361 | $htmlOut .= Xml::fieldset( wfMsgHtml( "centralnotice-manage" ) ); |
347 | 362 | $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) ); |
348 | 363 | |
— | — | @@ -354,8 +369,10 @@ |
355 | 370 | wfMsgHtml( 'centralnotice-end-date' ), |
356 | 371 | wfMsgHtml( 'centralnotice-enabled' ), |
357 | 372 | wfMsgHtml( 'centralnotice-locked' ), |
358 | | - wfMsgHtml( 'centralnotice-remove' ), |
359 | 373 | ); |
| 374 | + if( $this->editable ) { |
| 375 | + $headers[] = wfMsgHtml( 'centralnotice-remove' ); |
| 376 | + } |
360 | 377 | $htmlOut .= $this->tableRow( $headers, 'th' ); |
361 | 378 | |
362 | 379 | // Rows |
— | — | @@ -397,33 +414,41 @@ |
398 | 415 | // Enabled |
399 | 416 | $fields[] = |
400 | 417 | Xml::check( 'enabled[]', ( $row->not_enabled == '1' ), |
401 | | - array( 'value' => $row->not_name ) ); |
| 418 | + wfArrayMerge( $readonly, |
| 419 | + array( 'value' => $row->not_name ) ) ); |
402 | 420 | |
403 | 421 | // Locked |
404 | 422 | $fields[] = |
405 | 423 | Xml::check( 'locked[]', ( $row->not_locked == '1' ), |
406 | | - array( 'value' => $row->not_name ) ); |
| 424 | + wfArrayMerge( $readonly, |
| 425 | + array( 'value' => $row->not_name ) ) ); |
407 | 426 | |
408 | | - // Remove |
409 | | - $fields[] = Xml::check( 'removeNotices[]', false, |
410 | | - array( 'value' => $row->not_name ) ); |
| 427 | + if( $this->editable ) { |
| 428 | + // Remove |
| 429 | + $fields[] = Xml::check( 'removeNotices[]', false, |
| 430 | + array( 'value' => $row->not_name ) ); |
| 431 | + } |
411 | 432 | |
412 | 433 | $htmlOut .= $this->tableRow( $fields ); |
413 | 434 | } |
414 | | - $htmlOut .= $this->tableRow( |
415 | | - array( |
416 | | - Xml::submitButton( wfMsgHtml( 'centralnotice-modify' ), |
417 | | - array( |
418 | | - 'id' => 'centralnoticesubmit', |
419 | | - 'name' => 'centralnoticesubmit' |
| 435 | + if( $this->editable ) { |
| 436 | + $htmlOut .= $this->tableRow( |
| 437 | + array( |
| 438 | + Xml::submitButton( wfMsgHtml( 'centralnotice-modify' ), |
| 439 | + array( |
| 440 | + 'id' => 'centralnoticesubmit', |
| 441 | + 'name' => 'centralnoticesubmit' |
| 442 | + ) |
420 | 443 | ) |
421 | 444 | ) |
422 | | - ) |
423 | | - ); |
| 445 | + ); |
| 446 | + } |
424 | 447 | |
425 | 448 | $htmlOut .= Xml::closeElement( 'table' ); |
426 | 449 | $htmlOut .= Xml::closeElement( 'fieldset' ); |
427 | | - $htmlOut .= Xml::closeElement( 'form' ); |
| 450 | + if( $this->editable ) { |
| 451 | + $htmlOut .= Xml::closeElement( 'form' ); |
| 452 | + } |
428 | 453 | |
429 | 454 | |
430 | 455 | // No notices to show |
— | — | @@ -431,57 +456,60 @@ |
432 | 457 | $htmlOut = wfMsg( 'centralnotice-no-notices-exist' ); |
433 | 458 | } |
434 | 459 | |
435 | | - // Notice Adding |
436 | | - $htmlOut .= Xml::openElement( 'form', |
437 | | - array( |
438 | | - 'method' => 'post', |
439 | | - 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl() |
440 | | - ) |
441 | | - ); |
442 | | - $htmlOut .= Xml::openElement( 'fieldset' ); |
443 | | - $htmlOut .= Xml::element( 'legend', null, wfMsg( 'centralnotice-add-notice' ) ); |
444 | | - $htmlOut .= Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ); |
445 | | - $htmlOut .= Xml::hidden( 'method', 'addNotice' ); |
446 | | - |
447 | | - $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) ); |
448 | | - |
449 | | - $table = array( |
450 | | - // Name |
451 | | - array( |
452 | | - wfMsgHtml( 'centralnotice-notice-name' ), |
453 | | - Xml::inputLabel( '', 'noticeName', 'noticeName', 25 ), |
454 | | - ), |
455 | | - // Start Date |
456 | | - array( |
457 | | - Xml::label( wfMsg( 'centralnotice-start-date' ), 'start-date' ), |
458 | | - $this->dateSelector( 'start' ), |
459 | | - ), |
460 | | - // Start Time |
461 | | - array( |
462 | | - wfMsgHtml( 'centralnotice-start-hour' ) . "(GMT)", |
463 | | - $this->timeSelector( 'start' ), |
464 | | - ), |
465 | | - // Project |
466 | | - array( |
467 | | - wfMsgHtml( 'centralnotice-project-name' ), |
468 | | - $this->projectDropDownList(), |
469 | | - ), |
470 | | - // Languages + All |
471 | | - $this->languageDropDownList( $wpUserLang ), |
472 | | - // Submit |
473 | | - array( |
474 | | - Xml::submitButton( wfMsg( 'centralnotice-modify' ) ), |
475 | | - ), |
476 | | - ); |
477 | | - |
478 | | - foreach ( $table as $cells ) { |
479 | | - $htmlOut .= $this->tableRow( $cells ); |
| 460 | + if( $this->editable ) { |
| 461 | + // Notice Adding |
| 462 | + $htmlOut .= Xml::openElement( 'form', |
| 463 | + array( |
| 464 | + 'method' => 'post', |
| 465 | + 'action' => SpecialPage::getTitleFor( 'CentralNotice' )->getLocalUrl() |
| 466 | + ) |
| 467 | + ); |
| 468 | + $htmlOut .= Xml::openElement( 'fieldset' ); |
| 469 | + $htmlOut .= Xml::element( 'legend', null, wfMsg( 'centralnotice-add-notice' ) ); |
| 470 | + $htmlOut .= Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ); |
| 471 | + $htmlOut .= Xml::hidden( 'method', 'addNotice' ); |
| 472 | + |
| 473 | + $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) ); |
| 474 | + |
| 475 | + $table = array( |
| 476 | + // Name |
| 477 | + array( |
| 478 | + wfMsgHtml( 'centralnotice-notice-name' ), |
| 479 | + Xml::inputLabel( '', 'noticeName', 'noticeName', 25 ), |
| 480 | + ), |
| 481 | + // Start Date |
| 482 | + array( |
| 483 | + Xml::label( wfMsg( 'centralnotice-start-date' ), 'start-date' ), |
| 484 | + $this->dateSelector( 'start' ), |
| 485 | + ), |
| 486 | + // Start Time |
| 487 | + array( |
| 488 | + wfMsgHtml( 'centralnotice-start-hour' ) . "(GMT)", |
| 489 | + $this->timeSelector( 'start' ), |
| 490 | + ), |
| 491 | + // Project |
| 492 | + array( |
| 493 | + wfMsgHtml( 'centralnotice-project-name' ), |
| 494 | + $this->projectDropDownList(), |
| 495 | + ), |
| 496 | + // Languages + All |
| 497 | + $this->languageDropDownList( $wpUserLang ), |
| 498 | + // Submit |
| 499 | + array( |
| 500 | + Xml::submitButton( wfMsg( 'centralnotice-modify' ) ), |
| 501 | + ), |
| 502 | + ); |
| 503 | + |
| 504 | + foreach ( $table as $cells ) { |
| 505 | + $htmlOut .= $this->tableRow( $cells ); |
| 506 | + } |
| 507 | + |
| 508 | + $htmlOut .= Xml::hidden( 'change', 'weight' ); |
| 509 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 510 | + $htmlOut .= Xml::closeElement( 'fieldset' ); |
| 511 | + $htmlOut .= Xml::closeElement( 'form' ); |
480 | 512 | } |
481 | | - |
482 | | - $htmlOut .= Xml::hidden( 'change', 'weight' ); |
483 | | - $htmlOut .= Xml::closeElement( 'table' ); |
484 | | - $htmlOut .= Xml::closeElement( 'fieldset' ); |
485 | | - $htmlOut .= Xml::closeElement( 'form' ); |
| 513 | + |
486 | 514 | // Output HTML |
487 | 515 | $wgOut->addHTML( $htmlOut ); |
488 | 516 | } |
— | — | @@ -519,12 +547,15 @@ |
520 | 548 | } |
521 | 549 | } |
522 | 550 | |
523 | | - $htmlOut = Xml::openElement( 'form', |
524 | | - array( |
525 | | - 'method' => 'post', |
526 | | - 'action' => '' |
527 | | - ) |
528 | | - ); |
| 551 | + $htmlOut = ''; |
| 552 | + if( $this->editable ) { |
| 553 | + $htmlOut .= Xml::openElement( 'form', |
| 554 | + array( |
| 555 | + 'method' => 'post', |
| 556 | + 'action' => '' |
| 557 | + ) |
| 558 | + ); |
| 559 | + } |
529 | 560 | |
530 | 561 | /* |
531 | 562 | * Temporarily hard coded |
— | — | @@ -549,28 +580,34 @@ |
550 | 581 | $htmlOut .= $output; |
551 | 582 | } |
552 | 583 | |
553 | | - |
554 | | - $output = $this->addTemplatesForm( $notice ); |
555 | | - |
556 | | - // No templates in the system |
557 | | - if ( $output == '' ) { |
558 | | - $htmlOut .= wfMsg( 'centralnotice-no-templates' ); |
559 | | - } else { |
560 | | - $htmlOut .= $output; |
| 584 | + if( $this->editable ) { |
| 585 | + $output = $this->addTemplatesForm( $notice ); |
| 586 | + |
| 587 | + // No templates in the system |
| 588 | + if ( $output == '' ) { |
| 589 | + $htmlOut .= wfMsg( 'centralnotice-no-templates' ); |
| 590 | + } else { |
| 591 | + $htmlOut .= $output; |
| 592 | + } |
| 593 | + |
| 594 | + $htmlOut .= Xml::tags( 'tr', null, |
| 595 | + Xml::tags( 'td', array( 'collspan' => 2 ), |
| 596 | + Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) |
| 597 | + ) |
| 598 | + ); |
| 599 | + |
| 600 | + $htmlOut .= Xml::closeElement( 'form' ); |
561 | 601 | } |
562 | 602 | |
563 | | - # $htmlOut .= Xml::closeElement( 'table'); |
564 | | - # $htmlOut .= Xml::closeElement( 'fieldset' ); |
565 | | - $htmlOut .= Xml::tags( 'tr', null, |
566 | | - Xml::tags( 'td', array( 'collspan' => 2 ), |
567 | | - Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) |
568 | | - ) |
569 | | - ); |
570 | | - $htmlOut .= Xml::closeElement( 'form' ); |
571 | 603 | $wgOut->addHTML( $htmlOut ); |
572 | 604 | } |
573 | 605 | |
574 | 606 | function noticeDetailForm( $notice ) { |
| 607 | + if( $this->editable ) { |
| 608 | + $readonly = array(); |
| 609 | + } else { |
| 610 | + $readonly = array( 'disabled' => 'disabled' ); |
| 611 | + } |
575 | 612 | $dbr = wfGetDB( DB_SLAVE ); |
576 | 613 | |
577 | 614 | $row = $dbr->selectRow( 'cn_notices', |
— | — | @@ -622,21 +659,25 @@ |
623 | 660 | array( |
624 | 661 | wfMsgHtml( 'centralnotice-enabled' ), |
625 | 662 | Xml::check( 'enabled[]', ( $row->not_enabled == '1' ), |
626 | | - array( 'value' => $row->not_name ) ) |
| 663 | + wfArrayMerge( $readonly, |
| 664 | + array( 'value' => $row->not_name ) ) ) |
627 | 665 | ), |
628 | 666 | // Locked |
629 | 667 | array( |
630 | 668 | wfMsgHtml( 'centralnotice-locked' ), |
631 | 669 | Xml::check( 'locked[]', ( $row->not_locked == '1' ), |
632 | | - array( 'value' => $row->not_name ) ), |
| 670 | + wfArrayMerge( $readonly, |
| 671 | + array( 'value' => $row->not_name ) ) ), |
633 | 672 | ), |
| 673 | + ); |
| 674 | + if( $this->editable ) { |
634 | 675 | // Remove |
635 | | - array( |
| 676 | + $table[] = array( |
636 | 677 | wfMsgHtml( 'centralnotice-remove' ), |
637 | 678 | Xml::check( 'removeNotices[]', false, |
638 | 679 | array( 'value' => $row->not_name ) ) |
639 | | - ), |
640 | | - ); |
| 680 | + ); |
| 681 | + } |
641 | 682 | foreach ( $table as $cells ) { |
642 | 683 | $htmlOut .= $this->tableRow( $cells ); |
643 | 684 | } |
— | — | @@ -687,9 +728,11 @@ |
688 | 729 | 'width' => '100%' |
689 | 730 | ) |
690 | 731 | ); |
| 732 | + if( $this->editable ) { |
| 733 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
| 734 | + wfMsg ( "centralnotice-remove" ) ); |
| 735 | + } |
691 | 736 | $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
692 | | - wfMsg ( "centralnotice-remove" ) ); |
693 | | - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
694 | 737 | wfMsg ( "centralnotice-weight" ) ); |
695 | 738 | $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '70%' ), |
696 | 739 | wfMsg ( "centralnotice-templates" ) ); |
— | — | @@ -699,20 +742,16 @@ |
700 | 743 | |
701 | 744 | $htmlOut .= Xml::openElement( 'tr' ); |
702 | 745 | |
703 | | - // Remove |
704 | | - $htmlOut .= Xml::tags( 'td', null, |
| 746 | + if( $this->editable ) { |
| 747 | + // Remove |
| 748 | + $htmlOut .= Xml::tags( 'td', null, |
705 | 749 | Xml::check( 'removeTemplates[]', false, array( 'value' => $row->tmp_name ) ) |
706 | | - ); |
| 750 | + ); |
| 751 | + } |
707 | 752 | |
708 | 753 | // Weight |
709 | 754 | $htmlOut .= Xml::tags( 'td', null, |
710 | | - Xml::listDropDown( "weight[$row->tmp_name]", |
711 | | - $this->dropDownList( wfMsg( 'centralnotice-weight' ), |
712 | | - range ( 0, 100, 5 ) ), |
713 | | - '', |
714 | | - $row->tmp_weight, |
715 | | - '', |
716 | | - 1 ) |
| 755 | + $this->weightDropDown( "weight[$row->tmp_name]", $row->tmp_weight ) |
717 | 756 | ); |
718 | 757 | |
719 | 758 | $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate/view' ); |
— | — | @@ -736,6 +775,20 @@ |
737 | 776 | return $htmlOut; |
738 | 777 | |
739 | 778 | } |
| 779 | + |
| 780 | + function weightDropDown( $name, $selected ) { |
| 781 | + if( $this->editable ) { |
| 782 | + return Xml::listDropDown( $name, |
| 783 | + $this->dropDownList( wfMsg( 'centralnotice-weight' ), |
| 784 | + range ( 0, 100, 5 ) ), |
| 785 | + '', |
| 786 | + $selected, |
| 787 | + '', |
| 788 | + 1 ); |
| 789 | + } else { |
| 790 | + return htmlspecialchars( $selected ); |
| 791 | + } |
| 792 | + } |
740 | 793 | |
741 | 794 | |
742 | 795 | function addTemplatesForm( $notice ) { |
— | — | @@ -1113,38 +1166,57 @@ |
1114 | 1167 | |
1115 | 1168 | function projectDropDownList( $selected = '' ) { |
1116 | 1169 | global $wgNoticeProjects; |
1117 | | - |
1118 | | - $htmlOut = Xml::openElement( 'select', array( 'name' => 'project_name' ) ); |
1119 | | - $htmlOut .= Xml::option( 'All projects', '', ( $selected == '' ) ); |
1120 | | - foreach ( $wgNoticeProjects as $value ) { |
1121 | | - $htmlOut .= Xml::option( $value, $value, ( $selected == $value ) ); |
| 1170 | + |
| 1171 | + if( $this->editable ) { |
| 1172 | + $htmlOut = Xml::openElement( 'select', array( 'name' => 'project_name' ) ); |
| 1173 | + $htmlOut .= Xml::option( 'All projects', '', ( $selected == '' ) ); |
| 1174 | + foreach ( $wgNoticeProjects as $value ) { |
| 1175 | + $htmlOut .= Xml::option( $value, $value, ( $selected == $value ) ); |
| 1176 | + } |
| 1177 | + $htmlOut .= Xml::closeElement( 'select' ); |
| 1178 | + return $htmlOut; |
| 1179 | + } else { |
| 1180 | + if( $selected == '' ) { |
| 1181 | + return 'All projects'; |
| 1182 | + } else { |
| 1183 | + return htmlspecialchars( $selected ); |
| 1184 | + } |
1122 | 1185 | } |
1123 | | - $htmlOut .= Xml::closeElement( 'select' ); |
1124 | | - return $htmlOut; |
1125 | 1186 | } |
1126 | 1187 | |
1127 | 1188 | function languageDropDownList( $selected = '' ) { |
1128 | 1189 | // Language |
1129 | 1190 | list( $lsLabel, $lsSelect ) = Xml::languageSelector( $selected ); |
1130 | 1191 | |
1131 | | - /* |
1132 | | - * Dirty hack to add our very own "All" option |
1133 | | - */ |
1134 | | - // Strip selected flag |
1135 | | - if ( $selected == '' ) { |
1136 | | - $lsSelect = str_replace( ' selected="selected"', '', $lsSelect ); |
| 1192 | + if( $this->editable ) { |
| 1193 | + /* |
| 1194 | + * Dirty hack to add our very own "All" option |
| 1195 | + */ |
| 1196 | + // Strip selected flag |
| 1197 | + if ( $selected == '' ) { |
| 1198 | + $lsSelect = str_replace( ' selected="selected"', '', $lsSelect ); |
| 1199 | + } |
| 1200 | + |
| 1201 | + // Find the first select tag |
| 1202 | + $insertPoint = stripos( $lsSelect , '<option' ); |
| 1203 | + |
| 1204 | + // Create our own option |
| 1205 | + $option = Xml::option( 'All languages', '', ( $selected == '' ) ); |
| 1206 | + |
| 1207 | + // Insert our option |
| 1208 | + $lsSelect = substr( $lsSelect, 0, $insertPoint ) . $option . substr( $lsSelect, $insertPoint ); |
| 1209 | + |
| 1210 | + return array( $lsLabel, $lsSelect ); |
| 1211 | + } else { |
| 1212 | + if( $selected == '' ) { |
| 1213 | + $lang = 'All languages'; |
| 1214 | + } else { |
| 1215 | + global $wgLang; |
| 1216 | + $name = $wgLang->getLanguageName( $selected ); |
| 1217 | + $lang = htmlspecialchars( "$selected - $name" ); |
| 1218 | + } |
| 1219 | + return array( $lsLabel, $lang ); |
1137 | 1220 | } |
1138 | | - |
1139 | | - // Find the first select tag |
1140 | | - $insertPoint = stripos( $lsSelect , '<option' ); |
1141 | | - |
1142 | | - // Create our own option |
1143 | | - $option = Xml::option( 'All languages', '', ( $selected == '' ) ); |
1144 | | - |
1145 | | - // Insert our option |
1146 | | - $lsSelect = substr( $lsSelect, 0, $insertPoint ) . $option . substr( $lsSelect, $insertPoint ); |
1147 | | - |
1148 | | - return array( $lsLabel, $lsSelect ); |
1149 | 1221 | } |
1150 | 1222 | |
1151 | 1223 | function getProjectName( $value ) { |
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php |
— | — | @@ -27,10 +27,7 @@ |
28 | 28 | $sk = $wgUser->getSkin(); |
29 | 29 | |
30 | 30 | // Check permissions |
31 | | - if ( !$wgUser->isAllowed( 'centralnotice_admin_rights' ) ) { |
32 | | - $wgOut->permissionRequired( 'centralnotice_admin_rights' ); |
33 | | - return; |
34 | | - } |
| 31 | + $this->editable = $wgUser->isAllowed( 'centralnotice_admin_rights' ); |
35 | 32 | |
36 | 33 | // Show summary |
37 | 34 | $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ) ); |
— | — | @@ -38,42 +35,44 @@ |
39 | 36 | // Show header |
40 | 37 | CentralNotice::printHeader(); |
41 | 38 | |
42 | | - // Handle forms |
43 | | - if ( $wgRequest->wasPosted() ) { |
44 | | - |
45 | | - // Handle removing |
46 | | - $toRemove = $wgRequest->getArray( 'removeTemplates' ); |
47 | | - if ( isset( $toRemove ) ) { |
48 | | - // Remove templates in list |
49 | | - foreach ( $toRemove as $template ) { |
50 | | - $this->removeTemplate( $template ); |
| 39 | + if( $this->editable ) { |
| 40 | + // Handle forms |
| 41 | + if ( $wgRequest->wasPosted() ) { |
| 42 | + |
| 43 | + // Handle removing |
| 44 | + $toRemove = $wgRequest->getArray( 'removeTemplates' ); |
| 45 | + if ( isset( $toRemove ) ) { |
| 46 | + // Remove templates in list |
| 47 | + foreach ( $toRemove as $template ) { |
| 48 | + $this->removeTemplate( $template ); |
| 49 | + } |
51 | 50 | } |
52 | | - } |
53 | | - |
54 | | - // Handle translation message update |
55 | | - $update = $wgRequest->getArray( 'updateText' ); |
56 | | - $token = $wgRequest->getArray( 'token' ); |
57 | | - if ( isset ( $update ) ) { |
58 | | - foreach ( $update as $lang => $messages ) { |
59 | | - foreach ( $messages as $text => $translation ) { |
60 | | - // If we actually have text |
61 | | - if ( $translation ) { |
62 | | - $this->updateMessage( $text, $translation, $lang, $token ); |
| 51 | + |
| 52 | + // Handle translation message update |
| 53 | + $update = $wgRequest->getArray( 'updateText' ); |
| 54 | + $token = $wgRequest->getArray( 'token' ); |
| 55 | + if ( isset ( $update ) ) { |
| 56 | + foreach ( $update as $lang => $messages ) { |
| 57 | + foreach ( $messages as $text => $translation ) { |
| 58 | + // If we actually have text |
| 59 | + if ( $translation ) { |
| 60 | + $this->updateMessage( $text, $translation, $lang, $token ); |
| 61 | + } |
63 | 62 | } |
64 | 63 | } |
65 | 64 | } |
66 | 65 | } |
| 66 | + |
| 67 | + // Handle adding |
| 68 | + if ( $wgRequest->getVal( 'wpMethod' ) == 'addTemplate' ) { |
| 69 | + $this->addTemplate( |
| 70 | + $wgRequest->getVal( 'templateName' ), |
| 71 | + $wgRequest->getVal( 'templateBody' ) |
| 72 | + ); |
| 73 | + $sub = 'view'; |
| 74 | + } |
67 | 75 | } |
68 | 76 | |
69 | | - // Handle adding |
70 | | - if ( $wgRequest->getVal( 'wpMethod' ) == 'addTemplate' ) { |
71 | | - $this->addTemplate( |
72 | | - $wgRequest->getVal( 'templateName' ), |
73 | | - $wgRequest->getVal( 'templateBody' ) |
74 | | - ); |
75 | | - $sub = 'view'; |
76 | | - } |
77 | | - |
78 | 77 | // Handle Editing |
79 | 78 | if ( $wgRequest->getVal( 'wpMethod' ) == 'editTemplate' ) { |
80 | 79 | $this->editTemplate( |
— | — | @@ -89,10 +88,12 @@ |
90 | 89 | return; |
91 | 90 | } |
92 | 91 | |
93 | | - // Handle viewing a specific template |
94 | | - if ( $sub == 'add' ) { |
95 | | - $this->showAdd(); |
96 | | - return; |
| 92 | + if( $this->editable ) { |
| 93 | + // Handle viewing a specific template |
| 94 | + if ( $sub == 'add' ) { |
| 95 | + $this->showAdd(); |
| 96 | + return; |
| 97 | + } |
97 | 98 | } |
98 | 99 | |
99 | 100 | // Show list by default |
— | — | @@ -107,22 +108,28 @@ |
108 | 109 | // Templates |
109 | 110 | $templates = $this->queryTemplates(); |
110 | 111 | if ( count( $templates ) > 0 ) { |
111 | | - $htmlOut = Xml::openElement( 'form', |
112 | | - array( |
113 | | - 'method' => 'post', |
114 | | - 'action' => '' |
115 | | - ) |
116 | | - ); |
| 112 | + $htmlOut = ''; |
| 113 | + |
| 114 | + if( $this->editable ) { |
| 115 | + $htmlOut .= Xml::openElement( 'form', |
| 116 | + array( |
| 117 | + 'method' => 'post', |
| 118 | + 'action' => '' |
| 119 | + ) |
| 120 | + ); |
| 121 | + } |
117 | 122 | $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-available-templates' ) ); |
118 | 123 | $htmlOut .= Xml::openElement( 'table', |
119 | 124 | array( |
120 | 125 | 'cellpadding' => 9, |
121 | 126 | 'width' => '100%' |
122 | 127 | ) |
123 | | - ) ; |
124 | | - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
125 | | - wfMsg ( 'centralnotice-remove' ) |
126 | 128 | ); |
| 129 | + if( $this->editable ) { |
| 130 | + $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ), |
| 131 | + wfMsg ( 'centralnotice-remove' ) |
| 132 | + ); |
| 133 | + } |
127 | 134 | $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ), |
128 | 135 | wfMsg ( 'centralnotice-template-name' ) |
129 | 136 | ); |
— | — | @@ -132,15 +139,17 @@ |
133 | 140 | $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate/view' ); |
134 | 141 | $htmlOut .= Xml::openElement( 'tr' ); |
135 | 142 | |
136 | | - // Remove box |
137 | | - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
138 | | - Xml::check( 'removeTemplates[]', false, |
139 | | - array( |
140 | | - 'value' => $templateName, |
141 | | - 'onchange' => "if(this.checked){this.checked=confirm('{$msgConfirmDelete}')}" |
| 143 | + if( $this->editable ) { |
| 144 | + // Remove box |
| 145 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
| 146 | + Xml::check( 'removeTemplates[]', false, |
| 147 | + array( |
| 148 | + 'value' => $templateName, |
| 149 | + 'onchange' => "if(this.checked){this.checked=confirm('{$msgConfirmDelete}')}" |
| 150 | + ) |
142 | 151 | ) |
143 | | - ) |
144 | | - ); |
| 152 | + ); |
| 153 | + } |
145 | 154 | |
146 | 155 | // Link and Preview |
147 | 156 | $render = new SpecialNoticeText(); |
— | — | @@ -157,11 +166,13 @@ |
158 | 167 | |
159 | 168 | $htmlOut .= Xml::closeElement( 'tr' ); |
160 | 169 | } |
161 | | - $htmlOut .= Xml::tags( 'tr', null, |
162 | | - Xml::tags( 'td', array( 'colspan' => 3 ), |
163 | | - Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) |
164 | | - ) |
165 | | - ); |
| 170 | + if( $this->editable ) { |
| 171 | + $htmlOut .= Xml::tags( 'tr', null, |
| 172 | + Xml::tags( 'td', array( 'colspan' => 3 ), |
| 173 | + Xml::submitButton( wfMsg( 'centralnotice-modify' ) ) |
| 174 | + ) |
| 175 | + ); |
| 176 | + } |
166 | 177 | } else { |
167 | 178 | $htmlOut = Xml::tags( 'tr', null, |
168 | 179 | Xml::element( 'td', null, wfMsg( 'centralnotice-no-templates' ) ) |
— | — | @@ -169,11 +180,13 @@ |
170 | 181 | } |
171 | 182 | $htmlOut .= Xml::closeElement( 'table' ); |
172 | 183 | $htmlOut .= Xml::closeElement( 'fieldset' ); |
173 | | - $htmlOut .= Xml::closeElement( 'form' ); |
| 184 | + if( $this->editable ) { |
| 185 | + $htmlOut .= Xml::closeElement( 'form' ); |
174 | 186 | |
175 | | - // Show add link |
176 | | - $newPage = SpecialPage::getTitleFor( 'NoticeTemplate/add' ); |
177 | | - $htmlOut .= $sk->makeLinkObj( $newPage, wfMsgHtml( 'centralnotice-add-template' ) ); |
| 187 | + // Show add link |
| 188 | + $newPage = SpecialPage::getTitleFor( 'NoticeTemplate/add' ); |
| 189 | + $htmlOut .= $sk->makeLinkObj( $newPage, wfMsgHtml( 'centralnotice-add-template' ) ); |
| 190 | + } |
178 | 191 | |
179 | 192 | // Output HTML |
180 | 193 | $wgOut->addHtml( $htmlOut ); |
— | — | @@ -212,6 +225,11 @@ |
213 | 226 | global $wgOut, $wgUser, $wgRequest, $wgContLanguageCode; |
214 | 227 | |
215 | 228 | $sk = $wgUser->getSkin(); |
| 229 | + if( $this->editable ) { |
| 230 | + $readonly = array(); |
| 231 | + } else { |
| 232 | + $readonly = array( 'readonly' => 'readonly' ); |
| 233 | + } |
216 | 234 | |
217 | 235 | // Get token |
218 | 236 | $token = $wgUser->editToken(); |
— | — | @@ -231,7 +249,9 @@ |
232 | 250 | ); |
233 | 251 | |
234 | 252 | // Build HTML |
235 | | - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 253 | + if( $this->editable ) { |
| 254 | + $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 255 | + } |
236 | 256 | $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-translate-heading', $currentTemplate ) ); |
237 | 257 | $htmlOut .= Xml::openElement( 'table', |
238 | 258 | array ( |
— | — | @@ -301,23 +321,27 @@ |
302 | 322 | } |
303 | 323 | $htmlOut .= Xml::tags( 'td', null, |
304 | 324 | Xml::input( "updateText[{$wpUserLang}][{$currentTemplate}-{$field}]", '', $foreignText, |
305 | | - array( 'style' => 'width:100%;' . ( !$foreignTextExists ? 'color:red' : '' ) ) |
| 325 | + wfArrayMerge( $readonly, |
| 326 | + array( 'style' => 'width:100%;' . ( !$foreignTextExists ? 'color:red' : '' ) ) ) |
306 | 327 | ) |
307 | 328 | ); |
308 | 329 | |
309 | 330 | $htmlOut .= Xml::closeElement( 'tr' ); |
310 | 331 | } |
311 | | - $htmlOut .= Xml::hidden( 'token', $token ); |
312 | | - $htmlOut .= Xml::hidden( 'wpUserLanguage', $wpUserLang ); |
313 | | - $htmlOut .= Xml::openElement( 'tr' ); |
314 | | - $htmlOut .= Xml::tags( 'td', array( 'colspan' => 4 ), |
315 | | - Xml::submitButton( wfMsg( 'centralnotice-modify', array( 'name' => 'update' ) ) ) |
316 | | - ); |
317 | | - |
318 | | - $htmlOut .= Xml::closeElement( 'tr' ); |
| 332 | + if( $this->editable ) { |
| 333 | + $htmlOut .= Xml::hidden( 'token', $token ); |
| 334 | + $htmlOut .= Xml::hidden( 'wpUserLanguage', $wpUserLang ); |
| 335 | + $htmlOut .= Xml::openElement( 'tr' ); |
| 336 | + $htmlOut .= Xml::tags( 'td', array( 'colspan' => 4 ), |
| 337 | + Xml::submitButton( wfMsg( 'centralnotice-modify', array( 'name' => 'update' ) ) ) |
| 338 | + ); |
| 339 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 340 | + } |
319 | 341 | $htmlOut .= Xml::closeElement( 'table' ); |
320 | 342 | $htmlOut .= Xml::closeElement( 'fieldset' ); |
321 | | - $htmlOut .= Xml::closeElement( 'form' ); |
| 343 | + if( $this->editable ) { |
| 344 | + $htmlOut .= Xml::closeElement( 'form' ); |
| 345 | + } |
322 | 346 | |
323 | 347 | /* |
324 | 348 | * Show language selection form |
— | — | @@ -340,9 +364,11 @@ |
341 | 365 | /* |
342 | 366 | * Show edit form |
343 | 367 | */ |
344 | | - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 368 | + if( $this->editable ) { |
| 369 | + $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
| 370 | + $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' ); |
| 371 | + } |
345 | 372 | $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-edit-template' ) ); |
346 | | - $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' ); |
347 | 373 | $htmlOut .= Xml::openElement( 'table', |
348 | 374 | array( |
349 | 375 | 'cellpadding' => 9, |
— | — | @@ -350,14 +376,18 @@ |
351 | 377 | ) |
352 | 378 | ); |
353 | 379 | $htmlOut .= Xml::tags( 'tr', null, |
354 | | - Xml::tags( 'td', null, Xml::textarea( 'templateBody', $body, 60, 20 ) ) |
| 380 | + Xml::tags( 'td', null, Xml::textarea( 'templateBody', $body, 60, 20, $readonly ) ) |
355 | 381 | ); |
356 | | - $htmlOut .= Xml::tags( 'tr', null, |
357 | | - Xml::tags( 'td', null, Xml::submitButton( wfMsgHtml( 'centralnotice-modify' ) ) ) |
358 | | - ); |
| 382 | + if( $this->editable ) { |
| 383 | + $htmlOut .= Xml::tags( 'tr', null, |
| 384 | + Xml::tags( 'td', null, Xml::submitButton( wfMsgHtml( 'centralnotice-modify' ) ) ) |
| 385 | + ); |
| 386 | + } |
359 | 387 | $htmlOut .= Xml::closeElement( 'table' ); |
360 | 388 | $htmlOut .= Xml::closeElement( 'fieldset' ); |
361 | | - $htmlOut .= Xml::closeElement( 'form' ); |
| 389 | + if( $this->editable ) { |
| 390 | + $htmlOut .= Xml::closeElement( 'form' ); |
| 391 | + } |
362 | 392 | |
363 | 393 | // Output HTML |
364 | 394 | $wgOut->addHTML( $htmlOut ); |