Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -48,6 +48,9 @@ |
49 | 49 | $wgAutoloadClasses['CodeRepository'] = $dir . 'backend/CodeRepository.php'; |
50 | 50 | $wgAutoloadClasses['CodeRevision'] = $dir . 'backend/CodeRevision.php'; |
51 | 51 | $wgAutoloadClasses['CodeComment'] = $dir . 'backend/CodeComment.php'; |
| 52 | +$wgAutoloadClasses['CodeCommentLinker'] = $dir . 'backend/CodeCommentLinker.php'; |
| 53 | +$wgAutoloadClasses['CodeCommentLinkerHtml'] = $dir . 'backend/CodeCommentLinker.php'; |
| 54 | +$wgAutoloadClasses['CodeCommentLinkerWiki'] = $dir . 'backend/CodeCommentLinker.php'; |
52 | 55 | $wgAutoloadClasses['CodePropChange'] = $dir . 'backend/CodePropChange.php'; |
53 | 56 | $wgAutoloadClasses['CodeTestSuite'] = $dir . 'backend/CodeTestSuite.php'; |
54 | 57 | $wgAutoloadClasses['CodeTestRun'] = $dir . 'backend/CodeTestRun.php'; |
Index: trunk/extensions/CodeReview/backend/CodeCommentLinker.php |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class CodeCommentLinker { |
| 5 | + |
| 6 | + function __construct( $repo ) { |
| 7 | + global $wgUser; |
| 8 | + $this->mSkin = $wgUser->getSkin(); |
| 9 | + $this->mRepo = $repo; |
| 10 | + } |
| 11 | + |
| 12 | + function link( $text ) { |
| 13 | + # Catch links like http://www.mediawiki.org/wiki/Special:Code/MediaWiki/44245#c829 |
| 14 | + # Ended by space or brackets (like those pesky <br /> tags) |
| 15 | + $text = preg_replace_callback( '/(\b)(' . wfUrlProtocols() . ')([^ <>]+)(\b)/', array( $this, 'generalLink' ), $text ); |
| 16 | + $text = preg_replace_callback( '/\br(\d+)\b/', array( $this, 'messageRevLink' ), $text ); |
| 17 | + $text = preg_replace_callback( '/\bbug #?(\d+)\b/i', array( $this, 'messageBugLink' ), $text ); |
| 18 | + return $text; |
| 19 | + } |
| 20 | + |
| 21 | + function generalLink( $arr ) { |
| 22 | + $url = $arr[2] . $arr[3]; |
| 23 | + // Re-add the surrounding space/punctuation |
| 24 | + return $arr[1] . $this->makeExternalLink( $url, $url ) . $arr[4]; |
| 25 | + } |
| 26 | + |
| 27 | + function messageBugLink( $arr ) { |
| 28 | + $text = $arr[0]; |
| 29 | + $bugNo = intval( $arr[1] ); |
| 30 | + $url = $this->mRepo->getBugPath( $bugNo ); |
| 31 | + if ( $url ) { |
| 32 | + return $this->makeExternalLink( $url, $text ); |
| 33 | + } else { |
| 34 | + return $text; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + function messageRevLink( $matches ) { |
| 39 | + $text = $matches[0]; |
| 40 | + $rev = intval( $matches[1] ); |
| 41 | + |
| 42 | + $repo = $this->mRepo->getName(); |
| 43 | + $title = SpecialPage::getTitleFor( 'Code', "$repo/$rev" ); |
| 44 | + |
| 45 | + return $this->makeInternalLink( $title, $text ); |
| 46 | + } |
| 47 | + |
| 48 | + abstract function makeExternalLink( $url, $text ); |
| 49 | + |
| 50 | + abstract function makeInternalLink( $title, $text ); |
| 51 | +} |
| 52 | + |
| 53 | +class CodeCommentLinkerHtml extends CodeCommentLinker { |
| 54 | + function makeExternalLink( $url, $text ) { |
| 55 | + return $this->mSkin->makeExternalLink( $url, $text ); |
| 56 | + } |
| 57 | + |
| 58 | + function makeInternalLink( $title, $text ) { |
| 59 | + return $this->mSkin->link( $title, $text ); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +class CodeCommentLinkerWiki extends CodeCommentLinker { |
| 64 | + function makeExternalLink( $url, $text ) { |
| 65 | + return "[$url $text]"; |
| 66 | + } |
| 67 | + |
| 68 | + function makeInternalLink( $title, $text ) { |
| 69 | + return "[[" . $title->getPrefixedText() . "|$text]]"; |
| 70 | + } |
| 71 | +} |
Property changes on: trunk/extensions/CodeReview/backend/CodeCommentLinker.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 72 | + native |
Index: trunk/extensions/CodeReview/ui/SpecialCode.php |
— | — | @@ -213,68 +213,3 @@ |
214 | 214 | return $s; |
215 | 215 | } |
216 | 216 | } |
217 | | - |
218 | | -class CodeCommentLinker { |
219 | | - function __construct( $repo ) { |
220 | | - global $wgUser; |
221 | | - $this->mSkin = $wgUser->getSkin(); |
222 | | - $this->mRepo = $repo; |
223 | | - } |
224 | | - |
225 | | - function link( $text ) { |
226 | | - # Catch links like http://www.mediawiki.org/wiki/Special:Code/MediaWiki/44245#c829 |
227 | | - # Ended by space or brackets (like those pesky <br /> tags) |
228 | | - $text = preg_replace_callback( '/(\b)(' . wfUrlProtocols() . ')([^ <>]+)(\b)/', array( $this, 'generalLink' ), $text ); |
229 | | - $text = preg_replace_callback( '/\br(\d+)\b/', array( $this, 'messageRevLink' ), $text ); |
230 | | - $text = preg_replace_callback( '/\bbug #?(\d+)\b/i', array( $this, 'messageBugLink' ), $text ); |
231 | | - return $text; |
232 | | - } |
233 | | - |
234 | | - function generalLink( $arr ) { |
235 | | - $url = $arr[2] . $arr[3]; |
236 | | - // Re-add the surrounding space/punctuation |
237 | | - return $arr[1] . $this->makeExternalLink( $url, $url ) . $arr[4]; |
238 | | - } |
239 | | - |
240 | | - function messageBugLink( $arr ) { |
241 | | - $text = $arr[0]; |
242 | | - $bugNo = intval( $arr[1] ); |
243 | | - $url = $this->mRepo->getBugPath( $bugNo ); |
244 | | - if ( $url ) { |
245 | | - return $this->makeExternalLink( $url, $text ); |
246 | | - } else { |
247 | | - return $text; |
248 | | - } |
249 | | - } |
250 | | - |
251 | | - function messageRevLink( $matches ) { |
252 | | - $text = $matches[0]; |
253 | | - $rev = intval( $matches[1] ); |
254 | | - |
255 | | - $repo = $this->mRepo->getName(); |
256 | | - $title = SpecialPage::getTitleFor( 'Code', "$repo/$rev" ); |
257 | | - |
258 | | - return $this->makeInternalLink( $title, $text ); |
259 | | - } |
260 | | - |
261 | | -} |
262 | | - |
263 | | -class CodeCommentLinkerHtml extends CodeCommentLinker { |
264 | | - function makeExternalLink( $url, $text ) { |
265 | | - return $this->mSkin->makeExternalLink( $url, $text ); |
266 | | - } |
267 | | - |
268 | | - function makeInternalLink( $title, $text ) { |
269 | | - return $this->mSkin->link( $title, $text ); |
270 | | - } |
271 | | -} |
272 | | - |
273 | | -class CodeCommentLinkerWiki extends CodeCommentLinker { |
274 | | - function makeExternalLink( $url, $text ) { |
275 | | - return "[$url $text]"; |
276 | | - } |
277 | | - |
278 | | - function makeInternalLink( $title, $text ) { |
279 | | - return "[[" . $title->getPrefixedText() . "|$text]]"; |
280 | | - } |
281 | | -} |