Index: trunk/extensions/CodeReview/CodeReview.i18n.php |
— | — | @@ -143,6 +143,26 @@ |
144 | 144 | Commit summary: |
145 | 145 | |
146 | 146 | $4', |
| 147 | + |
| 148 | + 'codereview-email-subj3' => '[$1] [$2]: Revision status changed', |
| 149 | + 'codereview-email-body3' => 'User "$1" changed the status of $2. |
| 150 | + |
| 151 | +Old Status: $3 |
| 152 | +New Status: $4', |
| 153 | + |
| 154 | + 'codereview-email-subj4' => '[$1] [$2]: New comment added, and revision status changed', |
| 155 | + 'codereview-email-body4' => 'User "$1" changed the status of $2. |
| 156 | + |
| 157 | +Old Status: $3 |
| 158 | +New Status: $4 |
| 159 | + |
| 160 | +User "$1" also posted a comment on $2. |
| 161 | + |
| 162 | +Full URL: $5 |
| 163 | + |
| 164 | +Comment: |
| 165 | + |
| 166 | +$6', |
147 | 167 | |
148 | 168 | 'code-stats' => 'statistics', |
149 | 169 | 'code-stats-header' => 'Statistics for repository $1', |
Index: trunk/extensions/CodeReview/backend/CodeRevision.php |
— | — | @@ -12,6 +12,7 @@ |
13 | 13 | $rev->mMessage = rtrim( $data['msg'] ); |
14 | 14 | $rev->mPaths = $data['paths']; |
15 | 15 | $rev->mStatus = 'new'; |
| 16 | + $rev->mOldStatus = ''; |
16 | 17 | |
17 | 18 | $common = null; |
18 | 19 | if ( $rev->mPaths ) { |
— | — | @@ -71,6 +72,7 @@ |
72 | 73 | $rev->mTimestamp = wfTimestamp( TS_MW, $row->cr_timestamp ); |
73 | 74 | $rev->mMessage = $row->cr_message; |
74 | 75 | $rev->mStatus = $row->cr_status; |
| 76 | + $rev->mOldStatus = ''; |
75 | 77 | $rev->mCommonPath = $row->cr_path; |
76 | 78 | return $rev; |
77 | 79 | } |
— | — | @@ -147,12 +149,12 @@ |
148 | 150 | } |
149 | 151 | // Get the old status from the master |
150 | 152 | $dbw = wfGetDB( DB_MASTER ); |
151 | | - $oldStatus = $dbw->selectField( 'code_rev', |
| 153 | + $this->moldStatus = $dbw->selectField( 'code_rev', |
152 | 154 | 'cr_status', |
153 | 155 | array( 'cr_repo_id' => $this->mRepoId, 'cr_id' => $this->mId ), |
154 | 156 | __METHOD__ |
155 | 157 | ); |
156 | | - if ( $oldStatus === $status ) { |
| 158 | + if ( $this->moldStatus === $status ) { |
157 | 159 | return false; // nothing to do here |
158 | 160 | } |
159 | 161 | // Update status |
— | — | @@ -171,7 +173,7 @@ |
172 | 174 | 'cpc_repo_id' => $this->getRepoId(), |
173 | 175 | 'cpc_rev_id' => $this->getId(), |
174 | 176 | 'cpc_attrib' => 'status', |
175 | | - 'cpc_removed' => $oldStatus, |
| 177 | + 'cpc_removed' => $this->moldStatus, |
176 | 178 | 'cpc_added' => $status, |
177 | 179 | 'cpc_timestamp' => $dbw->timestamp(), |
178 | 180 | 'cpc_user' => $user->getId(), |
— | — | @@ -181,7 +183,7 @@ |
182 | 184 | ); |
183 | 185 | } |
184 | 186 | |
185 | | - $this->sendStatusToUDP( $status, $oldStatus ); |
| 187 | + $this->sendStatusToUDP( $status, $this->moldStatus ); |
186 | 188 | |
187 | 189 | return true; |
188 | 190 | } |
— | — | @@ -399,7 +401,6 @@ |
400 | 402 | } |
401 | 403 | |
402 | 404 | public function saveComment( $text, $review, $parent = null ) { |
403 | | - global $wgUser; |
404 | 405 | $text = trim( $text ); |
405 | 406 | if ( !strlen( $text ) ) { |
406 | 407 | return 0; |
— | — | @@ -413,47 +414,61 @@ |
414 | 415 | $commentId = $dbw->insertId(); |
415 | 416 | $dbw->commit(); |
416 | 417 | |
| 418 | + $url = $this->getFullUrl( $commentId ); |
| 419 | + |
| 420 | + $this->sendCommentToUDP( $commentId, $text, $url ); |
| 421 | + |
| 422 | + return $commentId; |
| 423 | + } |
| 424 | + |
| 425 | + /** |
| 426 | + * @param $subject |
| 427 | + * @param $body |
| 428 | + * @return void |
| 429 | + */ |
| 430 | + public function emailNotifyUsersOfChanges( $subject, $body ) { |
417 | 431 | // Give email notices to committer and commenters |
418 | | - global $wgCodeReviewENotif, $wgEnableEmail, $wgCodeReviewCommentWatcher; |
419 | | - if ( $wgCodeReviewENotif && $wgEnableEmail ) { |
420 | | - // Make list of users to send emails to |
421 | | - $users = $this->getCommentingUsers(); |
422 | | - if ( $user = $this->getWikiUser() ) { |
423 | | - $users[$user->getId()] = $user; |
424 | | - } |
425 | | - // If we've got a spam list, send e-mails to it too |
426 | | - if ( $wgCodeReviewCommentWatcher ) { |
427 | | - $watcher = new User(); |
428 | | - $watcher->setEmail( $wgCodeReviewCommentWatcher ); |
429 | | - $users[0] = $watcher; // We don't have any anons, so using 0 is safe |
430 | | - } |
431 | | - // Get repo and build comment title (for url) |
432 | | - $url = $this->getFullUrl( $commentId ); |
| 432 | + global $wgCodeReviewENotif, $wgEnableEmail, $wgCodeReviewCommentWatcher, |
| 433 | + $wgUser; |
| 434 | + if ( !$wgCodeReviewENotif && !$wgEnableEmail ) { |
| 435 | + return; |
| 436 | + } |
433 | 437 | |
434 | | - foreach ( $users as $userId => $user ) { |
435 | | - // Notify user with its own message if he already want |
436 | | - // to be CCed of all emails it sends. |
437 | | - if ( $wgUser->getId() == $user->getId() ) { |
438 | | - if(! $user->getBoolOption( 'ccmeonemails' ) ) { |
439 | | - continue; |
440 | | - } |
441 | | - } |
| 438 | + $args = func_get_args(); |
| 439 | + array_shift( $args ); //Drop $subject |
| 440 | + array_shift( $args ); //Drop $body |
442 | 441 | |
443 | | - if ( $user->canReceiveEmail() ) { |
444 | | - // Send message in receiver's language |
445 | | - $lang = array( 'language' => $user->getOption( 'language' ) ); |
446 | | - |
447 | | - $user->sendMail( |
448 | | - wfMsgExt( 'codereview-email-subj', $lang, $this->mRepo->getName(), $this->getIdString() ), |
449 | | - wfMsgExt( 'codereview-email-body', $lang, $wgUser->getName(), $url, $this->getIdStringUnique(), $text ) |
450 | | - ); |
| 442 | + // Make list of users to send emails to |
| 443 | + $users = $this->getCommentingUsers(); |
| 444 | + if ( $user = $this->getWikiUser() ) { |
| 445 | + $users[$user->getId()] = $user; |
| 446 | + } |
| 447 | + // If we've got a spam list, send e-mails to it too |
| 448 | + if ( $wgCodeReviewCommentWatcher ) { |
| 449 | + $watcher = new User(); |
| 450 | + $watcher->setEmail( $wgCodeReviewCommentWatcher ); |
| 451 | + $users[0] = $watcher; // We don't have any anons, so using 0 is safe |
| 452 | + } |
| 453 | + |
| 454 | + foreach ( $users as $user ) { |
| 455 | + // Notify user with its own message if he already want |
| 456 | + // to be CCed of all emails it sends. |
| 457 | + if ( $wgUser->getId() == $user->getId() ) { |
| 458 | + if(! $user->getBoolOption( 'ccmeonemails' ) ) { |
| 459 | + continue; |
451 | 460 | } |
452 | 461 | } |
453 | | - } |
454 | 462 | |
455 | | - $this->sendCommentToUDP( $commentId, $text, $url ); |
| 463 | + if ( $user->canReceiveEmail() ) { |
| 464 | + // Send message in receiver's language |
| 465 | + $lang = array( 'language' => $user->getOption( 'language' ) ); |
456 | 466 | |
457 | | - return $commentId; |
| 467 | + $localSubject = wfMsgExt( $subject, $lang, $this->mRepo->getName(), $this->getIdString() ); |
| 468 | + $localBody = call_user_func_array( 'wfMsgExt', array_merge( array( $body, $lang, $wgUser->getName() ), $args ) ); |
| 469 | + |
| 470 | + $user->sendMail( $localSubject, $localBody ); |
| 471 | + } |
| 472 | + } |
458 | 473 | } |
459 | 474 | |
460 | 475 | protected function commentData( $text, $review, $parent = null ) { |
Index: trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php |
— | — | @@ -25,8 +25,9 @@ |
26 | 26 | |
27 | 27 | $dbw->begin(); |
28 | 28 | // Change the status if allowed |
| 29 | + $statusChanged = false; |
29 | 30 | if ( $this->validPost( 'codereview-set-status' ) && $this->mRev->isValidStatus( $this->mStatus ) ) { |
30 | | - $this->mRev->setStatus( $this->mStatus, $wgUser ); |
| 31 | + $statusChanged = $this->mRev->setStatus( $this->mStatus, $wgUser ); |
31 | 32 | } |
32 | 33 | $addTags = $removeTags = array(); |
33 | 34 | if ( $this->validPost( 'codereview-add-tag' ) && count( $this->mAddTags ) ) { |
— | — | @@ -40,18 +41,40 @@ |
41 | 42 | $this->mRev->changeTags( $addTags, $removeTags, $wgUser ); |
42 | 43 | } |
43 | 44 | // Add any comments |
| 45 | + $commentAdded = false; |
44 | 46 | if ( $this->validPost( 'codereview-post-comment' ) && strlen( $this->text ) ) { |
45 | 47 | $parent = $wgRequest->getIntOrNull( 'wpParent' ); |
46 | 48 | $review = $wgRequest->getInt( 'wpReview' ); |
47 | 49 | // $isPreview = $wgRequest->getCheck( 'wpPreview' ); |
48 | | - $id = $this->mRev->saveComment( $this->text, $review, $parent ); |
| 50 | + $commentId = $this->mRev->saveComment( $this->text, $review, $parent ); |
| 51 | + |
| 52 | + $commentAdded = ($commentId !== 0); |
| 53 | + |
49 | 54 | // For comments, take us back to the rev page focused on the new comment |
50 | 55 | if ( !$this->jumpToNext ) { |
51 | | - $redirTarget = $this->commentLink( $id ); |
| 56 | + $redirTarget = $this->commentLink( $commentId ); |
52 | 57 | } |
53 | 58 | } |
54 | 59 | $dbw->commit(); |
55 | 60 | |
| 61 | + if ( $statusChanged || $commentAdded ) { |
| 62 | + if ( $statusChanged && $commentAdded ) { |
| 63 | + $url = $this->mRev->getFullUrl( $commentId ); |
| 64 | + $this->mRev->emailNotifyUsersOfChanges( 'codereview-email-subj4', 'codereview-email-body4', |
| 65 | + $wgUser->getName(), $this->mRev->getIdStringUnique(), $this->mRev->mOldStatus, $this->mRev->mStatus, |
| 66 | + $url, $this->text |
| 67 | + ); |
| 68 | + } else if ( $statusChanged ) { |
| 69 | + $this->mRev->emailNotifyUsersOfChanges( 'codereview-email-subj3', 'codereview-email-body3', |
| 70 | + $wgUser->getName(), $this->mRev->getIdStringUnique(), $this->mRev->mOldStatus, $this->mRev->mStatus |
| 71 | + ); |
| 72 | + } else if ( $commentAdded ) { |
| 73 | + $url = $this->mRev->getFullUrl( $commentId ); |
| 74 | + $this->mRev->emailNotifyUsersOfChanges( 'codereview-email-subj', 'codereview-email-body', |
| 75 | + $wgUser->getName(), $url, $this->mRev->getIdStringUnique(), $this->text ); |
| 76 | + } |
| 77 | + } |
| 78 | + |
56 | 79 | // Return to rev page |
57 | 80 | if ( !$redirTarget ) { |
58 | 81 | // Was "next & unresolved" clicked? |