/** * Show diff * between current page version and provided $text * or between the revisions provided via GET or POST * * @author Andreas Gohr <*****@*****.**> * @param string $text when non-empty: compare with this text with most current version * @param bool $intro display the intro text * @param string $type type of the diff (inline or sidebyside) */ function html_diff($text = '', $intro = true, $type = null) { global $ID; global $REV; global $lang; global $INPUT; global $INFO; $pagelog = new PageChangeLog($ID); /* * Determine diff type */ if (!$type) { $type = $INPUT->str('difftype'); if (empty($type)) { $type = get_doku_pref('difftype', $type); if (empty($type) && $INFO['ismobile']) { $type = 'inline'; } } } 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. $rev1 = $REV; $rev2 = $INPUT->ref('rev2'); if (is_array($rev2)) { $rev1 = (int) $rev2[0]; $rev2 = (int) $rev2[1]; if (!$rev1) { $rev1 = $rev2; unset($rev2); } } else { $rev2 = $INPUT->int('rev2'); } /* * Determine left and right revision, its texts and the header */ $r_minor = ''; $l_minor = ''; if ($text) { // compare text to the most current revision $l_rev = ''; $l_text = rawWiki($ID, ''); $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' . $lang['current']; $r_rev = ''; $r_text = cleanText($text); $r_head = $lang['yours']; } else { if ($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted // make sure order is correct (older on the left) if ($rev1 < $rev2) { $l_rev = $rev1; $r_rev = $rev2; } else { $l_rev = $rev2; $r_rev = $rev1; } } elseif ($rev1) { // single revision given, compare to current $r_rev = ''; $l_rev = $rev1; } else { // no revision was given, compare previous to current $r_rev = ''; $revs = $pagelog->getRevisions(0, 1); $l_rev = $revs[0]; $REV = $l_rev; // store revision back in $REV } // when both revisions are empty then the page was created just now if (!$l_rev && !$r_rev) { $l_text = ''; } else { $l_text = rawWiki($ID, $l_rev); } $r_text = rawWiki($ID, $r_rev); list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline'); } /* * Build navigation */ $l_nav = ''; $r_nav = ''; if (!$text) { list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev); } /* * 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'); } /* * Display type and exact reference */ if (!$text) { ptln('<div class="diffoptions group">'); $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 echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']); ptln('</p>'); ptln('</div>'); // .diffoptions } /* * Display diff view table */ ?> <div class="table"> <table class="diff diff_<?php echo $type; ?> "> <?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 $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) { ?> <tr> <td colspan="2" class="diffnav"><?php echo $l_nav; ?> </td> <td colspan="2" class="diffnav"><?php echo $r_nav; ?> </td> </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 } //diff view echo html_insert_softbreaks($diffformatter->format($diff)); ?> </table> </div> <?php }
/** * show diff * * @author Andreas Gohr <*****@*****.**> * @param string $text - compare with this text with most current version * @param bool $intr - display the intro text */ 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. $rev1 = $REV; if (is_array($_REQUEST['rev2'])) { $rev1 = (int) $_REQUEST['rev2'][0]; $rev2 = (int) $_REQUEST['rev2'][1]; if (!$rev1) { $rev1 = $rev2; unset($rev2); } } else { $rev2 = (int) $_REQUEST['rev2']; } $r_minor = ''; $l_minor = ''; if ($text) { // compare text to the most current revision $l_rev = ''; $l_text = rawWiki($ID, ''); $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' . $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' . $lang['current']; $r_rev = ''; $r_text = cleanText($text); $r_head = $lang['yours']; } else { if ($rev1 && $rev2) { // two specific revisions wanted // make sure order is correct (older on the left) if ($rev1 < $rev2) { $l_rev = $rev1; $r_rev = $rev2; } else { $l_rev = $rev2; $r_rev = $rev1; } } elseif ($rev1) { // single revision given, compare to current $r_rev = ''; $l_rev = $rev1; } else { // no revision was given, compare previous to current $r_rev = ''; $revs = getRevisions($ID, 0, 1); $l_rev = $revs[0]; $REV = $l_rev; // store revision back in $REV } // when both revisions are empty then the page was created just now if (!$l_rev && !$r_rev) { $l_text = ''; } else { $l_text = rawWiki($ID, $l_rev); } $r_text = rawWiki($ID, $r_rev); list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev); } $df = new Diff(explode("\n", htmlspecialchars($l_text)), explode("\n", htmlspecialchars($r_text))); if ($type == 'inline') { $tdf = new InlineDiffFormatter(); } else { $tdf = new TableDiffFormatter(); } if ($intro) { print p_locale_xhtml('diff'); } 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(); $diffurl = wl($ID, array('do' => 'diff', 'rev2[0]' => $l_rev, 'rev2[1]' => $r_rev, 'difftype' => $type)); ptln('<p><a class="wikilink1" href="' . $diffurl . '">' . $lang['difflink'] . '</a></p>'); ptln('</div>'); } ?> <table class="diff diff_<?php echo $type; ?> "> <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 $tdf->format($df); ?> </table> <?php }
/** * Shows difference between two revisions of image * * @author Kate Arzamastseva <*****@*****.**> */ function media_file_diff($image, $l_rev, $r_rev, $ns, $auth, $fromajax) { global $lang; global $INPUT; $l_meta = new JpegMeta(mediaFN($image, $l_rev)); $r_meta = new JpegMeta(mediaFN($image, $r_rev)); $is_img = preg_match('/\\.(jpe?g|gif|png)$/', $image); if ($is_img) { $l_size = media_image_preview_size($image, $l_rev, $l_meta); $r_size = media_image_preview_size($image, $r_rev, $r_meta); $is_img = $l_size && $r_size && ($l_size[0] >= 30 || $r_size[0] >= 30); $difftype = $INPUT->str('difftype'); if (!$fromajax) { $form = new Doku_Form(array('action' => media_managerURL(array(), '&'), 'method' => 'get', 'id' => 'mediamanager__form_diffview', 'class' => 'diffView')); $form->addHidden('sectok', null); $form->addElement('<input type="hidden" name="rev2[]" value="' . $l_rev . '" ></input>'); $form->addElement('<input type="hidden" name="rev2[]" value="' . $r_rev . '" ></input>'); $form->addHidden('mediado', 'diff'); $form->printForm(); echo NL . '<div id="mediamanager__diff" >' . NL; } if ($difftype == 'opacity' || $difftype == 'portions') { media_image_diff($image, $l_rev, $r_rev, $l_size, $r_size, $difftype); if (!$fromajax) { echo '</div>'; } return; } } list($l_head, $r_head) = html_diff_head($l_rev, $r_rev, $image, true); ?> <div class="table"> <table> <tr> <th><?php echo $l_head; ?> </th> <th><?php echo $r_head; ?> </th> </tr> <?php echo '<tr class="image">'; echo '<td>'; media_preview($image, $auth, $l_rev, $l_meta); echo '</td>'; echo '<td>'; media_preview($image, $auth, $r_rev, $r_meta); echo '</td>'; echo '</tr>' . NL; echo '<tr class="actions">'; echo '<td>'; media_preview_buttons($image, $auth, $l_rev); echo '</td>'; echo '<td>'; media_preview_buttons($image, $auth, $r_rev); echo '</td>'; echo '</tr>' . NL; $l_tags = media_file_tags($l_meta); $r_tags = media_file_tags($r_meta); // FIXME r_tags-only stuff foreach ($l_tags as $key => $l_tag) { if ($l_tag['value'] != $r_tags[$key]['value']) { $r_tags[$key]['highlighted'] = true; $l_tags[$key]['highlighted'] = true; } else { if (!$l_tag['value'] || !$r_tags[$key]['value']) { unset($r_tags[$key]); unset($l_tags[$key]); } } } echo '<tr>'; foreach (array($l_tags, $r_tags) as $tags) { echo '<td>' . NL; echo '<dl class="img_tags">'; foreach ($tags as $tag) { $value = cleanText($tag['value']); if (!$value) { $value = '-'; } echo '<dt>' . $lang[$tag['tag'][1]] . '</dt>'; echo '<dd>'; if ($tag['highlighted']) { echo '<strong>'; } if ($tag['tag'][2] == 'date') { echo dformat($value); } else { echo hsc($value); } if ($tag['highlighted']) { echo '</strong>'; } echo '</dd>'; } echo '</dl>' . NL; echo '</td>'; } echo '</tr>' . NL; echo '</table>' . NL; echo '</div>' . NL; if ($is_img && !$fromajax) { echo '</div>'; } }