r108350 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108349‎ | r108350 | r108351 >
Date:06:55, 8 January 2012
Author:johnduhart
Status:ok (Comments)
Tags:
Comment:
Reverting inline commenting from CodeReview

This change is still very buggy and has not recieved any love since initial commit. From the beginning it was an expertimental feature.

Instead of letting this sit in trunk forever, I'm just going to revert it. If you'd like to bring it back, finish it completely or make a branch.

ping r95429, r95435, r95680, r95680, r96173, r99030, r99034, r107068, r107069, r107074
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiCodeDiff.php (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiQueryCodeComments.php (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiRevisionUpdate.php (modified) (history)
  • /trunk/extensions/CodeReview/archives/code_comment_patch_line.sql (deleted) (history)
  • /trunk/extensions/CodeReview/backend/CodeComment.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/backend/DiffHighlighter.php (modified) (history)
  • /trunk/extensions/CodeReview/codereview.sql (modified) (history)
  • /trunk/extensions/CodeReview/modules/ext.codereview.linecomment.js (deleted) (history)
  • /trunk/extensions/CodeReview/modules/ext.codereview.styles.css (modified) (history)
  • /trunk/extensions/CodeReview/tests/CodeReviewApiTest.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeCommentsListView.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -167,10 +167,6 @@
168168 'scripts' => 'ext.codereview.loaddiff.js'
169169 ) + $commonModuleInfo;
170170
171 -$wgResourceModules['ext.codereview.linecomment'] = array(
172 - 'scripts' => 'ext.codereview.linecomment.js'
173 -) + $commonModuleInfo;
174 -
175171 // Revision tooltips CodeRevisionView:
176172 $wgResourceModules['ext.codereview.tooltips'] = array(
177173 'scripts' => 'ext.codereview.tooltips.js',
@@ -354,8 +350,6 @@
355351
356352 $updater->addExtensionIndex( 'code_rev', 'cr_repo_status_author',
357353 "$base/archives/code_revs_status_author-index.sql" );
358 - $updater->addExtensionField( 'code_comment', 'cc_patch_line',
359 - "$base/archives/code_comment_patch_line.sql" );
360354
361355 $updater->addExtensionUpdate( array( 'dropField', 'code_comment', 'cc_review',
362356 "$base/archives/code_drop_cc_review.sql", true ) );
@@ -371,8 +365,6 @@
372366 "$base/archives/code_signoffs_timestamp_struck.sql", true ) );
373367 $updater->addExtensionUpdate( array( 'addIndex', 'code_paths', 'repo_path',
374368 "$base/archives/codereview-repopath.sql", true ) );
375 - $updater->addExtensionUpdate( array( 'addField', 'code_comment', 'cc_patch_line',
376 - "$base/archives/code_comment_patch_line.sql", true ) );
377369 break;
378370 case 'postgres':
379371 // TODO
Index: trunk/extensions/CodeReview/tests/CodeReviewApiTest.php
@@ -68,7 +68,6 @@
6969 $data = $this->doApiRequest( array(
7070 'action' => 'coderevisionupdate',
7171 'rev' => 777,
72 - 'patchline' => 51,
7372 'comment' => 'Awesome comment',
7473
7574 ) + $this->commonApiData );
Index: trunk/extensions/CodeReview/archives/code_comment_patch_line.sql
@@ -1,2 +0,0 @@
2 -ALTER TABLE /*_*/code_comment
3 - ADD COLUMN cc_patch_line int default null;
Index: trunk/extensions/CodeReview/backend/CodeRevision.php
@@ -656,16 +656,15 @@
657657 * @param $text
658658 * @param $review
659659 * @param null $parent
660 - * @param int $patchLine (default: null)
661660 * @return int
662661 */
663 - public function saveComment( $text, $review, $parent = null, $patchLine = null ) {
 662+ public function saveComment( $text, $review, $parent = null ) {
664663 $text = rtrim( $text );
665664 if ( !strlen( $text ) ) {
666665 return 0;
667666 }
668667 $dbw = wfGetDB( DB_MASTER );
669 - $data = $this->commentData( $text, $review, $parent, $patchLine );
 668+ $data = $this->commentData( $text, $review, $parent );
670669
671670 $dbw->begin();
672671 $data['cc_id'] = $dbw->nextSequenceValue( 'code_comment_cc_id' );
@@ -735,10 +734,9 @@
736735 * @param $text
737736 * @param $review
738737 * @param null $parent
739 - * @param int $patchLine (default: null)
740738 * @return array
741739 */
742 - protected function commentData( $text, $review, $parent = null, $patchLine = null ) {
 740+ protected function commentData( $text, $review, $parent = null ) {
743741 global $wgUser;
744742 $dbw = wfGetDB( DB_MASTER );
745743 $ts = wfTimestamp( TS_MW );
@@ -748,7 +746,6 @@
749747 'cc_rev_id' => $this->id,
750748 'cc_text' => $text,
751749 'cc_parent' => $parent,
752 - 'cc_patch_line' => $patchLine,
753750 'cc_user' => $wgUser->getId(),
754751 'cc_user_text' => $wgUser->getName(),
755752 'cc_timestamp' => $dbw->timestamp( $ts ),
@@ -782,21 +779,9 @@
783780 }
784781
785782 /**
786 - * @param $attached boolean Fetch comment attached to a line of code (default: false)
787783 * @return array
788784 */
789 - public function getComments( $attached = false ) {
790 - $conditions = array(
791 - 'cc_repo_id' => $this->repoId,
792 - 'cc_rev_id' => $this->id
793 - );
794 -
795 - if( $attached ) {
796 - $conditions[] = 'cc_patch_line != null';
797 - } else {
798 - $conditions['cc_patch_line'] = null;
799 - }
800 -
 785+ public function getComments() {
801786 $dbr = wfGetDB( DB_SLAVE );
802787 $result = $dbr->select( 'code_comment',
803788 array(
@@ -804,10 +789,11 @@
805790 'cc_text',
806791 'cc_user',
807792 'cc_user_text',
808 - 'cc_patch_line',
809793 'cc_timestamp',
810794 'cc_sortkey' ),
811 - $conditions,
 795+ array(
 796+ 'cc_repo_id' => $this->repoId,
 797+ 'cc_rev_id' => $this->id ),
812798 __METHOD__,
813799 array(
814800 'ORDER BY' => 'cc_sortkey' )
Index: trunk/extensions/CodeReview/backend/CodeComment.php
@@ -4,7 +4,7 @@
55 * Represents a comment made to a revision.
66 */
77 class CodeComment {
8 - public $id, $text, $user, $userText, $timestamp, $sortkey, $attrib, $removed, $added, $patchLine;
 8+ public $id, $text, $user, $userText, $timestamp, $sortkey, $attrib, $removed, $added;
99
1010 /**
1111 * @var CodeRevision
@@ -68,7 +68,6 @@
6969 $comment->user = $data['cc_user'];
7070 $comment->userText = $data['cc_user_text'];
7171 $comment->timestamp = wfTimestamp( TS_MW, $data['cc_timestamp'] );
72 - $comment->patchLine = $data['cc_patch_line'];
7372 $comment->sortkey = $data['cc_sortkey'];
7473 return $comment;
7574 }
Index: trunk/extensions/CodeReview/backend/DiffHighlighter.php
@@ -14,67 +14,19 @@
1515 protected $lineNumber = 0;
1616
1717 /**
18 - * @var CodeRepositor The repository for this revision
19 - */
20 - protected $repo = null;
21 -
22 - /**
23 - * @var CodeRevision revision the diff comes from
24 - */
25 - protected $rev = null;
26 -
27 - /**
28 - * Comments inside the diff.
29 - * initialized with fetchInlineComments()
30 - */
31 - private $inlineComments = null;
32 -
33 - /**
3418 * Main entry point. Given a diff text, highlight it
3519 * and wrap it in a div
36 - * Pass both $repos and $rev to have the diff rendered with inline comments
3720 *
3821 * @param $text string Text to highlight
39 - * @param $repo CodeRepository (default: null)
40 - * @param $repo CodeRevision (default: null)
4122 * @return string
4223 */
43 - function render( $text, CodeRepository $repo = null, CodeRevision $rev = null ) {
44 - if( $repo xor $rev ) {
45 - throw new MWException( __METHOD__ . " must have both repository and revision or none of them\n" );
46 - } elseif( $repo && $rev ) {
47 - $this->repo = $repo;
48 - $this->rev = $rev;
49 - $this->fetchInlineComments();
50 - }
51 -
 24+ function render( $text ) {
5225 return '<table class="mw-codereview-diff">' .
5326 $this->splitLines( $text ) .
5427 "</table>\n";
5528 }
5629
5730 /**
58 - * Fetch comments attached to a patch line.
59 - * Comments can be accessed through the array inlineComments. Its format is:
60 - * array(
61 - * line# => array(
62 - * CodeComment, CodeComment ...
63 - * ),
64 - * line# => array(
65 - * CodeComment, CodeComment ...
66 - * ),
67 - * ...
68 - * );
69 - */
70 - private function fetchInlineComments() {
71 - $inline = $this->rev->getComments( 'which are attached' );
72 - foreach( $inline as $comment ) {
73 - $line = $comment->patchLine; # absolute line number in the diff
74 - $this->inlineComments[$line][] = $comment;
75 - }
76 - }
77 -
78 - /**
7931 * Given a bunch of text, split it into individual
8032 * lines, color them, then put it back into one big
8133 * string
@@ -128,39 +80,14 @@
12981 $r = $this->handleLineFile( $line );
13082 }
13183
132 - # Finally add up any lineComments that might apply to this line
133 - $r .= $this->addLineComments();
134 -
13584 # Return HTML generated by one of the handler
13685 return $r;
13786 }
13887
139 - function addLineComments() {
140 - $return = '';
141 - if( !isset( $this->inlineComments ) ) {
142 - # No inline comments for this revision.
143 - return $return;
144 - }
145 - if( !array_key_exists( $this->lineNumber, $this->inlineComments ) ) {
146 - # Line does not have any comment applying to
147 - return $return;
148 - }
149 -
150 - $comments = $this->inlineComments[$this->lineNumber];
151 - # FIXME: comment formatting can only be handled by a view
152 - # Would need abstraction, for example as a class of views helpers.
153 - $view = new CodeRevisionView( $this->repo, $this->rev );
154 - foreach( $comments as $comment ) {
155 - $return .= "<li>{$view->formatComment( $comment )}</li>\n" ;
156 - }
157 - return "<tr class=\"mw-codereview-inlineComment\"><td colspan=\"3\"><ul>{$return}</ul></td></tr>\n";
158 - }
159 -
16088 function formatLine( $content, $class = null ) {
16189
16290 if( is_null($class) ) {
163 - return Html::rawElement( 'tr',
164 - array_merge( $this->getLineIdAttr(), array( 'class' => 'commentable' ) ),
 91+ return Html::rawElement( 'tr', $this->getLineIdAttr(),
16592 Html::Element( 'td', array( 'class'=>'linenumbers' ), $this->left )
16693 . Html::Element( 'td', array( 'class'=>'linenumbers' ), $this->right )
16794 . Html::Element( 'td', array() , $content )
@@ -190,8 +117,7 @@
191118 }
192119
193120 $classAttr = is_null($class) ? array() : array( 'class' => $class );
194 - return Html::rawElement( 'tr',
195 - array_merge( $this->getLineIdAttr(), array( 'class' => 'commentable' ) ),
 121+ return Html::rawElement( 'tr', $this->getLineIdAttr(),
196122 Html::rawElement( 'td', array( 'class'=>'linenumbers' ), $left )
197123 . Html::rawElement( 'td', array( 'class'=>'linenumbers' ), $right )
198124 . Html::Element( 'td', $classAttr, $content )
Index: trunk/extensions/CodeReview/modules/ext.codereview.linecomment.js
@@ -1,110 +0,0 @@
2 -( function( $ ) {
3 -var $rev = 0;
4 -
5 -window.CodeReview = $.extend( window.CodeReview, {
6 -
7 - /* initialization from PHP */
8 - lcInit: function( rev ) {
9 - $rev = rev;
10 - // Register click() event to each diff lines
11 - $( 'table.mw-codereview-diff tr.commentable').click(
12 - function () { CodeReview.lcShowForm( $(this) ); }
13 - );
14 - },
15 -
16 - /**
17 - * Show the line comment code below a line of code
18 - * @param lineCode jQuery object
19 - */
20 - lcShowForm: function( lineCode ) {
21 - // Make sure the line id is an integer:
22 - var lineNumber = parseInt( lineCode.attr('id') ) + 0;
23 - // Forge the line comment HTML id:
24 - var htmlId = 'comment-for-' + lineNumber;
25 -
26 - lineCode.unbind( 'click' );
27 - lineCode.click( function () {
28 - $( '#'+htmlId ).fadeOut( 200 ).remove();
29 -
30 - lineCode.unbind( 'click' );
31 - lineCode.click( function() {
32 - CodeReview.lcShowForm( lineCode );
33 - });
34 - });
35 -
36 - var lineComment =
37 - $('<tr id="' + htmlId + '"><td colspan="3">'
38 - +'<textarea id="lineCommentContent" rows="5"></textarea><br/>'
39 - +'<input id="lineCommentSend" type="button" value="Send">'
40 - +'</td></tr>');
41 - lineComment.insertAfter( lineCode );
42 - $( '#lineCommentContent' ).focus();
43 -
44 - $( '#lineCommentSend' ).click( function() {
45 - CodeReview.lcSubmitComment(
46 - lineCode,
47 - lineComment,
48 - $( '#lineCommentContent' ).val()
49 - );
50 - });
51 - },
52 -
53 - lcSubmitComment: function( lineCode, lineComment, comment ) {
54 -
55 - // retrieve line number from the code line id attribute:
56 - var lineId = lineCode.attr('id');
57 - lineId = lineId.substring( lineId.indexOf( '-' ) + 1);
58 -
59 - $.ajax({
60 - url: mw.util.wikiScript( 'api' ),
61 - data: {
62 - 'action': 'coderevisionupdate',
63 -
64 - 'repo' : mw.config.get( 'wgCodeReviewRepository' ),
65 - 'rev' : $rev,
66 -
67 - 'comment': comment,
68 - 'patchline' : lineId,
69 -
70 - 'format': 'json',
71 - },
72 - dataType: 'json',
73 - type: 'POST',
74 - success: function( data ) {
75 - // our API return usage error as a success!
76 - if( data.error !== undefined ) {
77 - console.log( lineComment.find( 'input' ) );
78 - lineComment.find( 'input' ).after(
79 - $('<span class="errorbox"></span>')
80 - .text( data.error.info )
81 - );
82 - return;
83 - }
84 -
85 - var text = data.coderevisionupdate.HTML
86 - lineComment.fadeOut( 200 ).remove();
87 -
88 - // check we have a list to insert the comment in.
89 - var next = lineCode.next( '.inlineComment' );
90 - if( next.length === 0 ) {
91 - $( '<tr class="inlineComment"><td colspan="3"><ul><li>'+text+'</li></ul></td></tr>' ).insertAfter( lineCode )
92 - } else {
93 - lineCode.next('.inlineComment').find( 'ul' ).append(
94 - $( '<li>' + text + '</li>' )
95 - );
96 - }
97 -
98 -
99 - // rebind event handler
100 - lineCode.click(
101 - function () { CodeReview.lcShowForm( $(this) ); }
102 - );
103 - },
104 - error: function() {
105 - console.log( "AJAX ERROR" );
106 - }
107 - });
108 - },
109 -
110 -}); // window.CodeReview
111 -})( jQuery );
Index: trunk/extensions/CodeReview/modules/ext.codereview.styles.css
@@ -58,15 +58,6 @@
5959 padding: 16px 16px 16px 48px;
6060 }
6161
62 -/** list containers to insert comments inside the diff table */
63 -.mw-codereview-inlineComment ul {
64 - list-style-image: none; /* override Vector default */
65 - list-style-type: none;
66 - padding:0;
67 - padding-left: 2em;
68 - margin-bottom: 8px;
69 -}
70 -
7162 .mw-codereview-status-new,
7263 .mw-codereview-status-new td {
7364 background: #ffffc0 !important;
Index: trunk/extensions/CodeReview/api/ApiRevisionUpdate.php
@@ -66,14 +66,12 @@
6767 $params['removeflags'],
6868 $params['addreferences'],
6969 $params['removereferences'],
70 - $params['comment'],
71 - null, // parent
72 - 0, // review
73 - $params['patchline']
 70+ $params['comment']
7471 );
7572
7673 // Forge a response object
7774 $r = array( 'result' => 'Success' );
 75+
7876 if ( $commentID !== 0 ) {
7977 // id inserted
8078 $r['commentid'] = intval($commentID);
@@ -81,7 +79,6 @@
8280 $view = new CodeRevisionView( $repo, $rev);
8381 $comment = CodeComment::newFromID( $commentID, $rev );
8482 $r['HTML'] = $view->formatComment( $comment );
85 - //$r['HTML'] = print_r( $comment, true );
8683 }
8784
8885 $this->getResult()->addValue( null, $this->getModuleName(), $r );
@@ -137,10 +134,6 @@
138135 ApiBase::PARAM_TYPE => 'integer',
139136 ApiBase::PARAM_ISMULTI => true,
140137 ),
141 - 'patchline' => array(
142 - ApiBase::PARAM_TYPE => 'integer',
143 - ApiBase::PARAM_MIN => 1,
144 - ),
145138 );
146139 }
147140
@@ -156,7 +149,6 @@
157150 'removeflags' => 'Code Signoff flags to strike from the revision by the current user',
158151 'addreferences' => 'Add references to this revision',
159152 'removereferences' => 'Remove references from this revision',
160 - 'patchline' => 'Diff line to attach the comment to (optional)',
161153 );
162154 }
163155
Index: trunk/extensions/CodeReview/api/ApiCodeDiff.php
@@ -47,7 +47,6 @@
4848 $html = 'Diff too large.';
4949 } else {
5050 $hilite = new CodeDiffHighlighter();
51 - # Fetch diff rendered without inline comments
5251 $html = $hilite->render( $diff );
5352 }
5453
Index: trunk/extensions/CodeReview/api/ApiQueryCodeComments.php
@@ -95,9 +95,6 @@
9696 if ( isset( $this->props['text'] ) ) {
9797 ApiResult::setContent( $item, $row->cc_text );
9898 }
99 - if ( isset( $this->props['patchline'] ) ) {
100 - $item['patchline'] = $row->cc_patch_line;
101 - }
10299 return $item;
103100 }
104101
@@ -125,7 +122,6 @@
126123 'user',
127124 'status',
128125 'text',
129 - 'patchline',
130126 'revid',
131127 'revision',
132128 ),
Index: trunk/extensions/CodeReview/codereview.sql
@@ -173,9 +173,6 @@
174174 -- cc_id of parent comment if a threaded child, otherwise NULL
175175 cc_parent int,
176176
177 - -- patch line the comment eventually applies to or NULL
178 - cc_patch_line int default null,
179 -
180177 -- User id/name of the commenter
181178 cc_user int not null,
182179 cc_user_text varchar(255) not null,
Index: trunk/extensions/CodeReview/ui/CodeCommentsListView.php
@@ -57,8 +57,6 @@
5858 'cr_status' => wfMsg( 'code-field-status' ),
5959 'cr_message' => wfMsg( 'code-field-message' ),
6060 '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,
6361 );
6462 }
6563
Index: trunk/extensions/CodeReview/ui/CodeRevisionCommitter.php
@@ -58,12 +58,11 @@
5959 * @param string $commentText Comment to add to the revision
6060 * @param null|int $parent What the parent comment is (if a subcomment)
6161 * @param int $review (unused)
62 - * @param int $patchLine Patch line number to which the comment will be attached (default: null).
6362 * @return int Comment ID if added, else 0
6463 */
6564 public function revisionUpdate( $status, $addTags, $removeTags, $addSignoffs, $strikeSignoffs,
6665 $addReferences, $removeReferences, $commentText,
67 - $parent = null, $review = 0, $patchLine = null) {
 66+ $parent = null, $review = 0 ) {
6867 if ( !$this->mRev ) {
6968 return false;
7069 }
@@ -111,7 +110,7 @@
112111 $commentId = 0;
113112 if ( strlen( $commentText ) && $this->validPost( 'codereview-post-comment' ) ) {
114113 // $isPreview = $wgRequest->getCheck( 'wpPreview' );
115 - $commentId = $this->mRev->saveComment( $commentText, $review, $parent, $patchLine );
 114+ $commentId = $this->mRev->saveComment( $commentText, $review, $parent );
116115
117116 $commentAdded = ($commentId !== 0);
118117 }
Index: trunk/extensions/CodeReview/ui/CodeRevisionView.php
@@ -202,16 +202,6 @@
203203 }
204204 $html .= xml::closeElement( 'form' );
205205
206 - // Encode revision id for our modules
207 - $encRev = Xml::encodeJsVar( $this->mRev->getId() );
208 -
209 - if( $wgCodeReviewInlineComments ) {
210 - $wgOut->addModules( 'ext.codereview.linecomment' );
211 - $wgOut->addInlineScript(
212 - "$(document).ready( CodeReview.lcInit( $encRev ) );"
213 - );
214 - }
215 -
216206 $wgOut->addHTML( $html );
217207 }
218208
@@ -470,8 +460,7 @@
471461 return htmlspecialchars( wfMsg( 'code-rev-diff-too-large' ) );
472462 } else {
473463 $hilite = new CodeDiffHighlighter();
474 - # Diff rendered with inline comments
475 - return $hilite->render( $diff, $this->mRepo, $this->mRev );
 464+ return $hilite->render( $diff );
476465 }
477466 }
478467

Follow-up revisions

RevisionCommit summaryAuthorDate
r108351Followup r108350, remove remaining configuration option...johnduhart06:59, 8 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95429add ability to attach a comment to a diff line...hashar19:53, 24 August 2011
r95435add inline comments to the diff output...hashar19:53, 24 August 2011
r95680(bug 30617) inline comments forms cannot be closed...hashar17:31, 29 August 2011
r96173API: check user can post comment...hashar09:12, 3 September 2011
r99030disable inline commenting by default...hashar19:14, 5 October 2011
r99034API: give error when trying not attach a comment to a line...hashar19:40, 5 October 2011
r107068fix case of addInLineScript...hashar15:08, 22 December 2011
r107069wrap linecomment js initializer in a ready() block...hashar15:12, 22 December 2011
r107074make sure the line ID is an integer before injecting it...hashar16:14, 22 December 2011

Comments

#Comment by Hashar (talk | contribs)   11:51, 8 January 2012

> This change is still very buggy

Where are the bug reports?

> and has not recieved any love since initial commit.

Tim did a review of my changes, I turn fixed the issue with r105542 r106113 r107068 r107069 r107064 which can't be reviewed right now cause Tim is in vacations!

> From the beginning it was an experimental feature

Not at all. I have added that feature to make code reviewing easier. It follow a discussion with Sumanah and Mark IIRC. Bugzilla and Gerrit both have a similar feature.

#Comment by Hashar (talk | contribs)   14:49, 9 January 2012

Now we need git migration to be done so we can install gerrit /gitorious :D

Status & tagging log