r41212 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41211‎ | r41212 | r41213 >
Date:01:00, 24 September 2008
Author:brion
Status:old
Tags:
Comment:
Style the diffs a bit
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/CodeRevisionView.php (modified) (history)
  • /trunk/extensions/CodeReview/DiffHighlighter.php (added) (history)
  • /trunk/extensions/CodeReview/codereview.css (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -38,6 +38,7 @@
3939
4040 $dir = dirname(__FILE__) . '/';
4141
 42+$wgAutoloadClasses['CodeDiffHighlighter'] = $dir . 'DiffHighlighter.php';
4243 $wgAutoloadClasses['CodeRepository'] = $dir . 'CodeRepository.php';
4344 $wgAutoloadClasses['CodeRepoListView'] = $dir . 'CodeRepoListView.php';
4445 $wgAutoloadClasses['CodeRevision'] = $dir . 'CodeRevision.php';
Index: trunk/extensions/CodeReview/codereview.css
@@ -46,3 +46,18 @@
4747 .mw-codereview-status-resolved:hover td {
4848 background: #a0dfa0 !important;;
4949 }
 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 @@
235235 if( !$diff ) {
236236 return false;
237237 }
238 - return "<pre>" . htmlspecialchars( $diff ) . "</pre>";
 238+ $hilite = new CodeDiffHighlighter();
 239+ return $hilite->render( $diff );
239240 }
240241
241242 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
138 + native

Status & tagging log