r94949 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94948‎ | r94949 | r94950 >
Date:21:28, 18 August 2011
Author:hashar
Status:ok (Comments)
Tags:
Comment:
converts diff view from <pre> to <tables>

The diff is now an HTML table with each diff lines converted from a
<span> to a table line. CSS has been altered to offer a rendering much
like the <pre> rendering with vector. Looks identical with Safari 5.1,
Opera 10.63, Firefox 5 & 3.5.
Modified paths:
  • /trunk/extensions/CodeReview/backend/DiffHighlighter.php (modified) (history)
  • /trunk/extensions/CodeReview/modules/ext.codereview.styles.css (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/DiffHighlighter.php
@@ -12,9 +12,9 @@
1313 * @return string
1414 */
1515 function render( $text ) {
16 - return '<pre class="mw-codereview-diff">' .
 16+ return '<table class="mw-codereview-diff">' .
1717 $this->splitLines( $text ) .
18 - "</pre>\n";
 18+ "</table>\n";
1919 }
2020
2121 /**
@@ -41,7 +41,7 @@
4242 return ""; // don't create bogus spans
4343 }
4444 list( $element, $attribs ) = $this->tagForLine( $line );
45 - return Xml::element( $element, $attribs, $line );
 45+ return "<tr>".Xml::element( $element, $attribs, $line )."</tr>";
4646 }
4747
4848 /**
@@ -50,12 +50,12 @@
5151 * @return array
5252 */
5353 function tagForLine( $line ) {
54 - static $default = array( 'span', array() );
 54+ static $default = array( 'td', array() );
5555 static $tags = array(
56 - '-' => array( 'del', array() ),
57 - '+' => array( 'ins', array() ),
58 - '@' => array( 'span', array( 'class' => 'meta' ) ),
59 - ' ' => array( 'span', array() ),
 56+ '-' => array( 'td', array( 'class' => 'del' ) ),
 57+ '+' => array( 'td', array( 'class' => 'ins' ) ),
 58+ '@' => array( 'td', array( 'class' => 'meta' ) ),
 59+ ' ' => array( 'td', array() ),
6060 );
6161 $first = substr( $line, 0, 1 );
6262 if ( isset( $tags[$first] ) ) {
Index: trunk/extensions/CodeReview/modules/ext.codereview.styles.css
@@ -131,15 +131,47 @@
132132 }
133133
134134 /* Diffs */
135 -.mw-codereview-diff pre {
 135+.mw-codereview-diff table {
136136 /* @noflip */direction: ltr; /* Source code is always LTR */
 137+
 138+ /* mimic MediaWiki <pre> style */
 139+ font-family: monospace, "Courer New";
 140+ line-height: 1.3em;
 141+ background-color: #F9F9F9;
 142+ border: 1px dashed #2F6FAB;
 143+ color: black;
 144+
 145+ /* fix up space between <tr> */
 146+ border-collapse: collapse;
137147 }
138 -.mw-codereview-diff ins {
 148+.mw-codereview-diff td {
 149+ margin:0;
 150+
 151+ /* keep padding on left and right just like <pre>
 152+ * top bottom paddings are defined below for first/last childs
 153+ */
 154+ padding:0 1em;
 155+
 156+ /* respect white spaces just like <pre> */
 157+ white-space: pre;
 158+}
 159+
 160+/* "table border-collapse: collapse;" overrides padding
 161+ * The two next rules mimic <pre> padding by applying one to the first
 162+ * and last childs
 163+ */
 164+.mw-codereview-diff tr:first-child td {
 165+ padding-top: 1em;
 166+}
 167+.mw-codereview-diff tr:last-child td {
 168+ padding-bottom: 1em;
 169+}
 170+
 171+.mw-codereview-diff td.ins {
139172 text-decoration: none;
140173 color: green;
141174 }
142 -
143 -.mw-codereview-diff del {
 175+.mw-codereview-diff td.del {
144176 text-decoration: none;
145177 color: red;
146178 }

Sign-offs

UserFlagDate
Nikerabbitinspected10:41, 21 September 2011

Comments

#Comment by Hashar (talk | contribs)   21:30, 18 August 2011

From there, we can probably start doing interesting stuff to the diff output :-)

Dedicated to Sumanah

Status & tagging log