Index: trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php |
— | — | @@ -20,37 +20,80 @@ |
21 | 21 | return; |
22 | 22 | } |
23 | 23 | |
| 24 | + $redirTarget = $this->doRevisionUpdate( $this->mStatus, $this->mAddTags, $this->mRemoveTags, |
| 25 | + $this->mSignoffFlags, $this->text, $wgRequest->getIntOrNull( 'wpParent' ), |
| 26 | + $wgRequest->getInt( 'wpReview' ) |
| 27 | + ); |
| 28 | + |
| 29 | + // Return to rev page |
| 30 | + if ( !$redirTarget ) { |
| 31 | + // Was "next & unresolved" clicked? |
| 32 | + if ( $this->jumpToNext ) { |
| 33 | + $next = $this->mRev->getNextUnresolved( $this->mPath ); |
| 34 | + if ( $next ) { |
| 35 | + $redirTarget = SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() . '/' . $next ); |
| 36 | + } else { |
| 37 | + $redirTarget = SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() ); |
| 38 | + } |
| 39 | + } else { |
| 40 | + # $redirTarget already set for comments |
| 41 | + $redirTarget = $this->revLink(); |
| 42 | + } |
| 43 | + } |
| 44 | + $wgOut->redirect( $redirTarget->getFullUrl( array( 'path' => $this->mPath ) ) ); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Does the revision database update |
| 49 | + * |
| 50 | + * @param string $status Status to set the revision to |
| 51 | + * @param Array $addTags Tags to add to the revision |
| 52 | + * @param Array $removeTags Tags to remove from the Revision |
| 53 | + * @param Array $signoffFlags |
| 54 | + * @param string $commentText Comment to add to the revision |
| 55 | + * @param null|int $parent What the parent comment is (if a subcomment) |
| 56 | + * @param int $review (unused) |
| 57 | + * @return null|bool|Title False if not a valid rev. Title for redirect target, else null |
| 58 | + */ |
| 59 | + public function doRevisionUpdate( $status, $addTags, $removeTags, $signoffFlags, $commentText, $parent = null, |
| 60 | + $review = 0 ) { |
| 61 | + |
| 62 | + if ( !$this->mRev ) { |
| 63 | + return false; |
| 64 | + } |
| 65 | + |
| 66 | + global $wgUser; |
| 67 | + |
24 | 68 | $redirTarget = null; |
| 69 | + |
25 | 70 | $dbw = wfGetDB( DB_MASTER ); |
26 | 71 | |
27 | 72 | $dbw->begin(); |
28 | 73 | // Change the status if allowed |
29 | 74 | $statusChanged = false; |
30 | | - if ( $this->validPost( 'codereview-set-status' ) && $this->mRev->isValidStatus( $this->mStatus ) ) { |
31 | | - $statusChanged = $this->mRev->setStatus( $this->mStatus, $wgUser ); |
| 75 | + if ( $this->validPost( 'codereview-set-status' ) && $this->mRev->isValidStatus( $status ) ) { |
| 76 | + $statusChanged = $this->mRev->setStatus( $status, $wgUser ); |
32 | 77 | } |
33 | 78 | $addTags = $removeTags = array(); |
34 | | - if ( $this->validPost( 'codereview-add-tag' ) && count( $this->mAddTags ) ) { |
35 | | - $addTags = $this->mAddTags; |
| 79 | + if ( $this->validPost( 'codereview-add-tag' ) && count( $addTags ) ) { |
| 80 | + $validAddTags = $addTags; |
36 | 81 | } |
37 | | - if ( $this->validPost( 'codereview-remove-tag' ) && count( $this->mRemoveTags ) ) { |
38 | | - $removeTags = $this->mRemoveTags; |
| 82 | + if ( $this->validPost( 'codereview-remove-tag' ) && count( $removeTags ) ) { |
| 83 | + $validRemoveTags = $removeTags; |
39 | 84 | } |
40 | 85 | // If allowed to change any tags, then do so |
41 | | - if ( count( $addTags ) || count( $removeTags ) ) { |
42 | | - $this->mRev->changeTags( $addTags, $removeTags, $wgUser ); |
| 86 | + if ( count( $validAddTags ) || count( $validRemoveTags ) ) { |
| 87 | + $this->mRev->changeTags( $validAddTags, $validRemoveTags, $wgUser ); |
43 | 88 | } |
44 | 89 | // Add any signoffs |
45 | | - if ( $this->validPost( 'codereview-signoff' ) && count( $this->mSignoffFlags ) ) { |
46 | | - $this->mRev->addSignoff( $wgUser, $this->mSignoffFlags ); |
| 90 | + if ( $this->validPost( 'codereview-signoff' ) && count( $signoffFlags ) ) { |
| 91 | + $this->mRev->addSignoff( $wgUser, $signoffFlags ); |
47 | 92 | } |
48 | 93 | // Add any comments |
49 | 94 | $commentAdded = false; |
50 | | - if ( $this->validPost( 'codereview-post-comment' ) && strlen( $this->text ) ) { |
51 | | - $parent = $wgRequest->getIntOrNull( 'wpParent' ); |
52 | | - $review = $wgRequest->getInt( 'wpReview' ); |
| 95 | + if ( $this->validPost( 'codereview-post-comment' ) && strlen( $commentText ) ) { |
53 | 96 | // $isPreview = $wgRequest->getCheck( 'wpPreview' ); |
54 | | - $commentId = $this->mRev->saveComment( $this->text, $review, $parent ); |
| 97 | + $commentId = $this->mRev->saveComment( $commentText, $review, $parent ); |
55 | 98 | |
56 | 99 | $commentAdded = ($commentId !== 0); |
57 | 100 | |
— | — | @@ -80,22 +123,7 @@ |
81 | 124 | } |
82 | 125 | } |
83 | 126 | |
84 | | - // Return to rev page |
85 | | - if ( !$redirTarget ) { |
86 | | - // Was "next & unresolved" clicked? |
87 | | - if ( $this->jumpToNext ) { |
88 | | - $next = $this->mRev->getNextUnresolved( $this->mPath ); |
89 | | - if ( $next ) { |
90 | | - $redirTarget = SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() . '/' . $next ); |
91 | | - } else { |
92 | | - $redirTarget = SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() ); |
93 | | - } |
94 | | - } else { |
95 | | - # $redirTarget already set for comments |
96 | | - $redirTarget = $this->revLink(); |
97 | | - } |
98 | | - } |
99 | | - $wgOut->redirect( $redirTarget->getFullUrl( array( 'path' => $this->mPath ) ) ); |
| 127 | + return $redirTarget; |
100 | 128 | } |
101 | 129 | |
102 | 130 | public function validPost( $permission ) { |