Fix error display on failing rollback
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 27 Aug 2012 19:40:03 +0000 (21:40 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Mon, 27 Aug 2012 19:40:03 +0000 (21:40 +0200)
Rollback will now show the actual errors that caused it to fail,
instead of a misleading message about permissions.

Also, errores returned by WikiPage::doEditContent are now propagated
and shown.

Change-Id: I5a3f8cb7a0b881d07d52f63504dd3757192205a9

includes/WikiPage.php
includes/actions/RollbackAction.php

index a4afda7..96ff8b7 100644 (file)
@@ -2746,6 +2746,11 @@ class WikiPage extends Page implements IDBAccessObject {
 
                # Actually store the edit
                $status = $this->doEditContent( $target->getContent(), $summary, $flags, $target->getId(), $guser );
+
+               if ( !$status->isOK() ) {
+                       return $status->getErrorsArray();
+               }
+
                if ( !empty( $status->value['revision'] ) ) {
                        $revId = $status->value['revision']->getId();
                } else {
index 5ee6786..abe44fa 100644 (file)
@@ -71,25 +71,18 @@ class RollbackAction extends FormlessAction {
                        return;
                }
 
-               # Display permissions errors before read-only message -- there's no
-               # point in misleading the user into thinking the inability to rollback
-               # is only temporary.
-               if ( !empty( $result ) && $result !== array( array( 'readonlytext' ) ) ) {
-                       # array_diff is completely broken for arrays of arrays, sigh.
-                       # Remove any 'readonlytext' error manually.
-                       $out = array();
-                       foreach ( $result as $error ) {
-                               if ( $error != array( 'readonlytext' ) ) {
-                                       $out [] = $error;
-                               }
-                       }
-                       throw new PermissionsError( 'rollback', $out );
-               }
+               #NOTE: Permission errors already handled by Action::checkExecute.
 
                if ( $result == array( array( 'readonlytext' ) ) ) {
                        throw new ReadOnlyError;
                }
 
+               #XXX: Would be nice if ErrorPageError could take multiple errors, and/or a status object.
+               #     Right now, we only show the first error
+               foreach ( $result as $error ) {
+                       throw new ErrorPageError( 'rollbackfailed', $error[0], array_slice( $error, 1 ) );
+               }
+
                $current = $details['current'];
                $target = $details['target'];
                $newId = $details['newid'];