jenkins-bot has submitted this change and it was merged.

Change subject: Simplified doEditContent exception handling
......................................................................


Simplified doEditContent exception handling

* Callers should not catch errors and fail to rollback
  changes as much here as anywhere else

Change-Id: I65cbeb8d0895223b7ad60c9081d703d14197cb4a
---
M includes/page/WikiPage.php
1 file changed, 107 insertions(+), 114 deletions(-)

Approvals:
  Gilles: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 8ef3063..64dd99d 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -1692,6 +1692,7 @@
         *     revision: The revision object for the inserted revision, or null.
         *
         * @since 1.21
+        * @throws MWException
         */
        public function doEditContent( Content $content, $summary, $flags = 0, 
$baseRevId = false,
                User $user = null, $serialFormat = null
@@ -1803,56 +1804,52 @@
 
                        if ( $changed ) {
                                $dbw->begin( __METHOD__ );
-                               try {
 
-                                       $prepStatus = $content->prepareSave( 
$this, $flags, $oldid, $user );
-                                       $status->merge( $prepStatus );
+                               $prepStatus = $content->prepareSave( $this, 
$flags, $oldid, $user );
+                               $status->merge( $prepStatus );
 
-                                       if ( !$status->isOK() ) {
-                                               $dbw->rollback( __METHOD__ );
-
-                                               return $status;
-                                       }
-                                       $revisionId = $revision->insertOn( $dbw 
);
-
-                                       // Update page
-                                       //
-                                       // We check for conflicts by comparing 
$oldid with the current latest revision ID.
-                                       $ok = $this->updateRevisionOn( $dbw, 
$revision, $oldid, $oldIsRedirect );
-
-                                       if ( !$ok ) {
-                                               // Belated edit conflict! Run 
away!!
-                                               $status->fatal( 'edit-conflict' 
);
-
-                                               $dbw->rollback( __METHOD__ );
-
-                                               return $status;
-                                       }
-
-                                       Hooks::run( 
'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
-                                       // Update recentchanges
-                                       if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
-                                               // Mark as patrolled if the 
user can do so
-                                               $patrolled = $wgUseRCPatrol && 
!count(
-                                               
$this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
-                                               // Add RC row to the DB
-                                               $rc = RecentChange::notifyEdit( 
$now, $this->mTitle, $isminor, $user, $summary,
-                                                       $oldid, 
$this->getTimestamp(), $bot, '', $oldsize, $newsize,
-                                                       $revisionId, $patrolled
-                                               );
-
-                                               // Log auto-patrolled edits
-                                               if ( $patrolled ) {
-                                                       PatrolLog::record( $rc, 
true, $user );
-                                               }
-                                       }
-                                       $user->incEditCount();
-                               } catch ( Exception $e ) {
+                               if ( !$status->isOK() ) {
                                        $dbw->rollback( __METHOD__ );
-                                       // Question: Would it perhaps be better 
if this method turned all
-                                       // exceptions into $status's?
-                                       throw $e;
+
+                                       return $status;
                                }
+                               $revisionId = $revision->insertOn( $dbw );
+
+                               // Update page
+                               //
+                               // We check for conflicts by comparing $oldid 
with the current latest revision ID.
+                               $ok = $this->updateRevisionOn( $dbw, $revision, 
$oldid, $oldIsRedirect );
+
+                               if ( !$ok ) {
+                                       // Belated edit conflict! Run away!!
+                                       $status->fatal( 'edit-conflict' );
+
+                                       $dbw->rollback( __METHOD__ );
+
+                                       return $status;
+                               }
+
+                               Hooks::run( 'NewRevisionFromEditComplete', 
array( $this, $revision, $baseRevId, $user ) );
+
+                               // Update recentchanges
+                               if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
+                                       // Mark as patrolled if the user can do 
so
+                                       $patrolled = $wgUseRCPatrol && !count(
+                                       
$this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
+                                       // Add RC row to the DB
+                                       $rc = RecentChange::notifyEdit( $now, 
$this->mTitle, $isminor, $user, $summary,
+                                               $oldid, $this->getTimestamp(), 
$bot, '', $oldsize, $newsize,
+                                               $revisionId, $patrolled
+                                       );
+
+                                       // Log auto-patrolled edits
+                                       if ( $patrolled ) {
+                                               PatrolLog::record( $rc, true, 
$user );
+                                       }
+                               }
+
+                               $user->incEditCount();
+
                                $dbw->commit( __METHOD__ );
                        } else {
                                // Bug 32948: revision ID must be set to page 
{{REVISIONID}} and
@@ -1882,78 +1879,74 @@
                        $status->value['new'] = true;
 
                        $dbw->begin( __METHOD__ );
-                       try {
 
-                               $prepStatus = $content->prepareSave( $this, 
$flags, $oldid, $user );
-                               $status->merge( $prepStatus );
+                       $prepStatus = $content->prepareSave( $this, $flags, 
$oldid, $user );
+                       $status->merge( $prepStatus );
 
-                               if ( !$status->isOK() ) {
-                                       $dbw->rollback( __METHOD__ );
-
-                                       return $status;
-                               }
-
-                               $status->merge( $prepStatus );
-
-                               // Add the page record; stake our claim on this 
title!
-                               // This will return false if the article 
already exists
-                               $newid = $this->insertOn( $dbw );
-
-                               if ( $newid === false ) {
-                                       $dbw->rollback( __METHOD__ );
-                                       $status->fatal( 'edit-already-exists' );
-
-                                       return $status;
-                               }
-
-                               // Save the revision text...
-                               $revision = new Revision( array(
-                                       'page'       => $newid,
-                                       'title'      => $this->getTitle(), // 
for determining the default content model
-                                       'comment'    => $summary,
-                                       'minor_edit' => $isminor,
-                                       'text'       => $serialized,
-                                       'len'        => $newsize,
-                                       'user'       => $user->getId(),
-                                       'user_text'  => $user->getName(),
-                                       'timestamp'  => $now,
-                                       'content_model' => $content->getModel(),
-                                       'content_format' => $serialFormat,
-                               ) );
-                               $revisionId = $revision->insertOn( $dbw );
-
-                               // Bug 37225: use accessor to get the text as 
Revision may trim it
-                               $content = $revision->getContent(); // sanity; 
get normalized version
-
-                               if ( $content ) {
-                                       $newsize = $content->getSize();
-                               }
-
-                               // Update the page record with revision data
-                               $this->updateRevisionOn( $dbw, $revision, 0 );
-
-                               Hooks::run( 'NewRevisionFromEditComplete', 
array( $this, $revision, false, $user ) );
-
-                               // Update recentchanges
-                               if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
-                                       // Mark as patrolled if the user can do 
so
-                                       $patrolled = ( $wgUseRCPatrol || 
$wgUseNPPatrol ) && !count(
-                                               
$this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
-                                       // Add RC row to the DB
-                                       $rc = RecentChange::notifyNew( $now, 
$this->mTitle, $isminor, $user, $summary, $bot,
-                                               '', $newsize, $revisionId, 
$patrolled );
-
-                                       // Log auto-patrolled edits
-                                       if ( $patrolled ) {
-                                               PatrolLog::record( $rc, true, 
$user );
-                                       }
-                               }
-                               $user->incEditCount();
-
-                       } catch ( Exception $e ) {
+                       if ( !$status->isOK() ) {
                                $dbw->rollback( __METHOD__ );
-                               throw $e;
+
+                               return $status;
                        }
+
+                       $status->merge( $prepStatus );
+
+                       // Add the page record; stake our claim on this title!
+                       // This will return false if the article already exists
+                       $newid = $this->insertOn( $dbw );
+
+                       if ( $newid === false ) {
+                               $dbw->rollback( __METHOD__ );
+                               $status->fatal( 'edit-already-exists' );
+
+                               return $status;
+                       }
+
+                       // Save the revision text...
+                       $revision = new Revision( array(
+                               'page'       => $newid,
+                               'title'      => $this->getTitle(), // for 
determining the default content model
+                               'comment'    => $summary,
+                               'minor_edit' => $isminor,
+                               'text'       => $serialized,
+                               'len'        => $newsize,
+                               'user'       => $user->getId(),
+                               'user_text'  => $user->getName(),
+                               'timestamp'  => $now,
+                               'content_model' => $content->getModel(),
+                               'content_format' => $serialFormat,
+                       ) );
+                       $revisionId = $revision->insertOn( $dbw );
+
+                       // Bug 37225: use accessor to get the text as Revision 
may trim it
+                       $content = $revision->getContent(); // sanity; get 
normalized version
+
+                       if ( $content ) {
+                               $newsize = $content->getSize();
+                       }
+
+                       // Update the page record with revision data
+                       $this->updateRevisionOn( $dbw, $revision, 0 );
+
+                       Hooks::run( 'NewRevisionFromEditComplete', array( 
$this, $revision, false, $user ) );
+
+                       // Update recentchanges
+                       if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
+                               // Mark as patrolled if the user can do so
+                               $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol 
) && !count(
+                                       
$this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
+                               // Add RC row to the DB
+                               $rc = RecentChange::notifyNew( $now, 
$this->mTitle, $isminor, $user, $summary, $bot,
+                                       '', $newsize, $revisionId, $patrolled );
+
+                               // Log auto-patrolled edits
+                               if ( $patrolled ) {
+                                       PatrolLog::record( $rc, true, $user );
+                               }
+                       }
+
+                       $user->incEditCount();
+
                        $dbw->commit( __METHOD__ );
 
                        // Update links, etc.

-- 
To view, visit https://gerrit.wikimedia.org/r/212197
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I65cbeb8d0895223b7ad60c9081d703d14197cb4a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Gilles <gdu...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to