diff --git a/inc/html.php b/inc/html.php index fb44cd655371f60ea45bc1e87bf556384fc277b0..cda971f3d6388df101df54813b59147530f4dd2e 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1095,6 +1095,9 @@ function html_diff($text = '', $intro = true, $type = null) { global $INFO; $pagelog = new PageChangeLog($ID); + /* + * Determine diff type + */ if(!$type) { $type = $INPUT->str('difftype'); if(empty($type)) { @@ -1106,6 +1109,9 @@ function html_diff($text = '', $intro = true, $type = null) { } if($type != 'inline') $type = 'sidebyside'; + /* + * Determine requested revision(s) + */ // 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. @@ -1124,6 +1130,9 @@ function html_diff($text = '', $intro = true, $type = null) { $rev2 = $INPUT->int('rev2'); } + /* + * Determine left and right revision, its texts and the header + */ $r_minor = ''; $l_minor = ''; @@ -1168,58 +1177,14 @@ function html_diff($text = '', $intro = true, $type = null) { list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline'); } - $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text)); - - if($type == 'inline') { - $diffformatter = new InlineDiffFormatter(); - } else { - $diffformatter = new TableDiffFormatter(); - } - - if($intro) print p_locale_xhtml('diff'); - - if(!$text) { - ptln('<div class="diffoptions">'); - - /* - * display type and exact reference - */ - $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(); - - ptln('<p>'); - // link to exactly this view FS#2835 - html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']); - ptln('</p>'); - - ptln('</div>'); // .diffoptions - } - + /* + * Build navigation + */ $l_nav = ''; $r_nav = ''; if(!$text) { - /* - * Revisions navigation - */ $r_rev = $r_rev ? $r_rev : $INFO['meta']['last_change']['date']; //last timestamp is not in changelog + //retrieve revisions with additional info list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev); $l_revisions = array(); foreach($l_revs as $rev) { @@ -1247,13 +1212,13 @@ function html_diff($text = '', $intro = true, $type = null) { $r_prev = $r_revs[$r_index + 1]; $r_next = $r_revs[$r_index - 1]; - + //Left side: //move back if($l_prev) { $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev); $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev); } - //left dropdown + //dropdown $form = new Doku_Form(array('action' => wl())); $form->addHidden('id', $ID); $form->addHidden('difftype', $type); @@ -1275,11 +1240,12 @@ function html_diff($text = '', $intro = true, $type = null) { $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev); } + //Right side: //move back if($l_rev < $r_prev) { $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev); } - //rigth dropdown + //dropdown $form = new Doku_Form(array('action' => wl())); $form->addHidden('id', $ID); $form->addHidden('rev2[0]', $l_rev); @@ -1306,54 +1272,109 @@ function html_diff($text = '', $intro = true, $type = null) { $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next); } } + /* + * Create diff object and the formatter + */ + $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text)); + + if($type == 'inline') { + $diffformatter = new InlineDiffFormatter(); + } else { + $diffformatter = new TableDiffFormatter(); + } + /* + * Display intro + */ + if($intro) print p_locale_xhtml('diff'); /* - * Diff view + * Display type and exact reference + */ + if(!$text) { + ptln('<div class="diffoptions">'); + + + $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(); + + ptln('<p>'); + // link to exactly this view FS#2835 + html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['lastmod']); + ptln('</p>'); + + ptln('</div>'); // .diffoptions + } + + /* + * Display diff view table */ ?> <div class="table"> <table class="diff diff_<?php echo $type ?>"> - <?php - if($type == 'inline') { - if(!$text) { ?> + + <?php + //navigation and header + if($type == 'inline') { + if(!$text) { ?> + <tr> + <td class="diff-lineheader">-</td> + <td class="diffnav"><?php echo $l_nav ?></td> + </tr> + <tr> + <th class="diff-lineheader">-</th> + <th <?php echo $l_minor ?>> + <?php echo $l_head ?> + </th> + </tr> + <?php } ?> <tr> - <td class="diff-lineheader">-</td> - <td class="diffnav"><?php echo $l_nav ?></td> + <td class="diff-lineheader">+</td> + <td class="diffnav"><?php echo $r_nav ?></td> </tr> <tr> - <th class="diff-lineheader">-</th> - <th <?php echo $l_minor ?>> - <?php echo $l_head ?> + <th class="diff-lineheader">+</th> + <th <?php echo $r_minor ?>> + <?php echo $r_head ?> </th> </tr> - <?php } ?> - <tr> - <td class="diff-lineheader">+</td> - <td class="diffnav"><?php echo $r_nav ?></td> - </tr> - <tr> - <th class="diff-lineheader">+</th> - <th <?php echo $r_minor ?>> - <?php echo $r_head ?> - </th> - </tr> - <?php } else { - if(!$text) { ?> + <?php } else { + if(!$text) { ?> + <tr> + <td colspan="2" class="diffnav"><?php echo $l_nav ?></td> + <td colspan="2" class="diffnav"><?php echo $r_nav ?></td> + </tr> + <?php } ?> <tr> - <td colspan="2" class="diffnav"><?php echo $l_nav ?></td> - <td colspan="2" class="diffnav"><?php echo $r_nav ?></td> + <th colspan="2" <?php echo $l_minor ?>> + <?php echo $l_head ?> + </th> + <th colspan="2" <?php echo $r_minor ?>> + <?php echo $r_head ?> + </th> </tr> - <?php } ?> - <tr> - <th colspan="2" <?php echo $l_minor ?>> - <?php echo $l_head ?> - </th> - <th colspan="2" <?php echo $r_minor ?>> - <?php echo $r_head ?> - </th> - </tr> - <?php } - echo html_insert_softbreaks($diffformatter->format($diff)); ?> + <?php } + + //diff view + echo html_insert_softbreaks($diffformatter->format($diff)); ?> + </table> </div> <?php