r76905 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76904‎ | r76905 | r76906 >
Date:21:01, 17 November 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Prequisite to bug 25940 (Add API module(s) to add comments/set revision status)

Functioning out the actual revision update stuff so it can be used without doing an actual display against a page
Modified paths:
  • /trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php
@@ -20,37 +20,80 @@
2121 return;
2222 }
2323
 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+
2468 $redirTarget = null;
 69+
2570 $dbw = wfGetDB( DB_MASTER );
2671
2772 $dbw->begin();
2873 // Change the status if allowed
2974 $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 );
3277 }
3378 $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;
3681 }
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;
3984 }
4085 // 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 );
4388 }
4489 // 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 );
4792 }
4893 // Add any comments
4994 $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 ) ) {
5396 // $isPreview = $wgRequest->getCheck( 'wpPreview' );
54 - $commentId = $this->mRev->saveComment( $this->text, $review, $parent );
 97+ $commentId = $this->mRev->saveComment( $commentText, $review, $parent );
5598
5699 $commentAdded = ($commentId !== 0);
57100
@@ -80,22 +123,7 @@
81124 }
82125 }
83126
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;
100128 }
101129
102130 public function validPost( $permission ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r76912More for bug 25940 (Add API module(s) to add comments/set revision status)...reedy22:45, 17 November 2010
r76920Fix minor refactoring bug from r76905, actually use values passed inreedy23:36, 17 November 2010
r76922bug 25940 Add API module(s) to add comments/set revision status...reedy00:00, 18 November 2010
r76930bug 25940 Add API module(s) to add comments/set revision status...reedy00:42, 18 November 2010
r76944Followup r76905. Return comment ID rather than redirect logic layer specifics...reedy11:45, 18 November 2010

Comments

#Comment by Reedy (talk | contribs)   22:09, 17 November 2010

Needs a bit of further work to tidy up permissions...

#Comment by Bryan (talk | contribs)   11:13, 18 November 2010

You should move the $redirTarget logic entirely out of doRevisionUpdate, as it is purely interface logic.

Any specific reasons the function is called doUpdateRevision() instead of updateRevision()?

#Comment by Reedy (talk | contribs)   11:37, 18 November 2010

Nope, naming was purely what to came to mind firstly

Status & tagging log