r42194 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42193‎ | r42194 | r42195 >
Date:04:06, 18 October 2008
Author:aaron
Status:old (Comments)
Tags:
Comment:
Send email notification to committer/other commentors on comment
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.i18n.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevision.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRevision.php
@@ -4,7 +4,7 @@
55 class CodeRevision {
66 static function newFromSvn( CodeRepository $repo, $data ) {
77 $rev = new CodeRevision();
8 - $rev->mRepo = $repo->getId();
 8+ $rev->mRepo = CodeRepository::newFromId( $repo->getId() );
99 $rev->mId = intval($data['rev']);
1010 $rev->mAuthor = $data['author'];
1111 $rev->mTimestamp = wfTimestamp( TS_MW, strtotime( $data['date'] ) );
@@ -45,7 +45,7 @@
4646
4747 static function newFromRow( $row ) {
4848 $rev = new CodeRevision();
49 - $rev->mRepo = intval($row->cr_repo_id);
 49+ $rev->mRepo = CodeRepository::newFromId( intval($row->cr_repo_id) );
5050 $rev->mId = intval($row->cr_id);
5151 $rev->mAuthor = $row->cr_author;
5252 $rev->mTimestamp = wfTimestamp( TS_MW, $row->cr_timestamp );
@@ -62,6 +62,14 @@
6363 function getAuthor() {
6464 return $this->mAuthor;
6565 }
 66+
 67+ function getRepo() {
 68+ return $this->mRepo;
 69+ }
 70+
 71+ function getWikiUser() {
 72+ return $this->mRepo->authorWikiUser( $this->getAuthor() );
 73+ }
6674
6775 function getTimestamp() {
6876 return $this->mTimestamp;
@@ -98,7 +106,7 @@
99107 $dbw->update( 'code_rev',
100108 array( 'cr_status' => $status ),
101109 array(
102 - 'cr_repo_id' => $this->mRepo,
 110+ 'cr_repo_id' => $this->mRepo->getId(),
103111 'cr_id' => $this->mId ),
104112 __METHOD__ );
105113 }
@@ -109,7 +117,7 @@
110118
111119 $dbw->insert( 'code_rev',
112120 array(
113 - 'cr_repo_id' => $this->mRepo,
 121+ 'cr_repo_id' => $this->mRepo->getId(),
114122 'cr_id' => $this->mId,
115123 'cr_author' => $this->mAuthor,
116124 'cr_timestamp' => $dbw->timestamp( $this->mTimestamp ),
@@ -127,16 +135,16 @@
128136 'cr_message' => $this->mMessage,
129137 'cr_path' => $this->mCommonPath ),
130138 array(
131 - 'cr_repo_id' => $this->mRepo,
 139+ 'cr_repo_id' => $this->mRepo->getId(),
132140 'cr_id' => $this->mId ),
133141 __METHOD__ );
134142 }
135 -
 143+ // Update path tracking used for output and searching
136144 if( $this->mPaths ) {
137145 $data = array();
138146 foreach( $this->mPaths as $path ) {
139147 $data[] = array(
140 - 'cp_repo_id' => $this->mRepo,
 148+ 'cp_repo_id' => $this->mRepo->getId(),
141149 'cp_rev_id' => $this->mId,
142150 'cp_path' => $path['path'],
143151 'cp_action' => $path['action'] );
@@ -155,7 +163,8 @@
156164 return $dbr->select(
157165 'code_paths',
158166 array( 'cp_path', 'cp_action' ),
159 - array( 'cp_repo_id' => $this->mRepo, 'cp_rev_id' => $this->mId ),
 167+ array( 'cp_repo_id' => $this->mRepo->getId(),
 168+ 'cp_rev_id' => $this->mId ),
160169 __METHOD__
161170 );
162171 }
@@ -175,17 +184,47 @@
176185 }
177186
178187 function saveComment( $text, $review, $parent=null ) {
 188+ global $wgUser;
179189 if( !strlen($text) ) {
180190 return 0;
181191 }
182192 $dbw = wfGetDB( DB_MASTER );
183193 $data = $this->commentData( $text, $review, $parent );
 194+
 195+ $dbw->begin();
184196 $data['cc_id'] = $dbw->nextSequenceValue( 'code_comment_cc_id' );
185 - $dbw->insert( 'code_comment',
186 - $data,
187 - __METHOD__ );
 197+ $dbw->insert( 'code_comment', $data, __METHOD__ );
 198+ $commentId = $dbw->insertId();
 199+ $dbw->commit();
 200+
 201+ // Give email notices to committer and commentors
 202+ global $wgCodeReviewENotif, $wgEnableEmail;
 203+ if( $wgCodeReviewENotif && $wgEnableEmail ) {
 204+ // Make list of users to send emails to
 205+ $users = $this->getCommentingUsers();
 206+ if( $user = $this->getWikiUser() ) {
 207+ $users[$user->getId()] = $user;
 208+ }
 209+ // Get repo and build comment title (for url)
 210+ $title = SpecialPage::getTitleFor( 'Code', $this->mRepo->getName().'/'.$this->mId );
 211+ $title->setFragment( "#c{$commentId}" );
 212+ $url = $title->getFullUrl();
 213+ $preview = htmlspecialchars($text);
 214+ foreach( $users as $userId => $user ) {
 215+ // No sense in notifying this commentor
 216+ if( $wgUser->getId() == $user->getId() ) {
 217+ continue;
 218+ }
 219+ if( $user->canReceiveEmail() ) {
 220+ $user->sendMail(
 221+ wfMsg( 'codereview-email-subj', $repo->getName(), $this->mId ),
 222+ wfMsg( 'codereview-email-body', $wgUser->getName(), $url, $this->mId, $preview )
 223+ );
 224+ }
 225+ }
 226+ }
188227
189 - return $dbw->insertId();
 228+ return $commentId;
190229 }
191230
192231 protected function commentData( $text, $review, $parent=null ) {
@@ -194,7 +233,7 @@
195234 $ts = wfTimestamp( TS_MW );
196235 $sortkey = $this->threadedSortkey( $parent, $ts );
197236 return array(
198 - 'cc_repo_id' => $this->mRepo,
 237+ 'cc_repo_id' => $this->mRepo->getId(),
199238 'cc_rev_id' => $this->mId,
200239 'cc_text' => $text,
201240 'cc_parent' => $parent,
@@ -238,7 +277,7 @@
239278 'cc_review',
240279 'cc_sortkey' ),
241280 array(
242 - 'cc_repo_id' => $this->mRepo,
 281+ 'cc_repo_id' => $this->mRepo->getId(),
243282 'cc_rev_id' => $this->mId ),
244283 __METHOD__,
245284 array(
@@ -252,12 +291,30 @@
253292 return $comments;
254293 }
255294
 295+ function getCommentingUsers() {
 296+ $dbr = wfGetDB( DB_SLAVE );
 297+ $res = $dbr->select( 'code_comment',
 298+ 'DISTINCT(cc_user)',
 299+ array(
 300+ 'cc_repo_id' => $this->mRepo->getId(),
 301+ 'cc_rev_id' => $this->mId,
 302+ 'cc_user != 0' // users only
 303+ ),
 304+ __METHOD__
 305+ );
 306+ $users = array();
 307+ while( $row = $res->fetchObject() ) {
 308+ $users[$row->cc_user] = User::newFromId( $row->cc_user );
 309+ }
 310+ return $users;
 311+ }
 312+
256313 function getTags() {
257314 $dbr = wfGetDB( DB_SLAVE );
258315 $result = $dbr->select( 'code_tags',
259316 array( 'ct_tag' ),
260317 array(
261 - 'ct_repo_id' => $this->mRepo,
 318+ 'ct_repo_id' => $this->mRepo->getId(),
262319 'ct_rev_id' => $this->mId ),
263320 __METHOD__ );
264321
@@ -284,7 +341,7 @@
285342 }
286343 $result = $dbw->delete( 'code_tags',
287344 array(
288 - 'ct_repo_id' => $this->mRepo,
 345+ 'ct_repo_id' => $this->mRepo->getId(),
289346 'ct_rev_id' => $this->mId,
290347 'ct_tag' => $tagsNormal ),
291348 __METHOD__ );
@@ -294,7 +351,7 @@
295352 $data = array();
296353 foreach( $tags as $tag ) {
297354 $data[] = array(
298 - 'ct_repo_id' => $this->mRepo,
 355+ 'ct_repo_id' => $this->mRepo->getId(),
299356 'ct_rev_id' => $this->mId,
300357 'ct_tag' => $this->normalizeTag( $tag ) );
301358 }
@@ -332,7 +389,7 @@
333390 $row = $dbr->selectRow( 'code_rev',
334391 'cr_id',
335392 array(
336 - 'cr_repo_id' => $this->mRepo,
 393+ 'cr_repo_id' => $this->mRepo->getId(),
337394 "cr_id > $encId" ),
338395 __METHOD__,
339396 array(
@@ -352,7 +409,7 @@
353410 $row = $dbr->selectRow( 'code_rev',
354411 'cr_id',
355412 array(
356 - 'cr_repo_id' => $this->mRepo,
 413+ 'cr_repo_id' => $this->mRepo->getId(),
357414 "cr_id > $encId",
358415 'cr_status' => array('new','fixme') ),
359416 __METHOD__,
Index: trunk/extensions/CodeReview/CodeReview.php
@@ -99,3 +99,4 @@
100100 // The name of a repo which represents the code running on this wiki, used to highlight active revisions
101101 $wgWikiSVN = 'MediaWiki';
102102
 103+$wgCodeReviewENotif = true;
Index: trunk/extensions/CodeReview/CodeReview.i18n.php
@@ -74,6 +74,11 @@
7575 'code-rev-submit-next' => 'Commit & next unresolved',
7676
7777 'codereview-reply-link' => 'reply',
 78+
 79+ 'codereview-email-subj' => '[$1] [r$2]: New comment added',
 80+ 'codereview-email-body' => 'User <b>$1</b> posted the <a href="$2">following comment</a> on r$3:
 81+
 82+$4',
7883
7984 'repoadmin' => 'Repository Administration',
8085 'repoadmin-new-legend' => 'Create a new repository',

Follow-up revisions

RevisionCommit summaryAuthorDate
r42239Back out r42193/r42194 for now "Add newFromId()" and "Send email notification...brion00:20, 20 October 2008

Comments

#Comment by Brion VIBBER (talk | contribs)   00:22, 20 October 2008

Reverted in r42239 -- along with r42193 this adds weird, unnecessary reloading of repository information on every creation of a revision object.

The htmlspecialchars() around the comment text in the email message seems a little odd also.

Status & tagging log