Index: trunk/extensions/CentralNotice/CentralNotice.php |
— | — | @@ -156,6 +156,7 @@ |
157 | 157 | $base = dirname( __FILE__ ); |
158 | 158 | if ( $wgDBtype == 'mysql' ) { |
159 | 159 | $wgExtNewTables[] = array( 'cn_notices', $base . '/CentralNotice.sql' ); |
| 160 | + $wgExtNewFields[] = array( 'cn_notices', 'not_preferred', $base . '/patches/patch-notice_preferred.sql' ); |
160 | 161 | $wgExtNewTables[] = array( 'cn_notice_languages', $base . '/patches/patch-notice_languages.sql' ); |
161 | 162 | } |
162 | 163 | return true; |
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php |
— | — | @@ -72,16 +72,48 @@ |
73 | 73 | // Handle adding banner |
74 | 74 | // FIXME: getText()? weak comparison |
75 | 75 | if ( $wgRequest->getVal( 'wpMethod' ) == 'addTemplate' ) { |
| 76 | + |
| 77 | + // Handle "Display to anonymous users" checkbox |
| 78 | + $displayAnon = 0; |
| 79 | + if ( $wgRequest->getVal( 'displayAnon' ) ) { |
| 80 | + $displayAnon = $wgRequest->getVal( 'displayAnon' ); |
| 81 | + } |
| 82 | + |
| 83 | + // Handle "Display to logged in users" checkbox |
| 84 | + $displayAccount = 0; |
| 85 | + if ( $wgRequest->getVal( 'displayAccount' ) ) { |
| 86 | + $displayAccount = $wgRequest->getVal( 'displayAccount' ); |
| 87 | + } |
| 88 | + |
76 | 89 | $this->addTemplate( |
77 | 90 | $wgRequest->getVal( 'templateName' ), |
78 | | - $wgRequest->getVal( 'templateBody' ) |
| 91 | + $wgRequest->getVal( 'templateBody' ), |
| 92 | + $displayAnon, |
| 93 | + $displayAccount |
79 | 94 | ); |
80 | 95 | $sub = 'view'; |
81 | 96 | } |
| 97 | + |
| 98 | + // Handle editing banner |
82 | 99 | if ( $wgRequest->getVal( 'wpMethod' ) == 'editTemplate' ) { |
| 100 | + |
| 101 | + // Handle "Display to anonymous users" checkbox |
| 102 | + $displayAnon = 0; |
| 103 | + if ( $wgRequest->getVal( 'displayAnon' ) ) { |
| 104 | + $displayAnon = $wgRequest->getVal( 'displayAnon' ); |
| 105 | + } |
| 106 | + |
| 107 | + // Handle "Display to logged in users" checkbox |
| 108 | + $displayAccount = 0; |
| 109 | + if ( $wgRequest->getVal( 'displayAccount' ) ) { |
| 110 | + $displayAccount = $wgRequest->getVal( 'displayAccount' ); |
| 111 | + } |
| 112 | + |
83 | 113 | $this->editTemplate( |
84 | 114 | $wgRequest->getVal( 'template' ), |
85 | | - $wgRequest->getVal( 'templateBody' ) |
| 115 | + $wgRequest->getVal( 'templateBody' ), |
| 116 | + $displayAnon, |
| 117 | + $displayAccount |
86 | 118 | ); |
87 | 119 | $sub = 'view'; |
88 | 120 | } |
— | — | @@ -194,6 +226,15 @@ |
195 | 227 | $htmlOut .= Xml::tags( 'p', null, |
196 | 228 | Xml::inputLabel( wfMsg( 'centralnotice-banner-name' ) . ":", 'templateName', 'templateName', 25 ) |
197 | 229 | ); |
| 230 | + |
| 231 | + $htmlOut .= Xml::openElement( 'p', null ); |
| 232 | + $htmlOut .= wfMsg( 'centralnotice-banner-display' ); |
| 233 | + $htmlOut .= Xml::check( 'displayAnon', true, array( 'id' => 'displayAnon' ) ); |
| 234 | + $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-anonymous' ), 'displayAnon' ); |
| 235 | + $htmlOut .= Xml::check( 'displayAccount', true, array( 'id' => 'displayAccount' ) ); |
| 236 | + $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-logged-in' ), 'displayAccount' ); |
| 237 | + $htmlOut .= Xml::closeElement( 'p' ); |
| 238 | + |
198 | 239 | $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-banner' ) ); |
199 | 240 | $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' ); |
200 | 241 | $buttons = array(); |
— | — | @@ -231,8 +272,10 @@ |
232 | 273 | |
233 | 274 | if ( $this->editable ) { |
234 | 275 | $readonly = array(); |
| 276 | + $disabled = array(); |
235 | 277 | } else { |
236 | 278 | $readonly = array( 'readonly' => 'readonly' ); |
| 279 | + $disabled = array( 'disabled' => 'disabled' ); |
237 | 280 | } |
238 | 281 | |
239 | 282 | // Get user's language |
— | — | @@ -241,6 +284,17 @@ |
242 | 285 | // Get current banner |
243 | 286 | $currentTemplate = $wgRequest->getText( 'template' ); |
244 | 287 | |
| 288 | + // Pull template settings from database |
| 289 | + $dbr = wfGetDB( DB_SLAVE ); |
| 290 | + $row = $dbr->selectRow( 'cn_templates', |
| 291 | + array( |
| 292 | + 'tmp_display_anon', |
| 293 | + 'tmp_display_account' |
| 294 | + ), |
| 295 | + array( 'tmp_name' => $currentTemplate ), |
| 296 | + __METHOD__ |
| 297 | + ); |
| 298 | + |
245 | 299 | // Begin building HTML |
246 | 300 | $htmlOut = ''; |
247 | 301 | |
— | — | @@ -397,6 +451,18 @@ |
398 | 452 | $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) ); |
399 | 453 | $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' ); |
400 | 454 | } |
| 455 | + |
| 456 | + // FIXME |
| 457 | + $htmlOut .= Xml::fieldset( 'Settings' ); |
| 458 | + $htmlOut .= Xml::openElement( 'p', null ); |
| 459 | + $htmlOut .= wfMsg( 'centralnotice-banner-display' ); |
| 460 | + $htmlOut .= Xml::check( 'displayAnon', ( $row->tmp_display_anon == 1 ), wfArrayMerge( $disabled, array( 'id' => 'displayAnon' ) ) ); |
| 461 | + $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-anonymous' ), 'displayAnon' ); |
| 462 | + $htmlOut .= Xml::check( 'displayAccount', ( $row->tmp_display_account == 1 ), wfArrayMerge( $disabled, array( 'id' => 'displayAccount' ) ) ); |
| 463 | + $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-logged-in' ), 'displayAccount' ); |
| 464 | + $htmlOut .= Xml::closeElement( 'p' ); |
| 465 | + $htmlOut .= Xml::closeElement( 'fieldset' ); |
| 466 | + |
401 | 467 | $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-edit-template' ) ); |
402 | 468 | $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' ); |
403 | 469 | $buttons = array(); |
— | — | @@ -554,7 +620,7 @@ |
555 | 621 | /** |
556 | 622 | * Create a new banner |
557 | 623 | */ |
558 | | - private function addTemplate ( $name, $body ) { |
| 624 | + private function addTemplate( $name, $body, $displayAnon, $displayAccount ) { |
559 | 625 | global $wgOut; |
560 | 626 | |
561 | 627 | if ( $body == '' || $name == '' ) { |
— | — | @@ -579,9 +645,12 @@ |
580 | 646 | } else { |
581 | 647 | $dbw = wfGetDB( DB_MASTER ); |
582 | 648 | $dbw->begin(); |
583 | | - $res = $dbw->insert( |
584 | | - 'cn_templates', |
585 | | - array( 'tmp_name' => $name ), |
| 649 | + $res = $dbw->insert( 'cn_templates', |
| 650 | + array( |
| 651 | + 'tmp_name' => $name, |
| 652 | + 'tmp_display_anon' => $displayAnon, |
| 653 | + 'tmp_display_account' => $displayAccount |
| 654 | + ), |
586 | 655 | __METHOD__ |
587 | 656 | ); |
588 | 657 | $dbw->commit(); |
— | — | @@ -598,7 +667,7 @@ |
599 | 668 | /** |
600 | 669 | * Update a banner |
601 | 670 | */ |
602 | | - private function editTemplate ( $name, $body ) { |
| 671 | + private function editTemplate( $name, $body, $displayAnon, $displayAccount ) { |
603 | 672 | global $wgOut; |
604 | 673 | |
605 | 674 | if ( $body == '' || $name == '' ) { |
— | — | @@ -612,7 +681,18 @@ |
613 | 682 | __METHOD__ |
614 | 683 | ); |
615 | 684 | |
616 | | - if ( $dbr->numRows( $res ) > 0 ) { |
| 685 | + if ( $dbr->numRows( $res ) == 1 ) { |
| 686 | + $dbw = wfGetDB( DB_MASTER ); |
| 687 | + $dbw->begin(); |
| 688 | + $res = $dbw->update( 'cn_templates', |
| 689 | + array( |
| 690 | + 'tmp_display_anon' => $displayAnon, |
| 691 | + 'tmp_display_account' => $displayAccount |
| 692 | + ), |
| 693 | + array( 'tmp_name' => $name ) |
| 694 | + ); |
| 695 | + $dbw->commit(); |
| 696 | + |
617 | 697 | // Perhaps these should move into the db as blob |
618 | 698 | $article = new Article( |
619 | 699 | Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI ) |