Skip to content

Commit

Permalink
Make diff type selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Jan 31, 2011
1 parent c495dc4 commit 7216538
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
46 changes: 41 additions & 5 deletions inc/html.php
Expand Up @@ -870,13 +870,18 @@ function html_backlinks(){
* show diff
*
* @author Andreas Gohr <andi@splitbrain.org>
* @param string $text - compare with this text with most current version
* @param bool $intr - display the intro text
*/
function html_diff($text='',$intro=true){
function html_diff($text='',$intro=true,$type=null){
global $ID;
global $REV;
global $lang;
global $conf;

if(!$type) $type = $_REQUEST['difftype'];
if($type != 'inline') $type = 'sidebyside';

// we're trying to be clever here, revisions to compare can be either
// given as rev and rev2 parameters, with rev2 being optional. Or in an
// array in rev2.
Expand Down Expand Up @@ -993,17 +998,48 @@ function html_diff($text='',$intro=true){
$df = new Diff(explode("\n",htmlspecialchars($l_text)),
explode("\n",htmlspecialchars($r_text)));

$tdf = new TableDiffFormatter();
if($type == 'inline'){
$tdf = new InlineDiffFormatter();
} else {
$tdf = new TableDiffFormatter();
}



if($intro) print p_locale_xhtml('diff');

if (!$text) {
$diffurl = wl($ID, array('do'=>'diff', 'rev2[0]'=>$l_rev, 'rev2[1]'=>$r_rev));
ptln('<p class="difflink">');
ptln(' <a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a>');

$form = new Doku_Form(array('action'=>wl()));
$form->addHidden('ID',$ID);
$form->addHidden('rev2[0]',$l_rev);
$form->addHidden('rev2[1]',$r_rev);
$form->addHidden('do','diff');
$form->addElement(form_makeListboxField(
'difftype',
array(
'sidebyside' => $lang['diff_side'],
'inline' => $lang['diff_inline']),
$type,
$lang['diff_type'],
'','',
array('class'=>'quickselect')));
$form->addElement(form_makeButton('submit', 'diff','Go'));
$form->printForm();


$diffurl = wl($ID, array(
'do' => 'diff',
'rev2[0]' => $l_rev,
'rev2[1]' => $r_rev,
'difftype' => $type,
));
ptln('<br /><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a>');
ptln('</p>');
}
?>
<table class="diff">
<table class="diff diff_<?php echo $type?>">
<tr>
<th colspan="2" <?php echo $l_minor?>>
<?php echo $l_head?>
Expand Down
3 changes: 3 additions & 0 deletions inc/lang/en/lang.php
Expand Up @@ -164,6 +164,9 @@
$lang['diff'] = 'Show differences to current revisions';
$lang['diff2'] = 'Show differences between selected revisions';
$lang['difflink'] = 'Link to this comparison view';
$lang['diff_type'] = 'View differences:';
$lang['diff_inline']= 'Inline';
$lang['diff_side'] = 'Side by Side';
$lang['line'] = 'Line';
$lang['breadcrumb'] = 'Trace';
$lang['youarehere'] = 'You are here';
Expand Down
6 changes: 4 additions & 2 deletions lib/tpl/default/design.css
Expand Up @@ -652,10 +652,12 @@ div.dokuwiki table.diff td {
font-family: monospace;
font-size: 100%;
}
div.dokuwiki td.diff-addedline {
div.dokuwiki td.diff-addedline,
div.dokuwiki span.diff-addedline {
background-color: #ddffdd;
}
div.dokuwiki td.diff-deletedline {
div.dokuwiki td.diff-deletedline,
div.dokuwiki span.diff-deletedline {
background-color: #ffffbb;
}
div.dokuwiki td.diff-context {
Expand Down

0 comments on commit 7216538

Please sign in to comment.