r40884 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40883‎ | r40884 | r40885 >
Date:21:54, 15 September 2008
Author:brion
Status:old
Tags:
Comment:
quick hack to apply 'bug 1234' and 'r1234' link transformations to wikitext comments as well.
Note this probably won't play very nice with people already linking those texts :)
Modified paths:
  • /trunk/extensions/CodeReview/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/SpecialCode.php
@@ -71,18 +71,41 @@
7272 return $userLinks[$author] = $link;
7373 }
7474
75 - function formatMessage( $value ){
76 - $value = nl2br( htmlspecialchars( $value ) );
77 - $value = preg_replace_callback( '/\br(\d+)\b/', array( $this, 'messageRevLink' ), $value );
78 - $value = preg_replace_callback( '/\bbug #?(\d+)\b/i', array( $this, 'messageBugLink' ), $value );
79 - return $value;
 75+ function formatMessage( $text ){
 76+ $text = nl2br( htmlspecialchars( $text ) );
 77+ $linker = new CodeCommentLinkerHtml( $this->mRepo );
 78+ return $linker->link( $text );
8079 }
8180
 81+ function messageFragment( $value ) {
 82+ global $wgLang;
 83+ $message = trim( $value );
 84+ $lines = explode( "\n", $message, 2 );
 85+ $first = $lines[0];
 86+ $trimmed = $wgLang->truncate( $first, 60, '...' );
 87+ return $this->formatMessage( $trimmed );
 88+ }
 89+}
 90+
 91+class CodeCommentLinker {
 92+ function __construct( $repo ) {
 93+ global $wgUser;
 94+ $this->mSkin = $wgUser->getSkin();
 95+ $this->mRepo = $repo;
 96+ }
 97+
 98+ function link( $text ) {
 99+ $text = preg_replace_callback( '/\br(\d+)\b/', array( $this, 'messageRevLink' ), $text );
 100+ $text = preg_replace_callback( '/\bbug #?(\d+)\b/i', array( $this, 'messageBugLink' ), $text );
 101+ return $text;
 102+ }
 103+
82104 function messageBugLink( $arr ){
83105 $text = $arr[0];
84106 $bugNo = intval( $arr[1] );
85107 $url = $this->mRepo->getBugPath( $bugNo );
86 - return $this->mSkin->makeExternalLink( $url, $text );
 108+
 109+ return $this->makeExternalLink( $url, $text );
87110 }
88111
89112 function messageRevLink( $matches ) {
@@ -92,17 +115,29 @@
93116 $repo = $this->mRepo->getName();
94117 $title = SpecialPage::getTitleFor( 'Code', "$repo/$rev" );
95118
 119+ return $this->makeInternalLink( $title, $text );
 120+ }
 121+
 122+}
 123+
 124+class CodeCommentLinkerHtml extends CodeCommentLinker {
 125+ function makeExternalLink( $url, $text ) {
 126+ return $this->mSkin->makeExternalLink( $url, $text );
 127+ }
 128+
 129+ function makeInternalLink( $title, $text ) {
96130 return $this->mSkin->link( $title, $text );
97131 }
 132+}
98133
99 - function messageFragment( $value ) {
100 - global $wgLang;
101 - $message = trim( $value );
102 - $lines = explode( "\n", $message, 2 );
103 - $first = $lines[0];
104 - $trimmed = $wgLang->truncate( $first, 60, '...' );
105 - return $this->formatMessage( $trimmed );
 134+class CodeCommentLinkerWiki extends CodeCommentLinker {
 135+ function makeExternalLink( $url, $text ) {
 136+ return "[$url $text]";
106137 }
 138+
 139+ function makeInternalLink( $title, $text ) {
 140+ return "[[" . $title->getPrefixedText() . "|$text]]";
 141+ }
107142 }
108143
109144 // Special:Code
@@ -306,6 +341,7 @@
307342
308343 function formatComment( $comment ) {
309344 global $wgOut, $wgLang;
 345+ $linker = new CodeCommentLinkerWiki( $this->mRepo );
310346 return '<div class="mw-codereview-comment">' .
311347 '<div class="mw-codereview-comment-meta">' .
312348 wfMsgHtml( 'code-rev-comment-by' ) . ' ' .
@@ -315,7 +351,7 @@
316352 $wgLang->timeanddate( $comment->timestamp ) .
317353 '</div>' .
318354 '<div class="mw-codereview-comment-text">' .
319 - $wgOut->parse( $comment->text ) .
 355+ $wgOut->parse( $linker->link( $comment->text ) ) .
320356 '</div>' .
321357 '</div>';
322358 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r1234Added name attributes to all form elements to facilitate testing.lcrocker22:54, 13 March 2003
r40871fix for 'Bug 1234' as well as 'bug 1234'brion19:20, 15 September 2008

Status & tagging log