Further fixes to protection expiry:
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 22 Jan 2007 20:59:00 +0000 (20:59 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 22 Jan 2007 20:59:00 +0000 (20:59 +0000)
* 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
includes/ProtectionForm.php

index e8c152c..2d7504c 100644 (file)
@@ -1634,7 +1634,7 @@ class Article {
         */
        function protect() {
                $form = new ProtectionForm( $this );
-               $form->show();
+               $form->execute();
        }
 
        /**
index e349fba..56eae6e 100644 (file)
@@ -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 );