r43037 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43036‎ | r43037 | r43038 >
Date:22:06, 1 November 2008
Author:brion
Status:old
Tags:
Comment:
Allow non-priveledged visitors to view the notice campaigns and templates, just not edit them
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -27,10 +27,7 @@
2828 $sk = $wgUser->getSkin();
2929
3030 // 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' );
3532
3633 // Show summary
3734 $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ) );
@@ -39,7 +36,7 @@
4037 $this->printHeader( $sub );
4138
4239 // Handle form sumissions
43 - if ( $wgRequest->wasPosted() ) {
 40+ if ( $this->editable && $wgRequest->wasPosted() ) {
4441
4542 // Handle removing
4643 $toRemove = $wgRequest->getArray( 'removeNotices' );
@@ -130,7 +127,7 @@
131128 // Handle adding
132129 $method = $wgRequest->getVal( 'method' );
133130 $this->showAll = $wgRequest->getVal( 'showAll' );
134 - if ( $method == 'addNotice' ) {
 131+ if ( $this->editable && $method == 'addNotice' ) {
135132 $noticeName = $wgRequest->getVal( 'noticeName' );
136133 $start = $wgRequest->getArray( 'start' );
137134 $project_name = $wgRequest->getVal( 'project_name' );
@@ -144,13 +141,13 @@
145142 }
146143
147144 // Handle removing
148 - if ( $method == 'removeNotice' ) {
 145+ if ( $this->editable && $method == 'removeNotice' ) {
149146 $noticeName = $wgRequest->getVal ( 'noticeName' );
150147 $this->removeNotice ( $noticeName );
151148 }
152149
153150 // Handle adding of template
154 - if ( $method == 'addTemplateTo' ) {
 151+ if ( $this->editable && $method == 'addTemplateTo' ) {
155152 $noticeName = $wgRequest->getVal( 'noticeName' );
156153 $templateName = $wgRequest->getVal( 'templateName' );
157154 $templateWeight = $wgRequest->getVal ( 'weight' );
@@ -160,7 +157,7 @@
161158 }
162159
163160 // Handle removing of template
164 - if ( $method == 'removeTemplateFor' ) {
 161+ if ( $this->editable && $method == 'removeTemplateFor' ) {
165162 $noticeName = $wgRequest->getVal ( 'noticeName' );
166163 $templateName = $wgRequest->getVal ( 'templateName ' );
167164 $this->removeTemplateFor( $noticeName , $templateName );
@@ -233,41 +230,51 @@
234231 }
235232
236233 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+ }
254256 }
255257
256258 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+ }
272279 }
273280
274281 private function genSelector( $prefix, $fields ) {
@@ -295,6 +302,11 @@
296303 // Get connection
297304 $dbr = wfGetDB( DB_SLAVE );
298305 $sk = $wgUser->getSkin();
 306+ if( $this->editable ) {
 307+ $readonly = array();
 308+ } else {
 309+ $readonly = array( 'disabled' => 'disabled' );
 310+ }
299311
300312 /*
301313 * This is temporarily hard-coded
@@ -336,12 +348,15 @@
337349 }
338350
339351 // 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+ }
346361 $htmlOut .= Xml::fieldset( wfMsgHtml( "centralnotice-manage" ) );
347362 $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) );
348363
@@ -354,8 +369,10 @@
355370 wfMsgHtml( 'centralnotice-end-date' ),
356371 wfMsgHtml( 'centralnotice-enabled' ),
357372 wfMsgHtml( 'centralnotice-locked' ),
358 - wfMsgHtml( 'centralnotice-remove' ),
359373 );
 374+ if( $this->editable ) {
 375+ $headers[] = wfMsgHtml( 'centralnotice-remove' );
 376+ }
360377 $htmlOut .= $this->tableRow( $headers, 'th' );
361378
362379 // Rows
@@ -397,33 +414,41 @@
398415 // Enabled
399416 $fields[] =
400417 Xml::check( 'enabled[]', ( $row->not_enabled == '1' ),
401 - array( 'value' => $row->not_name ) );
 418+ wfArrayMerge( $readonly,
 419+ array( 'value' => $row->not_name ) ) );
402420
403421 // Locked
404422 $fields[] =
405423 Xml::check( 'locked[]', ( $row->not_locked == '1' ),
406 - array( 'value' => $row->not_name ) );
 424+ wfArrayMerge( $readonly,
 425+ array( 'value' => $row->not_name ) ) );
407426
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+ }
411432
412433 $htmlOut .= $this->tableRow( $fields );
413434 }
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+ )
420443 )
421444 )
422 - )
423 - );
 445+ );
 446+ }
424447
425448 $htmlOut .= Xml::closeElement( 'table' );
426449 $htmlOut .= Xml::closeElement( 'fieldset' );
427 - $htmlOut .= Xml::closeElement( 'form' );
 450+ if( $this->editable ) {
 451+ $htmlOut .= Xml::closeElement( 'form' );
 452+ }
428453
429454
430455 // No notices to show
@@ -431,57 +456,60 @@
432457 $htmlOut = wfMsg( 'centralnotice-no-notices-exist' );
433458 }
434459
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' );
480512 }
481 -
482 - $htmlOut .= Xml::hidden( 'change', 'weight' );
483 - $htmlOut .= Xml::closeElement( 'table' );
484 - $htmlOut .= Xml::closeElement( 'fieldset' );
485 - $htmlOut .= Xml::closeElement( 'form' );
 513+
486514 // Output HTML
487515 $wgOut->addHTML( $htmlOut );
488516 }
@@ -519,12 +547,15 @@
520548 }
521549 }
522550
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+ }
529560
530561 /*
531562 * Temporarily hard coded
@@ -549,28 +580,34 @@
550581 $htmlOut .= $output;
551582 }
552583
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' );
561601 }
562602
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' );
571603 $wgOut->addHTML( $htmlOut );
572604 }
573605
574606 function noticeDetailForm( $notice ) {
 607+ if( $this->editable ) {
 608+ $readonly = array();
 609+ } else {
 610+ $readonly = array( 'disabled' => 'disabled' );
 611+ }
575612 $dbr = wfGetDB( DB_SLAVE );
576613
577614 $row = $dbr->selectRow( 'cn_notices',
@@ -622,21 +659,25 @@
623660 array(
624661 wfMsgHtml( 'centralnotice-enabled' ),
625662 Xml::check( 'enabled[]', ( $row->not_enabled == '1' ),
626 - array( 'value' => $row->not_name ) )
 663+ wfArrayMerge( $readonly,
 664+ array( 'value' => $row->not_name ) ) )
627665 ),
628666 // Locked
629667 array(
630668 wfMsgHtml( 'centralnotice-locked' ),
631669 Xml::check( 'locked[]', ( $row->not_locked == '1' ),
632 - array( 'value' => $row->not_name ) ),
 670+ wfArrayMerge( $readonly,
 671+ array( 'value' => $row->not_name ) ) ),
633672 ),
 673+ );
 674+ if( $this->editable ) {
634675 // Remove
635 - array(
 676+ $table[] = array(
636677 wfMsgHtml( 'centralnotice-remove' ),
637678 Xml::check( 'removeNotices[]', false,
638679 array( 'value' => $row->not_name ) )
639 - ),
640 - );
 680+ );
 681+ }
641682 foreach ( $table as $cells ) {
642683 $htmlOut .= $this->tableRow( $cells );
643684 }
@@ -687,9 +728,11 @@
688729 'width' => '100%'
689730 )
690731 );
 732+ if( $this->editable ) {
 733+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
 734+ wfMsg ( "centralnotice-remove" ) );
 735+ }
691736 $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
692 - wfMsg ( "centralnotice-remove" ) );
693 - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
694737 wfMsg ( "centralnotice-weight" ) );
695738 $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '70%' ),
696739 wfMsg ( "centralnotice-templates" ) );
@@ -699,20 +742,16 @@
700743
701744 $htmlOut .= Xml::openElement( 'tr' );
702745
703 - // Remove
704 - $htmlOut .= Xml::tags( 'td', null,
 746+ if( $this->editable ) {
 747+ // Remove
 748+ $htmlOut .= Xml::tags( 'td', null,
705749 Xml::check( 'removeTemplates[]', false, array( 'value' => $row->tmp_name ) )
706 - );
 750+ );
 751+ }
707752
708753 // Weight
709754 $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 )
717756 );
718757
719758 $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate/view' );
@@ -736,6 +775,20 @@
737776 return $htmlOut;
738777
739778 }
 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+ }
740793
741794
742795 function addTemplatesForm( $notice ) {
@@ -1113,38 +1166,57 @@
11141167
11151168 function projectDropDownList( $selected = '' ) {
11161169 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+ }
11221185 }
1123 - $htmlOut .= Xml::closeElement( 'select' );
1124 - return $htmlOut;
11251186 }
11261187
11271188 function languageDropDownList( $selected = '' ) {
11281189 // Language
11291190 list( $lsLabel, $lsSelect ) = Xml::languageSelector( $selected );
11301191
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 );
11371220 }
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 );
11491221 }
11501222
11511223 function getProjectName( $value ) {
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
@@ -27,10 +27,7 @@
2828 $sk = $wgUser->getSkin();
2929
3030 // 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' );
3532
3633 // Show summary
3734 $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ) );
@@ -38,42 +35,44 @@
3936 // Show header
4037 CentralNotice::printHeader();
4138
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+ }
5150 }
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+ }
6362 }
6463 }
6564 }
6665 }
 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+ }
6775 }
6876
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 -
7877 // Handle Editing
7978 if ( $wgRequest->getVal( 'wpMethod' ) == 'editTemplate' ) {
8079 $this->editTemplate(
@@ -89,10 +88,12 @@
9089 return;
9190 }
9291
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+ }
9798 }
9899
99100 // Show list by default
@@ -107,22 +108,28 @@
108109 // Templates
109110 $templates = $this->queryTemplates();
110111 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+ }
117122 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-available-templates' ) );
118123 $htmlOut .= Xml::openElement( 'table',
119124 array(
120125 'cellpadding' => 9,
121126 'width' => '100%'
122127 )
123 - ) ;
124 - $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
125 - wfMsg ( 'centralnotice-remove' )
126128 );
 129+ if( $this->editable ) {
 130+ $htmlOut .= Xml::element( 'th', array( 'align' => 'left', 'width' => '5%' ),
 131+ wfMsg ( 'centralnotice-remove' )
 132+ );
 133+ }
127134 $htmlOut .= Xml::element( 'th', array( 'align' => 'left' ),
128135 wfMsg ( 'centralnotice-template-name' )
129136 );
@@ -132,15 +139,17 @@
133140 $viewPage = SpecialPage::getTitleFor( 'NoticeTemplate/view' );
134141 $htmlOut .= Xml::openElement( 'tr' );
135142
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+ )
142151 )
143 - )
144 - );
 152+ );
 153+ }
145154
146155 // Link and Preview
147156 $render = new SpecialNoticeText();
@@ -157,11 +166,13 @@
158167
159168 $htmlOut .= Xml::closeElement( 'tr' );
160169 }
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+ }
166177 } else {
167178 $htmlOut = Xml::tags( 'tr', null,
168179 Xml::element( 'td', null, wfMsg( 'centralnotice-no-templates' ) )
@@ -169,11 +180,13 @@
170181 }
171182 $htmlOut .= Xml::closeElement( 'table' );
172183 $htmlOut .= Xml::closeElement( 'fieldset' );
173 - $htmlOut .= Xml::closeElement( 'form' );
 184+ if( $this->editable ) {
 185+ $htmlOut .= Xml::closeElement( 'form' );
174186
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+ }
178191
179192 // Output HTML
180193 $wgOut->addHtml( $htmlOut );
@@ -212,6 +225,11 @@
213226 global $wgOut, $wgUser, $wgRequest, $wgContLanguageCode;
214227
215228 $sk = $wgUser->getSkin();
 229+ if( $this->editable ) {
 230+ $readonly = array();
 231+ } else {
 232+ $readonly = array( 'readonly' => 'readonly' );
 233+ }
216234
217235 // Get token
218236 $token = $wgUser->editToken();
@@ -231,7 +249,9 @@
232250 );
233251
234252 // Build HTML
235 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
 253+ if( $this->editable ) {
 254+ $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
 255+ }
236256 $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-translate-heading', $currentTemplate ) );
237257 $htmlOut .= Xml::openElement( 'table',
238258 array (
@@ -301,23 +321,27 @@
302322 }
303323 $htmlOut .= Xml::tags( 'td', null,
304324 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' : '' ) ) )
306327 )
307328 );
308329
309330 $htmlOut .= Xml::closeElement( 'tr' );
310331 }
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+ }
319341 $htmlOut .= Xml::closeElement( 'table' );
320342 $htmlOut .= Xml::closeElement( 'fieldset' );
321 - $htmlOut .= Xml::closeElement( 'form' );
 343+ if( $this->editable ) {
 344+ $htmlOut .= Xml::closeElement( 'form' );
 345+ }
322346
323347 /*
324348 * Show language selection form
@@ -340,9 +364,11 @@
341365 /*
342366 * Show edit form
343367 */
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+ }
345372 $htmlOut .= Xml::fieldset( wfMsgHtml( 'centralnotice-edit-template' ) );
346 - $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' );
347373 $htmlOut .= Xml::openElement( 'table',
348374 array(
349375 'cellpadding' => 9,
@@ -350,14 +376,18 @@
351377 )
352378 );
353379 $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 ) )
355381 );
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+ }
359387 $htmlOut .= Xml::closeElement( 'table' );
360388 $htmlOut .= Xml::closeElement( 'fieldset' );
361 - $htmlOut .= Xml::closeElement( 'form' );
 389+ if( $this->editable ) {
 390+ $htmlOut .= Xml::closeElement( 'form' );
 391+ }
362392
363393 // Output HTML
364394 $wgOut->addHTML( $htmlOut );

Status & tagging log