Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -288,6 +288,8 @@ |
289 | 289 | |
290 | 290 | $updater->addExtensionUpdate( array( 'addIndex', 'code_rev', 'cr_repo_status_author', |
291 | 291 | "$base/archives/code_revs_status_author-index.sql", true ) ); |
| 292 | + $updater->addExtensionUpdate( array( 'addField', 'code_comment', 'cc_patch_line', |
| 293 | + "$base/archives/code_comment_patch_line.sql", true ) ); |
292 | 294 | break; |
293 | 295 | case 'sqlite': |
294 | 296 | $updater->addExtensionUpdate( array( 'addTable', 'code_rev', "$base/codereview.sql", true ) ); |
— | — | @@ -298,6 +300,8 @@ |
299 | 301 | "$base/archives/code_signoffs_timestamp_struck.sql", true ) ); |
300 | 302 | $updater->addExtensionUpdate( array( 'addIndex', 'code_paths', 'repo_path', |
301 | 303 | "$base/archives/codereview-repopath.sql", true ) ); |
| 304 | + $updater->addExtensionUpdate( array( 'addField', 'code_comment', 'cc_patch_line', |
| 305 | + "$base/archives/code_comment_patch_line.sql", true ) ); |
302 | 306 | break; |
303 | 307 | case 'postgres': |
304 | 308 | // TODO |
Index: trunk/extensions/CodeReview/backend/CodeRevision.php |
— | — | @@ -607,15 +607,16 @@ |
608 | 608 | * @param $text |
609 | 609 | * @param $review |
610 | 610 | * @param null $parent |
| 611 | + * @param int $patchLine (default: null) |
611 | 612 | * @return int |
612 | 613 | */ |
613 | | - public function saveComment( $text, $review, $parent = null ) { |
| 614 | + public function saveComment( $text, $review, $parent = null, $patchLine = null ) { |
614 | 615 | $text = rtrim( $text ); |
615 | 616 | if ( !strlen( $text ) ) { |
616 | 617 | return 0; |
617 | 618 | } |
618 | 619 | $dbw = wfGetDB( DB_MASTER ); |
619 | | - $data = $this->commentData( $text, $review, $parent ); |
| 620 | + $data = $this->commentData( $text, $review, $parent, $patchLine ); |
620 | 621 | |
621 | 622 | $dbw->begin(); |
622 | 623 | $data['cc_id'] = $dbw->nextSequenceValue( 'code_comment_cc_id' ); |
— | — | @@ -685,9 +686,10 @@ |
686 | 687 | * @param $text |
687 | 688 | * @param $review |
688 | 689 | * @param null $parent |
| 690 | + * @param int $patchLine (default: null) |
689 | 691 | * @return array |
690 | 692 | */ |
691 | | - protected function commentData( $text, $review, $parent = null ) { |
| 693 | + protected function commentData( $text, $review, $parent = null, $patchLine = null ) { |
692 | 694 | global $wgUser; |
693 | 695 | $dbw = wfGetDB( DB_MASTER ); |
694 | 696 | $ts = wfTimestamp( TS_MW ); |
— | — | @@ -697,6 +699,7 @@ |
698 | 700 | 'cc_rev_id' => $this->id, |
699 | 701 | 'cc_text' => $text, |
700 | 702 | 'cc_parent' => $parent, |
| 703 | + 'cc_patch_line' => $patchLine, |
701 | 704 | 'cc_user' => $wgUser->getId(), |
702 | 705 | 'cc_user_text' => $wgUser->getName(), |
703 | 706 | 'cc_timestamp' => $dbw->timestamp( $ts ), |
— | — | @@ -731,9 +734,17 @@ |
732 | 735 | } |
733 | 736 | |
734 | 737 | /** |
| 738 | + * @param $attached boolean Fetch comment attached to a line of code (default: false) |
735 | 739 | * @return array |
736 | 740 | */ |
737 | | - public function getComments() { |
| 741 | + public function getComments( $attached = false ) { |
| 742 | + $conditions = array( |
| 743 | + 'cc_repo_id' => $this->repoId, |
| 744 | + 'cc_rev_id' => $this->id ); |
| 745 | + |
| 746 | + if( $attached ) { $conditions['cc_patch_line!'] = null; } |
| 747 | + else { $conditions['cc_patch_line'] = null; } |
| 748 | + |
738 | 749 | $dbr = wfGetDB( DB_SLAVE ); |
739 | 750 | $result = $dbr->select( 'code_comment', |
740 | 751 | array( |
— | — | @@ -741,12 +752,11 @@ |
742 | 753 | 'cc_text', |
743 | 754 | 'cc_user', |
744 | 755 | 'cc_user_text', |
| 756 | + 'cc_patch_line', |
745 | 757 | 'cc_timestamp', |
746 | 758 | 'cc_review', |
747 | 759 | 'cc_sortkey' ), |
748 | | - array( |
749 | | - 'cc_repo_id' => $this->repoId, |
750 | | - 'cc_rev_id' => $this->id ), |
| 760 | + $conditions, |
751 | 761 | __METHOD__, |
752 | 762 | array( |
753 | 763 | 'ORDER BY' => 'cc_sortkey' ) |
Index: trunk/extensions/CodeReview/backend/CodeComment.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | class CodeComment { |
5 | | - public $id, $text, $user, $userText, $timestamp, $review, $sortkey, $attrib, $removed, $added; |
| 5 | + public $id, $text, $user, $userText, $timestamp, $review, $sortkey, $attrib, $removed, $added, $patchLine; |
6 | 6 | |
7 | 7 | /** |
8 | 8 | * @var CodeRevision |
— | — | @@ -36,6 +36,7 @@ |
37 | 37 | $comment->user = $data['cc_user']; |
38 | 38 | $comment->userText = $data['cc_user_text']; |
39 | 39 | $comment->timestamp = wfTimestamp( TS_MW, $data['cc_timestamp'] ); |
| 40 | + $comment->patchLine = $data['cc_patch_line']; |
40 | 41 | $comment->review = $data['cc_review']; |
41 | 42 | $comment->sortkey = $data['cc_sortkey']; |
42 | 43 | return $comment; |
Index: trunk/extensions/CodeReview/codereview.sql |
— | — | @@ -173,6 +173,9 @@ |
174 | 174 | -- cc_id of parent comment if a threaded child, otherwise NULL |
175 | 175 | cc_parent int, |
176 | 176 | |
| 177 | + -- patch line the comment eventually applies to or NULL |
| 178 | + cc_patch_line int default null, |
| 179 | + |
177 | 180 | -- User id/name of the commenter |
178 | 181 | cc_user int not null, |
179 | 182 | cc_user_text varchar(255) not null, |
Index: trunk/extensions/CodeReview/archives/code_comment_patch_line.sql |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +ALTER TABLE /*_*/code_comment |
| 3 | + ADD COLUMN cc_patch_line int default null; |
Index: trunk/extensions/CodeReview/api/ApiRevisionUpdate.php |
— | — | @@ -53,7 +53,10 @@ |
54 | 54 | $params['removeflags'], |
55 | 55 | $params['addreferences'], |
56 | 56 | $params['removereferences'], |
57 | | - $params['comment'] |
| 57 | + $params['comment'], |
| 58 | + null, // parent |
| 59 | + 0, // review |
| 60 | + $params['patchline'] |
58 | 61 | ); |
59 | 62 | |
60 | 63 | $r = array( 'result' => 'Success' ); |
— | — | @@ -115,6 +118,10 @@ |
116 | 119 | ApiBase::PARAM_TYPE => 'integer', |
117 | 120 | ApiBase::PARAM_ISMULTI => true, |
118 | 121 | ), |
| 122 | + 'patchline' => array( |
| 123 | + ApiBase::PARAM_TYPE => 'integer', |
| 124 | + ApiBase::PARAM_MIN => 1, |
| 125 | + ), |
119 | 126 | ); |
120 | 127 | } |
121 | 128 | |
— | — | @@ -130,6 +137,7 @@ |
131 | 138 | 'removeflags' => 'Code Signoff flags to strike from the revision by the current user', |
132 | 139 | 'addreferences' => 'Add references to this revision', |
133 | 140 | 'removereferences' => 'Remove references from this revision', |
| 141 | + 'patchline' => 'Diff line to attach the comment to (optional)', |
134 | 142 | ); |
135 | 143 | } |
136 | 144 | |
Index: trunk/extensions/CodeReview/api/ApiQueryCodeComments.php |
— | — | @@ -95,6 +95,9 @@ |
96 | 96 | if ( isset( $this->props['text'] ) ) { |
97 | 97 | ApiResult::setContent( $item, $row->cc_text ); |
98 | 98 | } |
| 99 | + if ( isset( $this->props['patchline'] ) ) { |
| 100 | + $item['patchline'] = $row->cc_patch_line; |
| 101 | + } |
99 | 102 | return $item; |
100 | 103 | } |
101 | 104 | |
— | — | @@ -122,6 +125,7 @@ |
123 | 126 | 'user', |
124 | 127 | 'status', |
125 | 128 | 'text', |
| 129 | + 'patchline', |
126 | 130 | 'revid', |
127 | 131 | 'revision', |
128 | 132 | ), |
Index: trunk/extensions/CodeReview/ui/CodeCommentsListView.php |
— | — | @@ -57,6 +57,8 @@ |
58 | 58 | 'cr_status' => wfMsg( 'code-field-status' ), |
59 | 59 | 'cr_message' => wfMsg( 'code-field-message' ), |
60 | 60 | 'cc_text' => wfMsg( 'code-field-text' ), |
| 61 | + # patch line is only used for API call. No need for an i18n message |
| 62 | + 'cc_patch_line' => null, |
61 | 63 | ); |
62 | 64 | } |
63 | 65 | |
Index: trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php |
— | — | @@ -58,11 +58,12 @@ |
59 | 59 | * @param string $commentText Comment to add to the revision |
60 | 60 | * @param null|int $parent What the parent comment is (if a subcomment) |
61 | 61 | * @param int $review (unused) |
| 62 | + * @param int $patchLine Patch line number to which the comment will be attached (default: null). |
62 | 63 | * @return int Comment ID if added, else 0 |
63 | 64 | */ |
64 | 65 | public function revisionUpdate( $status, $addTags, $removeTags, $addSignoffs, $strikeSignoffs, |
65 | 66 | $addReferences, $removeReferences, $commentText, |
66 | | - $parent = null, $review = 0 ) { |
| 67 | + $parent = null, $review = 0, $patchLine = null) { |
67 | 68 | if ( !$this->mRev ) { |
68 | 69 | return false; |
69 | 70 | } |
— | — | @@ -110,7 +111,7 @@ |
111 | 112 | $commentId = 0; |
112 | 113 | if ( strlen( $commentText ) && $this->validPost( 'codereview-post-comment' ) ) { |
113 | 114 | // $isPreview = $wgRequest->getCheck( 'wpPreview' ); |
114 | | - $commentId = $this->mRev->saveComment( $commentText, $review, $parent ); |
| 115 | + $commentId = $this->mRev->saveComment( $commentText, $review, $parent, $patchLine ); |
115 | 116 | |
116 | 117 | $commentAdded = ($commentId !== 0); |
117 | 118 | } |