r40889 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40888‎ | r40889 | r40890 >
Date:23:53, 15 September 2008
Author:brion
Status:old
Tags:
Comment:
Code review comment UI updates:
* Do a redirect after post; this avoids some madness, and lets us jump right to the comment
* Attempt to set focus to the input when hitting reply URLs. This seems to work ok in Safari, but Firefox and IE 7 don't quite take the focus(). They'll work if I drop the fragment, but then scrolling looks kind of funny.
Modified paths:
  • /trunk/extensions/CodeReview/CodeRevision.php (modified) (history)
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeRevision.php
@@ -95,6 +95,8 @@
9696 'cc_review' => $review,
9797 'cc_sortkey' => $sortkey ),
9898 __METHOD__ );
 99+
 100+ return $dbw->insertId();
99101 }
100102
101103 protected function threadedSortKey( $parent, $ts ) {
Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -257,7 +257,11 @@
258258 return;
259259 }
260260
261 - $this->checkPostings();
 261+ $redirectOnPost = $this->checkPostings();
 262+ if( $redirectOnPost ) {
 263+ $wgOut->redirect( $redirectOnPost );
 264+ return;
 265+ }
262266
263267 $repoLink = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() ),
264268 htmlspecialchars( $this->mRepo->getName() ) );
@@ -293,6 +297,14 @@
294298 $html .=
295299 "<h2>Comments</h2>" .
296300 $this->formatComments();
 301+
 302+ if( $this->mReplyTarget ) {
 303+ $id = intval( $this->mReplyTarget );
 304+ $html .= "<script>addOnloadHook(function(){" .
 305+ "document.getElementById('wpReplyTo$id').focus();" .
 306+ "});</script>";
 307+ }
 308+
297309 $wgOut->addHtml( $html );
298310 }
299311
@@ -301,17 +313,22 @@
302314 if( $wgRequest->wasPosted()
303315 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
304316 // Look for a posting...
305 - $text = $wgRequest->getText( 'wpTextbox1' );
 317+ $text = $wgRequest->getText( 'wpReply' );
306318 $parent = $wgRequest->getIntOrNull( 'wpParent' );
307319 $review = $wgRequest->getInt( 'wpReview' );
308320 $isPreview = $wgRequest->getCheck( 'wpCommentPreview' );
309321 if( $isPreview ) {
310322 // NYI
311323 } else {
312 - $this->mRev->saveComment( $text, $review, $parent );
313 - // fixme -- won't show up in slave load
 324+ $id = $this->mRev->saveComment( $text, $review, $parent );
 325+
 326+ // Redirect to the just-saved comment; this avoids POST
 327+ // horrors on forward/rewind. Hope we don't have slave issues?
 328+ $permaLink = $this->commentLink( $id );
 329+ return $permaLink->getFullUrl();
314330 }
315331 }
 332+ return false;
316333 }
317334
318335 function formatPathLine( $path, $action ) {
@@ -354,22 +371,25 @@
355372 }
356373 }
357374
 375+ function commentLink( $commentId ) {
 376+ $repo = $this->mRepo->getName();
 377+ $rev = $this->mRev->getId();
 378+ $title = SpecialPage::getTitleFor( 'Code', "$repo/$rev" );
 379+ $title->setFragment( "#c{$commentId}" );
 380+ return $title;
 381+ }
 382+
358383 function formatComment( $comment, $replyForm='' ) {
359384 global $wgOut, $wgLang;
360385 $linker = new CodeCommentLinkerWiki( $this->mRepo );
361386
362 - $repo = $this->mRepo->getName();
363 - $rev = $this->mRev->getId();
364 - $perma = SpecialPage::getTitleFor( 'Code', "$repo/$rev" );
365 - $perma->setFragment( "#c{$comment->id}" );
366 -
367387 return Xml::openElement( 'div',
368388 array(
369389 'class' => 'mw-codereview-comment',
370390 'id' => 'c' . intval( $comment->id ),
371391 'style' => $this->commentStyle( $comment ) ) ) .
372392 '<div class="mw-codereview-comment-meta">' .
373 - $this->mSkin->link( $perma, "#" ) .
 393+ $this->mSkin->link( $this->commentLink( $comment->id ), "#" ) .
374394 wfMsgHtml( 'code-rev-comment-by',
375395 $this->mSkin->userLink( $comment->user, $comment->userText ) .
376396 $this->mSkin->userToolLinks( $comment->user, $comment->userText ) ) .
@@ -411,7 +431,12 @@
412432 Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
413433 ($parent ? Xml::hidden( 'wpParent', $parent ) : '') .
414434 '<div>' .
415 - Xml::textArea( 'wpTextbox1', '' ) .
 435+ Xml::openElement( 'textarea', array(
 436+ 'name' => 'wpReply',
 437+ 'id' => "wpReplyTo{$parent}",
 438+ 'cols' => 40,
 439+ 'rows' => 5 ) ) .
 440+ '</textarea>' .
416441 '</div>' .
417442 '<div>' .
418443 Xml::submitButton( wfMsg( 'code-rev-comment-submit' ), array( 'name' => 'wpSave' ) ) .

Status & tagging log