r40887 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40886‎ | r40887 | r40888 >
Date:22:26, 15 September 2008
Author:brion
Status:old
Tags:
Comment:
Basic threaded comment posting. (Post-submission display is still a bit wonky)
Modified paths:
  • /trunk/extensions/CodeReview/CodeComment.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeReview.i18n.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)
  • /trunk/extensions/CodeReview/codereview.css (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRevision.php
@@ -102,8 +102,8 @@
103103 // We construct a threaded sort key by concatenating the timestamps
104104 // of all our parent comments
105105 $dbw = wfGetDB( DB_SLAVE );
106 - $parentKey = $dbw->selectRow( 'code_comment',
107 - array( 'cc_sortkey' ),
 106+ $parentKey = $dbw->selectField( 'code_comment',
 107+ 'cc_sortkey',
108108 array( 'cc_id' => $parent ),
109109 __METHOD__ );
110110 if( $parentKey ) {
@@ -127,7 +127,8 @@
128128 'cc_user',
129129 'cc_user_text',
130130 'cc_timestamp',
131 - 'cc_review' ),
 131+ 'cc_review',
 132+ 'cc_sortkey' ),
132133 array(
133134 'cc_repo_id' => $this->mRepo,
134135 'cc_rev_id' => $this->mId ),
Index: trunk/extensions/CodeReview/CodeReview.i18n.php
@@ -30,6 +30,8 @@
3131 'code-rev-comment-submit' => 'Submit comment',
3232 'code-rev-comment-preview' => 'Preview',
3333 'code-rev-diff' => 'Diff',
 34+
 35+ 'codereview-reply-link' => 'reply',
3436
3537 'repoadmin' => 'Repository Administration',
3638 'repoadmin-new-legend' => 'Create a new repository',
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -25,6 +25,11 @@
2626 case 2:
2727 $view = new CodeRevisionView( $params[0], $params[1] );
2828 break;
 29+ case 4:
 30+ if( $params[2] == 'reply' ) {
 31+ $view = new CodeRevisionView( $params[0], $params[1], $params[3] );
 32+ break;
 33+ }
2934 default:
3035 throw new MWException( "Unexpected number of parameters" );
3136 }
@@ -237,10 +242,11 @@
238243 // Special:Code/MediaWiki/40696
239244 class CodeRevisionView extends CodeView {
240245
241 - function __construct( $repoName, $rev ){
 246+ function __construct( $repoName, $rev, $replyTarget=null ){
242247 parent::__construct();
243248 $this->mRepo = CodeRepository::newFromName( $repoName );
244249 $this->mRev = $this->mRepo ? $this->mRepo->getRevision( intval( $rev ) ) : null;
 250+ $this->mReplyTarget = $replyTarget;
245251 }
246252
247253 function execute(){
@@ -333,29 +339,61 @@
334340 return "<div class='mw-codereview-comments'>" .
335341 implode( "\n",
336342 array_map(
337 - array( $this, 'formatComment' ),
 343+ array( $this, 'formatCommentInline' ),
338344 $this->mRev->getComments() ) ) .
339345 $this->postCommentForm() .
340346 "</div>";
341347 }
342348
343 - function formatComment( $comment ) {
 349+ function formatCommentInline( $comment ) {
 350+ if( $comment->id == $this->mReplyTarget ) {
 351+ return $this->formatComment( $comment,
 352+ $this->postCommentForm( $comment->id ) );
 353+ } else {
 354+ return $this->formatComment( $comment );
 355+ }
 356+ }
 357+
 358+ function formatComment( $comment, $replyForm='' ) {
344359 global $wgOut, $wgLang;
345360 $linker = new CodeCommentLinkerWiki( $this->mRepo );
346 - return '<div class="mw-codereview-comment">' .
 361+ return Xml::openElement( 'div',
 362+ array(
 363+ 'class' => 'mw-codereview-comment',
 364+ 'id' => 'c' . intval( $comment->id ),
 365+ 'style' => $this->commentStyle( $comment ) ) ) .
347366 '<div class="mw-codereview-comment-meta">' .
348367 wfMsgHtml( 'code-rev-comment-by' ) . ' ' .
349368 $this->mSkin->userLink( $comment->user, $comment->userText ) .
350369 $this->mSkin->userToolLinks( $comment->user, $comment->userText ) .
351370 ' ' .
352371 $wgLang->timeanddate( $comment->timestamp ) .
 372+ ' ' .
 373+ $this->commentReplyLink( $comment->id ) .
353374 '</div>' .
354375 '<div class="mw-codereview-comment-text">' .
355376 $wgOut->parse( $linker->link( $comment->text ) ) .
356377 '</div>' .
 378+ $replyForm .
357379 '</div>';
358380 }
359381
 382+ function commentStyle( $comment ) {
 383+ $depth = $comment->threadDepth();
 384+ $margin = ($depth - 1) * 48;
 385+ return "margin-left: ${margin}px";
 386+ }
 387+
 388+ function commentReplyLink( $id ) {
 389+ $repo = $this->mRepo->getName();
 390+ $rev = $this->mRev->getId();
 391+ $self = SpecialPage::getTitleFor( 'Code', "$repo/$rev/reply/$id" );
 392+ $self->setFragment( "#c$id" );
 393+ return '[' .
 394+ $this->mSkin->link( $self, wfMsg( 'codereview-reply-link' ) ) .
 395+ ']';
 396+ }
 397+
360398 function postCommentForm( $parent=null ) {
361399 global $wgUser;
362400 return '<div class="mw-codereview-post-comment">' .
@@ -364,9 +402,7 @@
365403 'action' => '', // fixme
366404 'method' => 'post' ) ) .
367405 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
368 - Xml::hidden( 'wpCodeRepo', $this->mRepo->getName() ) .
369 - Xml::hidden( 'wpCodeRev', $this->mRev->getId() ) .
370 - ($parent ? Xml::hidden( 'wpCodeParent', $parent ) : '') .
 406+ ($parent ? Xml::hidden( 'wpParent', $parent ) : '') .
371407 '<div>' .
372408 Xml::textArea( 'wpTextbox1', '' ) .
373409 '</div>' .
Index: trunk/extensions/CodeReview/CodeComment.php
@@ -10,5 +10,11 @@
1111 $this->userText = $row->cc_user_text;
1212 $this->timestamp = wfTimestamp( TS_MW, $row->cc_timestamp );
1313 $this->review = $row->cc_review;
 14+ $this->sortkey = $row->cc_sortkey;
1415 }
 16+
 17+ function threadDepth() {
 18+ $timestamps = explode( ",", $this->sortkey );
 19+ return count( $timestamps );
 20+ }
1521 }
Index: trunk/extensions/CodeReview/codereview.css
@@ -13,3 +13,8 @@
1414 background: white;
1515 padding: 16px;
1616 }
 17+
 18+.mw-codereview-comment .mw-codereview-post-comment {
 19+ padding: 16px;
 20+ padding-left: 48px;
 21+}

Status & tagging log