r70908 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70907‎ | r70908 | r70909 >
Date:18:54, 11 August 2010
Author:kaldari
Status:resolved
Tags:
Comment:
adding patch-notice_preferred.sql to update hook per comment at r68758
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/CentralNotice.php
@@ -156,6 +156,7 @@
157157 $base = dirname( __FILE__ );
158158 if ( $wgDBtype == 'mysql' ) {
159159 $wgExtNewTables[] = array( 'cn_notices', $base . '/CentralNotice.sql' );
 160+ $wgExtNewFields[] = array( 'cn_notices', 'not_preferred', $base . '/patches/patch-notice_preferred.sql' );
160161 $wgExtNewTables[] = array( 'cn_notice_languages', $base . '/patches/patch-notice_languages.sql' );
161162 }
162163 return true;
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
@@ -72,16 +72,48 @@
7373 // Handle adding banner
7474 // FIXME: getText()? weak comparison
7575 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+
7689 $this->addTemplate(
7790 $wgRequest->getVal( 'templateName' ),
78 - $wgRequest->getVal( 'templateBody' )
 91+ $wgRequest->getVal( 'templateBody' ),
 92+ $displayAnon,
 93+ $displayAccount
7994 );
8095 $sub = 'view';
8196 }
 97+
 98+ // Handle editing banner
8299 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+
83113 $this->editTemplate(
84114 $wgRequest->getVal( 'template' ),
85 - $wgRequest->getVal( 'templateBody' )
 115+ $wgRequest->getVal( 'templateBody' ),
 116+ $displayAnon,
 117+ $displayAccount
86118 );
87119 $sub = 'view';
88120 }
@@ -194,6 +226,15 @@
195227 $htmlOut .= Xml::tags( 'p', null,
196228 Xml::inputLabel( wfMsg( 'centralnotice-banner-name' ) . ":", 'templateName', 'templateName', 25 )
197229 );
 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+
198239 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-banner' ) );
199240 $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' );
200241 $buttons = array();
@@ -231,8 +272,10 @@
232273
233274 if ( $this->editable ) {
234275 $readonly = array();
 276+ $disabled = array();
235277 } else {
236278 $readonly = array( 'readonly' => 'readonly' );
 279+ $disabled = array( 'disabled' => 'disabled' );
237280 }
238281
239282 // Get user's language
@@ -241,6 +284,17 @@
242285 // Get current banner
243286 $currentTemplate = $wgRequest->getText( 'template' );
244287
 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+
245299 // Begin building HTML
246300 $htmlOut = '';
247301
@@ -397,6 +451,18 @@
398452 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
399453 $htmlOut .= Xml::hidden( 'wpMethod', 'editTemplate' );
400454 }
 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+
401467 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-edit-template' ) );
402468 $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' );
403469 $buttons = array();
@@ -554,7 +620,7 @@
555621 /**
556622 * Create a new banner
557623 */
558 - private function addTemplate ( $name, $body ) {
 624+ private function addTemplate( $name, $body, $displayAnon, $displayAccount ) {
559625 global $wgOut;
560626
561627 if ( $body == '' || $name == '' ) {
@@ -579,9 +645,12 @@
580646 } else {
581647 $dbw = wfGetDB( DB_MASTER );
582648 $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+ ),
586655 __METHOD__
587656 );
588657 $dbw->commit();
@@ -598,7 +667,7 @@
599668 /**
600669 * Update a banner
601670 */
602 - private function editTemplate ( $name, $body ) {
 671+ private function editTemplate( $name, $body, $displayAnon, $displayAccount ) {
603672 global $wgOut;
604673
605674 if ( $body == '' || $name == '' ) {
@@ -612,7 +681,18 @@
613682 __METHOD__
614683 );
615684
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+
617697 // Perhaps these should move into the db as blob
618698 $article = new Article(
619699 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )

Follow-up revisions

RevisionCommit summaryAuthorDate
r70910rolling back premature commit of SpecialNoticeTemplate.php in r70908kaldari18:58, 11 August 2010
r71282missing global var in r70908kaldari00:54, 19 August 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68758adding SQL patch support for auto-updatingkaldari01:32, 30 June 2010

Status & tagging log