r42243 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42242‎ | r42243 | r42244 >
Date:00:42, 20 October 2008
Author:aaron
Status:old (Comments)
Tags:
Comment:
Revert rest of r42239 - redo with delayed repo query and some minor fixes
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
@@ -5,6 +5,7 @@
66 static function newFromSvn( CodeRepository $repo, $data ) {
77 $rev = new CodeRevision();
88 $rev->mRepoId = $repo->getId();
 9+ $rev->mRepo = $repo;
910 $rev->mId = intval($data['rev']);
1011 $rev->mAuthor = $data['author'];
1112 $rev->mTimestamp = wfTimestamp( TS_MW, strtotime( $data['date'] ) );
@@ -46,6 +47,7 @@
4748 static function newFromRow( $row ) {
4849 $rev = new CodeRevision();
4950 $rev->mRepoId = intval($row->cr_repo_id);
 51+ $rev->mRepo = NULL;
5052 $rev->mId = intval($row->cr_id);
5153 $rev->mAuthor = $row->cr_author;
5254 $rev->mTimestamp = wfTimestamp( TS_MW, $row->cr_timestamp );
@@ -58,10 +60,25 @@
5961 function getId() {
6062 return intval( $this->mId );
6163 }
 64+
 65+ function getRepoId() {
 66+ return intval( $this->mRepoId );
 67+ }
6268
6369 function getAuthor() {
6470 return $this->mAuthor;
6571 }
 72+
 73+ function getRepo() {
 74+ if( !isset($this->mRepo) ) {
 75+ $this->mRepo = CodeRepository::newFromId( $this->mRepoId );
 76+ }
 77+ return $this->mRepo;
 78+ }
 79+
 80+ function getWikiUser() {
 81+ return $this->getRepo()->authorWikiUser( $this->getAuthor() );
 82+ }
6683
6784 function getTimestamp() {
6885 return $this->mTimestamp;
@@ -131,7 +148,7 @@
132149 'cr_id' => $this->mId ),
133150 __METHOD__ );
134151 }
135 -
 152+ // Update path tracking used for output and searching
136153 if( $this->mPaths ) {
137154 $data = array();
138155 foreach( $this->mPaths as $path ) {
@@ -175,17 +192,46 @@
176193 }
177194
178195 function saveComment( $text, $review, $parent=null ) {
 196+ global $wgUser;
179197 if( !strlen($text) ) {
180198 return 0;
181199 }
182200 $dbw = wfGetDB( DB_MASTER );
183201 $data = $this->commentData( $text, $review, $parent );
 202+
 203+ $dbw->begin();
184204 $data['cc_id'] = $dbw->nextSequenceValue( 'code_comment_cc_id' );
185 - $dbw->insert( 'code_comment',
186 - $data,
187 - __METHOD__ );
 205+ $dbw->insert( 'code_comment', $data, __METHOD__ );
 206+ $commentId = $dbw->insertId();
 207+ $dbw->commit();
 208+
 209+ // Give email notices to committer and commentors
 210+ global $wgCodeReviewENotif, $wgEnableEmail;
 211+ if( $wgCodeReviewENotif && $wgEnableEmail ) {
 212+ // Make list of users to send emails to
 213+ $users = $this->getCommentingUsers();
 214+ if( $user = $this->getWikiUser() ) {
 215+ $users[$user->getId()] = $user;
 216+ }
 217+ // Get repo and build comment title (for url)
 218+ $title = SpecialPage::getTitleFor( 'Code', $this->getRepo()->getName().'/'.$this->mId );
 219+ $title->setFragment( "#c{$commentId}" );
 220+ $url = $title->getFullUrl();
 221+ foreach( $users as $userId => $user ) {
 222+ // No sense in notifying this commentor
 223+ if( $wgUser->getId() == $user->getId() ) {
 224+ continue;
 225+ }
 226+ if( $user->canReceiveEmail() ) {
 227+ $user->sendMail(
 228+ wfMsg( 'codereview-email-subj', $this->getRepo()->getName(), $this->mId ),
 229+ wfMsg( 'codereview-email-body', $wgUser->getName(), $url, $this->mId, $text )
 230+ );
 231+ }
 232+ }
 233+ }
188234
189 - return $dbw->insertId();
 235+ return $commentId;
190236 }
191237
192238 protected function commentData( $text, $review, $parent=null ) {
@@ -252,6 +298,24 @@
253299 return $comments;
254300 }
255301
 302+ function getCommentingUsers() {
 303+ $dbr = wfGetDB( DB_SLAVE );
 304+ $res = $dbr->select( 'code_comment',
 305+ 'DISTINCT(cc_user)',
 306+ array(
 307+ 'cc_repo_id' => $this->mRepoId,
 308+ 'cc_rev_id' => $this->mId,
 309+ 'cc_user != 0' // users only
 310+ ),
 311+ __METHOD__
 312+ );
 313+ $users = array();
 314+ while( $row = $res->fetchObject() ) {
 315+ $users[$row->cc_user] = User::newFromId( $row->cc_user );
 316+ }
 317+ return $users;
 318+ }
 319+
256320 function getTags() {
257321 $dbr = wfGetDB( DB_SLAVE );
258322 $result = $dbr->select( 'code_tags',
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
@@ -69,6 +69,11 @@
7070 'code-rev-submit-next' => 'Commit & next unresolved',
7171
7272 'codereview-reply-link' => 'reply',
 73+
 74+ 'codereview-email-subj' => '[$1] [r$2]: New comment added',
 75+ 'codereview-email-body' => 'User <b>$1</b> posted the <a href="$2">following comment</a> on r$3:
 76+
 77+$4',
7378
7479 'repoadmin' => 'Repository Administration',
7580 'repoadmin-new-legend' => 'Create a new repository',

Past revisions this follows-up on

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)   01:44, 20 October 2008

Lazy load of the repo object isn't necessary -- we're only ever created in context of a repo object, which can be passed to us. :) Fixed in r42247.

Mail itself is bad, though -- it's listed as text/plain but contains HTML. Disabled notifications by default for now.

#Comment by Brion VIBBER (talk | contribs)   02:13, 20 October 2008

That has been fixed up. :D

Status & tagging log