Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | |
40 | 40 | $dir = dirname(__FILE__) . '/'; |
41 | 41 | |
| 42 | +$wgAutoloadClasses['CodeDiffHighlighter'] = $dir . 'DiffHighlighter.php'; |
42 | 43 | $wgAutoloadClasses['CodeRepository'] = $dir . 'CodeRepository.php'; |
43 | 44 | $wgAutoloadClasses['CodeRepoListView'] = $dir . 'CodeRepoListView.php'; |
44 | 45 | $wgAutoloadClasses['CodeRevision'] = $dir . 'CodeRevision.php'; |
Index: trunk/extensions/CodeReview/codereview.css |
— | — | @@ -46,3 +46,18 @@ |
47 | 47 | .mw-codereview-status-resolved:hover td { |
48 | 48 | background: #a0dfa0 !important;; |
49 | 49 | } |
| 50 | + |
| 51 | +/* Diffs */ |
| 52 | +.mw-codereview-diff ins { |
| 53 | + text-decoration: none; |
| 54 | + color: green; |
| 55 | +} |
| 56 | + |
| 57 | +.mw-codereview-diff del { |
| 58 | + text-decoration: none; |
| 59 | + color: red; |
| 60 | +} |
| 61 | + |
| 62 | +.mw-codereview-diff .meta { |
| 63 | + color: darkcyan; |
| 64 | +} |
Index: trunk/extensions/CodeReview/CodeRevisionView.php |
— | — | @@ -234,7 +234,8 @@ |
235 | 235 | if( !$diff ) { |
236 | 236 | return false; |
237 | 237 | } |
238 | | - return "<pre>" . htmlspecialchars( $diff ) . "</pre>"; |
| 238 | + $hilite = new CodeDiffHighlighter(); |
| 239 | + return $hilite->render( $diff ); |
239 | 240 | } |
240 | 241 | |
241 | 242 | function formatComments() { |
Index: trunk/extensions/CodeReview/DiffHighlighter.php |
— | — | @@ -0,0 +1,36 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class CodeDiffHighlighter { |
| 5 | + function render( $text ) { |
| 6 | + return '<pre class="mw-codereview-diff">' . |
| 7 | + $this->splitLines( $text ) . |
| 8 | + "</pre>\n"; |
| 9 | + } |
| 10 | + |
| 11 | + function splitLines( $text ) { |
| 12 | + return implode( "\n", |
| 13 | + array_map( array( $this, 'colorLine' ), |
| 14 | + explode( "\n", $text ) ) ); |
| 15 | + } |
| 16 | + |
| 17 | + function colorLine( $line ) { |
| 18 | + list( $element, $attribs ) = $this->tagForLine( $line ); |
| 19 | + return Xml::element( $element, $attribs, $line ); |
| 20 | + } |
| 21 | + |
| 22 | + function tagForLine( $line ) { |
| 23 | + static $default = array( 'span', array() ); |
| 24 | + static $tags = array( |
| 25 | + '-' => array( 'del', array() ), |
| 26 | + '+' => array( 'ins', array() ), |
| 27 | + '@' => array( 'span', array( 'class' => 'meta' ) ), |
| 28 | + ' ' => array( 'span', array() ), |
| 29 | + ); |
| 30 | + $first = substr( $line, 0, 1 ); |
| 31 | + if( isset( $tags[$first] ) ) |
| 32 | + return $tags[$first]; |
| 33 | + else |
| 34 | + return $default; |
| 35 | + } |
| 36 | + |
| 37 | +} |
Property changes on: trunk/extensions/CodeReview/DiffHighlighter.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 38 | + native |