r71996 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71995‎ | r71996 | r71997 >
Date:00:27, 31 August 2010
Author:kaldari
Status:ok
Tags:
Comment:
redoing how errors are handled for Post/Redirect/Get (fix for r71832), removing extra whitespace
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialCentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialCentralNotice.php
@@ -6,9 +6,8 @@
77 }
88
99 class CentralNotice extends SpecialPage {
10 - var $centralNoticeDB;
11 - /* Functions */
12 -
 10+ var $centralNoticeDB, $editable, $centralNoticeError;
 11+
1312 function __construct() {
1413 // Register special page
1514 parent::__construct( 'CentralNotice' );
@@ -36,6 +35,9 @@
3736
3837 // Check permissions
3938 $this->editable = $wgUser->isAllowed( 'centralnotice-admin' );
 39+
 40+ // Initialize error variable
 41+ $this->centralNoticeError = false;
4042
4143 // Show summary
4244 $wgOut->addWikiText( wfMsg( 'centralnotice-summary' ) );
@@ -70,7 +72,7 @@
7173 $this->removeNotice( $notice );
7274 }
7375
74 - // Show list of campaigns
 76+ // Skip subsequent form handling and show list of campaigns
7577 $this->listNotices();
7678 $wgOut->addHTML( Xml::closeElement( 'div' ) );
7779 return;
@@ -146,14 +148,20 @@
147149 $project_name = $wgRequest->getVal( 'project_name' );
148150 $project_languages = $wgRequest->getArray( 'project_languages' );
149151 if ( $noticeName == '' ) {
150 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-null-string' );
 152+ $this->showError( 'centralnotice-null-string' );
151153 } else {
152154 $this->addNotice( $noticeName, '0', $start, $project_name, $project_languages );
153155 }
154156 }
155 -
 157+
 158+ // If there were no errors, reload the page to prevent duplicate form submission
 159+ if ( !$this->centralNoticeError ) {
 160+ $wgOut->redirect( $this->getTitle()->getLocalUrl() );
 161+ return;
 162+ }
 163+
156164 } else {
157 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'sessionfailure' );
 165+ $this->showError( 'sessionfailure' );
158166 }
159167
160168 }
@@ -521,7 +529,7 @@
522530
523531 // Make sure notice exists
524532 if ( !$this->noticeExists( $notice ) ) {
525 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-doesnt-exist' );
 533+ $this->showError( 'centralnotice-notice-doesnt-exist' );
526534 } else {
527535
528536 // Handle form submissions from campaign detail interface
@@ -533,10 +541,11 @@
534542 // Handle removing campaign
535543 if ( $wgRequest->getVal( 'remove' ) ) {
536544 $this->removeNotice( $notice );
537 -
538 - // Leave campaign detail interface
539 - $wgOut->redirect( $this->getTitle()->getLocalUrl() );
540 - return;
 545+ if ( !$this->centralNoticeError ) {
 546+ // Leave campaign detail interface
 547+ $wgOut->redirect( $this->getTitle()->getLocalUrl() );
 548+ return;
 549+ }
541550 }
542551
543552 // Handle locking/unlocking campaign
@@ -615,8 +624,13 @@
616625 $this->updateProjectLanguages( $notice, $projectLangs );
617626 }
618627
 628+ // If there were no errors, reload the page to prevent duplicate form submission
 629+ if ( !$this->centralNoticeError ) {
 630+ $wgOut->redirect( $this->getTitle()->getLocalUrl( "method=listNoticeDetail&notice=$notice" ) );
 631+ return;
 632+ }
619633 } else {
620 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'sessionfailure' );
 634+ $this->showError( 'sessionfailure' );
621635 }
622636
623637 }
@@ -983,10 +997,10 @@
984998 global $wgOut;
985999
9861000 if ( $this->noticeExists( $noticeName ) ) {
987 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-exists' );
 1001+ $this->showError( 'centralnotice-notice-exists' );
9881002 return;
9891003 } elseif ( empty( $project_languages ) ) {
990 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-no-language' );
 1004+ $this->showError( 'centralnotice-no-language' );
9911005 return;
9921006 } else {
9931007 $dbw = wfGetDB( DB_MASTER );
@@ -1036,22 +1050,22 @@
10371051 array( 'not_name' => $noticeName )
10381052 );
10391053 if ( $dbr->numRows( $res ) < 1 ) {
1040 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-remove-notice-doesnt-exist' );
1041 - return;
 1054+ $this->showError( 'centralnotice-remove-notice-doesnt-exist' );
 1055+ return;
10421056 }
10431057 $row = $dbr->fetchObject( $res );
10441058 if ( $row->not_locked == '1' ) {
1045 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-is-locked' );
1046 - return;
 1059+ $this->showError( 'centralnotice-notice-is-locked' );
 1060+ return;
10471061 } else {
1048 - $dbw = wfGetDB( DB_MASTER );
1049 - $dbw->begin();
1050 - $noticeId = htmlspecialchars( $this->getNoticeId( $noticeName ) );
1051 - $res = $dbw->delete( 'cn_assignments', array ( 'not_id' => $noticeId ) );
1052 - $res = $dbw->delete( 'cn_notices', array ( 'not_name' => $noticeName ) );
1053 - $res = $dbw->delete( 'cn_notice_languages', array ( 'nl_notice_id' => $noticeId ) );
1054 - $dbw->commit();
1055 - return;
 1062+ $dbw = wfGetDB( DB_MASTER );
 1063+ $dbw->begin();
 1064+ $noticeId = htmlspecialchars( $this->getNoticeId( $noticeName ) );
 1065+ $res = $dbw->delete( 'cn_assignments', array ( 'not_id' => $noticeId ) );
 1066+ $res = $dbw->delete( 'cn_notices', array ( 'not_name' => $noticeName ) );
 1067+ $res = $dbw->delete( 'cn_notice_languages', array ( 'nl_notice_id' => $noticeId ) );
 1068+ $dbw->commit();
 1069+ return;
10561070 }
10571071 }
10581072
@@ -1070,7 +1084,7 @@
10711085 )
10721086 );
10731087 if ( $dbr->numRows( $res ) > 0 ) {
1074 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-template-already-exists' );
 1088+ $this->showError( 'centralnotice-template-already-exists' );
10751089 } else {
10761090 $dbw = wfGetDB( DB_MASTER );
10771091 $dbw->begin();
@@ -1146,13 +1160,13 @@
11471161
11481162 // Start/end don't line up
11491163 if ( $start > $end || $end < $start ) {
1150 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-invalid-date-range' );
 1164+ $this->showError( 'centralnotice-invalid-date-range' );
11511165 return;
11521166 }
11531167
11541168 // Invalid campaign name
11551169 if ( !$this->noticeExists( $noticeName ) ) {
1156 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-notice-doesnt-exist' );
 1170+ $this->showError( 'centralnotice-notice-doesnt-exist' );
11571171 return;
11581172 }
11591173
@@ -1177,7 +1191,7 @@
11781192 global $wgOut;
11791193
11801194 if ( !$this->noticeExists( $noticeName ) ) {
1181 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
 1195+ $this->showError( 'centralnotice-doesnt-exist' );
11821196 } else {
11831197 $dbw = wfGetDB( DB_MASTER );
11841198 $res = $dbw->update( 'cn_notices',
@@ -1194,7 +1208,7 @@
11951209 global $wgOut;
11961210
11971211 if ( !$this->noticeExists( $noticeName ) ) {
1198 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
 1212+ $this->showError( 'centralnotice-doesnt-exist' );
11991213 } else {
12001214 $dbw = wfGetDB( DB_MASTER );
12011215 $res = $dbw->update( 'cn_notices',
@@ -1211,7 +1225,7 @@
12121226 global $wgOut;
12131227
12141228 if ( !$this->noticeExists( $noticeName ) ) {
1215 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
 1229+ $this->showError( 'centralnotice-doesnt-exist' );
12161230 } else {
12171231 $dbw = wfGetDB( DB_MASTER );
12181232 $res = $dbw->update( 'cn_notices',
@@ -1370,6 +1384,12 @@
13711385 }
13721386 return $text;
13731387 }
 1388+
 1389+ function showError( $message ) {
 1390+ global $wgOut;
 1391+ $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", $message );
 1392+ $this->centralNoticeError = true;
 1393+ }
13741394 }
13751395
13761396
Index: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
@@ -6,7 +6,7 @@
77 }
88
99 class SpecialNoticeTemplate extends UnlistedSpecialPage {
10 - var $editable;
 10+ var $editable, $centralNoticeError;
1111
1212 function __construct() {
1313 parent::__construct( 'NoticeTemplate' );
@@ -32,6 +32,9 @@
3333
3434 // Check permissions
3535 $this->editable = $wgUser->isAllowed( 'centralnotice-admin' );
 36+
 37+ // Initialize error variable
 38+ $this->centralNoticeError = false;
3639
3740 // Show summary
3841 $wgOut->addWikiMsg( 'centralnotice-summary' );
@@ -86,7 +89,7 @@
8790 );
8891 $sub = 'view';
8992 } else {
90 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-null-string' );
 93+ $this->showError( 'centralnotice-null-string' );
9194 }
9295 }
9396
@@ -102,7 +105,7 @@
103106 }
104107
105108 } else {
106 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'sessionfailure' );
 109+ $this->showError( 'sessionfailure' );
107110 }
108111
109112 }
@@ -144,7 +147,7 @@
145148 return;
146149
147150 } else {
148 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'sessionfailure' );
 151+ $this->showError( 'sessionfailure' );
149152 }
150153
151154 }
@@ -612,7 +615,7 @@
613616 $res = $dbr->select( 'cn_assignments', 'asn_id', array( 'tmp_id' => $id ), __METHOD__ );
614617
615618 if ( $dbr->numRows( $res ) > 0 ) {
616 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-template-still-bound' );
 619+ $this->showError( 'centralnotice-template-still-bound' );
617620 return;
618621 } else {
619622 $dbw = wfGetDB( DB_MASTER );
@@ -637,7 +640,7 @@
638641 global $wgOut;
639642
640643 if ( $body == '' || $name == '' ) {
641 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-null-string' );
 644+ $this->showError( 'centralnotice-null-string' );
642645 return;
643646 }
644647
@@ -653,7 +656,7 @@
654657 );
655658
656659 if ( $dbr->numRows( $res ) > 0 ) {
657 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-template-exists' );
 660+ $this->showError( 'centralnotice-template-exists' );
658661 return false;
659662 } else {
660663 $dbw = wfGetDB( DB_MASTER );
@@ -682,7 +685,7 @@
683686 global $wgOut;
684687
685688 if ( $body == '' || $name == '' ) {
686 - $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", 'centralnotice-null-string' );
 689+ $this->showError( 'centralnotice-null-string' );
687690 return;
688691 }
689692
@@ -805,4 +808,10 @@
806809 }
807810 return $translations;
808811 }
 812+
 813+ function showError( $message ) {
 814+ global $wgOut;
 815+ $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", $message );
 816+ $this->centralNoticeError = true;
 817+ }
809818 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r71832moving wasPosted() test inside notice existance testkaldari00:38, 28 August 2010

Status & tagging log