From 50d9a5ec18cd1e952433b9ee1f22bf04916d1537 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 22 Jan 2007 20:59:00 +0000 Subject: [PATCH] Further fixes to protection expiry: * Use RFC 2822-style date/time format instead of localized formatting for the expiry time in the protection form; while ugly, it actually works; a localized time is usually lossy (changing the time on submit) and more significantly will fail for any UI language that's not english! * Rearrange some of the form display logic to handle error conditions a little more gracefully; invalid expiry format caused the form to be displayed twice. * Should be nicer on session token expiration as well, showing the form instead of just an exception message. --- includes/Article.php | 2 +- includes/ProtectionForm.php | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index e8c152c6b2..2d7504cc0e 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1634,7 +1634,7 @@ class Article { */ function protect() { $form = new ProtectionForm( $this ); - $form->show(); + $form->execute(); } /** diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index e349fba44b..56eae6e29d 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -49,7 +49,7 @@ class ProtectionForm { } else if ( strlen($this->mTitle->mRestrictionsExpiry) == 0 ) { $this->mExpiry = ''; } else { - $this->mExpiry = $wgLang->timeanddate( $this->mTitle->mRestrictionsExpiry ); + $this->mExpiry = wfTimestamp( TS_RFC2822, $this->mTitle->mRestrictionsExpiry ); } } @@ -70,12 +70,18 @@ class ProtectionForm { $this->mRestrictions[$action] = $val; } } - + } + } + + function execute() { + global $wgRequest; + if( $wgRequest->wasPosted() ) { if( $this->save() ) { global $wgOut; $wgOut->redirect( $this->mTitle->getFullUrl() ); - return; } + } else { + $this->show(); } } @@ -124,17 +130,16 @@ class ProtectionForm { function save() { global $wgRequest, $wgUser, $wgOut; - if( !$wgRequest->wasPosted() ) { - return false; - } - + if( $this->disabled ) { + $this->show(); return false; } $token = $wgRequest->getVal( 'wpEditToken' ); if( !$wgUser->matchEditToken( $token ) ) { - throw new FatalError( wfMsg( 'sessionfailure' ) ); + $this->show( wfMsg( 'sessionfailure' ) ); + return false; } if ( strlen( $this->mExpiry ) == 0 ) { @@ -149,7 +154,7 @@ class ProtectionForm { if ( $expiry < 0 || $expiry === false ) { $this->show( wfMsg( 'protect_expiry_invalid' ) ); - return; + return false; } $expiry = wfTimestamp( TS_MW, $expiry ); -- 2.20.1