Index: trunk/extensions/CodeReview/SpecialCode.php |
— | — | @@ -71,18 +71,41 @@ |
72 | 72 | return $userLinks[$author] = $link; |
73 | 73 | } |
74 | 74 | |
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 ); |
80 | 79 | } |
81 | 80 | |
| 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 | + |
82 | 104 | function messageBugLink( $arr ){ |
83 | 105 | $text = $arr[0]; |
84 | 106 | $bugNo = intval( $arr[1] ); |
85 | 107 | $url = $this->mRepo->getBugPath( $bugNo ); |
86 | | - return $this->mSkin->makeExternalLink( $url, $text ); |
| 108 | + |
| 109 | + return $this->makeExternalLink( $url, $text ); |
87 | 110 | } |
88 | 111 | |
89 | 112 | function messageRevLink( $matches ) { |
— | — | @@ -92,17 +115,29 @@ |
93 | 116 | $repo = $this->mRepo->getName(); |
94 | 117 | $title = SpecialPage::getTitleFor( 'Code', "$repo/$rev" ); |
95 | 118 | |
| 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 ) { |
96 | 130 | return $this->mSkin->link( $title, $text ); |
97 | 131 | } |
| 132 | +} |
98 | 133 | |
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]"; |
106 | 137 | } |
| 138 | + |
| 139 | + function makeInternalLink( $title, $text ) { |
| 140 | + return "[[" . $title->getPrefixedText() . "|$text]]"; |
| 141 | + } |
107 | 142 | } |
108 | 143 | |
109 | 144 | // Special:Code |
— | — | @@ -306,6 +341,7 @@ |
307 | 342 | |
308 | 343 | function formatComment( $comment ) { |
309 | 344 | global $wgOut, $wgLang; |
| 345 | + $linker = new CodeCommentLinkerWiki( $this->mRepo ); |
310 | 346 | return '<div class="mw-codereview-comment">' . |
311 | 347 | '<div class="mw-codereview-comment-meta">' . |
312 | 348 | wfMsgHtml( 'code-rev-comment-by' ) . ' ' . |
— | — | @@ -315,7 +351,7 @@ |
316 | 352 | $wgLang->timeanddate( $comment->timestamp ) . |
317 | 353 | '</div>' . |
318 | 354 | '<div class="mw-codereview-comment-text">' . |
319 | | - $wgOut->parse( $comment->text ) . |
| 355 | + $wgOut->parse( $linker->link( $comment->text ) ) . |
320 | 356 | '</div>' . |
321 | 357 | '</div>'; |
322 | 358 | } |