http://www.mediawiki.org/wiki/Special:Code/MediaWiki/71996
Revision: 71996
Author: kaldari
Date: 2010-08-31 00:27:12 +0000 (Tue, 31 Aug 2010)
Log Message:
-----------
redoing how errors are handled for Post/Redirect/Get (fix for r71832), removing
extra whitespace
Modified Paths:
--------------
trunk/extensions/CentralNotice/SpecialCentralNotice.php
trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
Modified: trunk/extensions/CentralNotice/SpecialCentralNotice.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-08-31
00:11:49 UTC (rev 71995)
+++ trunk/extensions/CentralNotice/SpecialCentralNotice.php 2010-08-31
00:27:12 UTC (rev 71996)
@@ -6,9 +6,8 @@
}
class CentralNotice extends SpecialPage {
- var $centralNoticeDB;
- /* Functions */
-
+ var $centralNoticeDB, $editable, $centralNoticeError;
+
function __construct() {
// Register special page
parent::__construct( 'CentralNotice' );
@@ -36,6 +35,9 @@
// Check permissions
$this->editable = $wgUser->isAllowed( 'centralnotice-admin' );
+
+ // Initialize error variable
+ $this->centralNoticeError = false;
// Show summary
$wgOut->addWikiText( wfMsg( 'centralnotice-summary' ) );
@@ -70,7 +72,7 @@
$this->removeNotice( $notice );
}
- // Show list of campaigns
+ // Skip subsequent form handling and
show list of campaigns
$this->listNotices();
$wgOut->addHTML( Xml::closeElement(
'div' ) );
return;
@@ -146,14 +148,20 @@
$project_name =
$wgRequest->getVal( 'project_name' );
$project_languages =
$wgRequest->getArray( 'project_languages' );
if ( $noticeName == '' ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-null-string' );
+ $this->showError(
'centralnotice-null-string' );
} else {
$this->addNotice( $noticeName,
'0', $start, $project_name, $project_languages );
}
}
-
+
+ // If there were no errors, reload the page to
prevent duplicate form submission
+ if ( !$this->centralNoticeError ) {
+ $wgOut->redirect(
$this->getTitle()->getLocalUrl() );
+ return;
+ }
+
} else {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'sessionfailure' );
+ $this->showError( 'sessionfailure' );
}
}
@@ -521,7 +529,7 @@
// Make sure notice exists
if ( !$this->noticeExists( $notice ) ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-notice-doesnt-exist' );
+ $this->showError( 'centralnotice-notice-doesnt-exist' );
} else {
// Handle form submissions from campaign detail
interface
@@ -533,10 +541,11 @@
// Handle removing campaign
if ( $wgRequest->getVal( 'remove' ) ) {
$this->removeNotice( $notice );
-
- // Leave campaign detail
interface
- $wgOut->redirect(
$this->getTitle()->getLocalUrl() );
- return;
+ if ( !$this->centralNoticeError
) {
+ // Leave campaign
detail interface
+ $wgOut->redirect(
$this->getTitle()->getLocalUrl() );
+ return;
+ }
}
// Handle locking/unlocking campaign
@@ -615,8 +624,13 @@
$this->updateProjectLanguages(
$notice, $projectLangs );
}
+ // If there were no errors, reload the
page to prevent duplicate form submission
+ if ( !$this->centralNoticeError ) {
+ $wgOut->redirect(
$this->getTitle()->getLocalUrl( "method=listNoticeDetail¬ice=$notice" ) );
+ return;
+ }
} else {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'sessionfailure' );
+ $this->showError( 'sessionfailure' );
}
}
@@ -983,10 +997,10 @@
global $wgOut;
if ( $this->noticeExists( $noticeName ) ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-notice-exists' );
+ $this->showError( 'centralnotice-notice-exists' );
return;
} elseif ( empty( $project_languages ) ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-no-language' );
+ $this->showError( 'centralnotice-no-language' );
return;
} else {
$dbw = wfGetDB( DB_MASTER );
@@ -1036,22 +1050,22 @@
array( 'not_name' => $noticeName )
);
if ( $dbr->numRows( $res ) < 1 ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-remove-notice-doesnt-exist' );
- return;
+ $this->showError(
'centralnotice-remove-notice-doesnt-exist' );
+ return;
}
$row = $dbr->fetchObject( $res );
if ( $row->not_locked == '1' ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-notice-is-locked' );
- return;
+ $this->showError( 'centralnotice-notice-is-locked' );
+ return;
} else {
- $dbw = wfGetDB( DB_MASTER );
- $dbw->begin();
- $noticeId = htmlspecialchars( $this->getNoticeId(
$noticeName ) );
- $res = $dbw->delete( 'cn_assignments', array (
'not_id' => $noticeId ) );
- $res = $dbw->delete( 'cn_notices', array ( 'not_name'
=> $noticeName ) );
- $res = $dbw->delete( 'cn_notice_languages', array (
'nl_notice_id' => $noticeId ) );
- $dbw->commit();
- return;
+ $dbw = wfGetDB( DB_MASTER );
+ $dbw->begin();
+ $noticeId = htmlspecialchars( $this->getNoticeId(
$noticeName ) );
+ $res = $dbw->delete( 'cn_assignments', array (
'not_id' => $noticeId ) );
+ $res = $dbw->delete( 'cn_notices', array ( 'not_name'
=> $noticeName ) );
+ $res = $dbw->delete( 'cn_notice_languages', array (
'nl_notice_id' => $noticeId ) );
+ $dbw->commit();
+ return;
}
}
@@ -1070,7 +1084,7 @@
)
);
if ( $dbr->numRows( $res ) > 0 ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-template-already-exists' );
+ $this->showError(
'centralnotice-template-already-exists' );
} else {
$dbw = wfGetDB( DB_MASTER );
$dbw->begin();
@@ -1146,13 +1160,13 @@
// Start/end don't line up
if ( $start > $end || $end < $start ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-invalid-date-range' );
+ $this->showError( 'centralnotice-invalid-date-range' );
return;
}
// Invalid campaign name
if ( !$this->noticeExists( $noticeName ) ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-notice-doesnt-exist' );
+ $this->showError( 'centralnotice-notice-doesnt-exist' );
return;
}
@@ -1177,7 +1191,7 @@
global $wgOut;
if ( !$this->noticeExists( $noticeName ) ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
+ $this->showError( 'centralnotice-doesnt-exist' );
} else {
$dbw = wfGetDB( DB_MASTER );
$res = $dbw->update( 'cn_notices',
@@ -1194,7 +1208,7 @@
global $wgOut;
if ( !$this->noticeExists( $noticeName ) ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
+ $this->showError( 'centralnotice-doesnt-exist' );
} else {
$dbw = wfGetDB( DB_MASTER );
$res = $dbw->update( 'cn_notices',
@@ -1211,7 +1225,7 @@
global $wgOut;
if ( !$this->noticeExists( $noticeName ) ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-doesnt-exist' );
+ $this->showError( 'centralnotice-doesnt-exist' );
} else {
$dbw = wfGetDB( DB_MASTER );
$res = $dbw->update( 'cn_notices',
@@ -1370,6 +1384,12 @@
}
return $text;
}
+
+ function showError( $message ) {
+ global $wgOut;
+ $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>",
$message );
+ $this->centralNoticeError = true;
+ }
}
Modified: trunk/extensions/CentralNotice/SpecialNoticeTemplate.php
===================================================================
--- trunk/extensions/CentralNotice/SpecialNoticeTemplate.php 2010-08-31
00:11:49 UTC (rev 71995)
+++ trunk/extensions/CentralNotice/SpecialNoticeTemplate.php 2010-08-31
00:27:12 UTC (rev 71996)
@@ -6,7 +6,7 @@
}
class SpecialNoticeTemplate extends UnlistedSpecialPage {
- var $editable;
+ var $editable, $centralNoticeError;
function __construct() {
parent::__construct( 'NoticeTemplate' );
@@ -32,6 +32,9 @@
// Check permissions
$this->editable = $wgUser->isAllowed( 'centralnotice-admin' );
+
+ // Initialize error variable
+ $this->centralNoticeError = false;
// Show summary
$wgOut->addWikiMsg( 'centralnotice-summary' );
@@ -86,7 +89,7 @@
);
$sub = 'view';
} else {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-null-string' );
+ $this->showError(
'centralnotice-null-string' );
}
}
@@ -102,7 +105,7 @@
}
} else {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'sessionfailure' );
+ $this->showError( 'sessionfailure' );
}
}
@@ -144,7 +147,7 @@
return;
} else {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'sessionfailure' );
+ $this->showError( 'sessionfailure' );
}
}
@@ -612,7 +615,7 @@
$res = $dbr->select( 'cn_assignments', 'asn_id', array(
'tmp_id' => $id ), __METHOD__ );
if ( $dbr->numRows( $res ) > 0 ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-template-still-bound' );
+ $this->showError( 'centralnotice-template-still-bound'
);
return;
} else {
$dbw = wfGetDB( DB_MASTER );
@@ -637,7 +640,7 @@
global $wgOut;
if ( $body == '' || $name == '' ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-null-string' );
+ $this->showError( 'centralnotice-null-string' );
return;
}
@@ -653,7 +656,7 @@
);
if ( $dbr->numRows( $res ) > 0 ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-template-exists' );
+ $this->showError( 'centralnotice-template-exists' );
return false;
} else {
$dbw = wfGetDB( DB_MASTER );
@@ -682,7 +685,7 @@
global $wgOut;
if ( $body == '' || $name == '' ) {
- $wgOut->wrapWikiMsg( "<div
class='cn-error'>\n$1\n</div>", 'centralnotice-null-string' );
+ $this->showError( 'centralnotice-null-string' );
return;
}
@@ -805,4 +808,10 @@
}
return $translations;
}
+
+ function showError( $message ) {
+ global $wgOut;
+ $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>",
$message );
+ $this->centralNoticeError = true;
+ }
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs