diff options
author | petko <petko@524c5546-5005-0410-9a3e-e25e191bd360> | 2024-01-21 22:02:04 +0000 |
---|---|---|
committer | petko <petko@524c5546-5005-0410-9a3e-e25e191bd360> | 2024-01-21 22:02:04 +0000 |
commit | 55be94cb38178f614dcb8288e2a2e1077e7428d7 (patch) | |
tree | c440bf4f597ae37824a1f00f9c709ce846a3ca09 /scripts/pagerev.php | |
parent | ba218518df70a3f0eb773646ca866e3b426be5a0 (diff) | |
download | pmwiki.svn-55be94cb38178f614dcb8288e2a2e1077e7428d7.tar.bz2 |
Improved lisibility for inline diffs in page history.
git-svn-id: svn://pmwiki.org/pmwiki/trunk@4596 524c5546-5005-0410-9a3e-e25e191bd360
Diffstat (limited to 'scripts/pagerev.php')
-rw-r--r-- | scripts/pagerev.php | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/scripts/pagerev.php b/scripts/pagerev.php index e5df12ab..b2e00909 100644 --- a/scripts/pagerev.php +++ b/scripts/pagerev.php @@ -1,5 +1,5 @@ <?php if (!defined('PmWiki')) exit(); -/* Copyright 2004-2022 Patrick R. Michaud (pmichaud@pobox.com) +/* Copyright 2004-2024 Patrick R. Michaud (pmichaud@pobox.com) This file is part of PmWiki; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -217,19 +217,20 @@ function DiffRenderSource($in, $out, $which) { $countdifflines = abs(count($in)-count($out)); $lines = $cnt = $x2 = $y2 = array(); foreach($in as $line) { - $tmp = $countdifflines>20 ? array($line) : $DiffPrepareInlineFunction($line); + $tmp = $DiffPrepareInlineFunction($line); if (!$which) $cnt[] = array(count($x2), count($tmp)); $x2 = array_merge($x2, $tmp); } foreach($out as $line) { - $tmp = $countdifflines>20 ? array($line) : $DiffPrepareInlineFunction($line); + $tmp = $DiffPrepareInlineFunction($line); if ($which) $cnt[] = array(count($y2), count($tmp)); $y2 = array_merge($y2, $tmp); } $z = $WordDiffFunction(implode("\n", $x2), implode("\n", $y2)); - + + array_unshift($x2, ''); + array_unshift($y2, ''); $z2 = array_map('PHSC', ($which? $y2 : $x2)); - array_unshift($z2, ''); foreach (explode("\n", $z) as $zz) { if (preg_match('/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/',$zz,$m)) { $a1 = $a2 = $m[1]; @@ -245,6 +246,15 @@ function DiffRenderSource($in, $out, $which) { $z2[$b1] = '<ins>'.$z2[$b1]; $z2[$b2] .= '</ins>'; } + if ($m[4]=='c') { + $xx = PHSC(strval(@$x2[$a1])); + $yy = PHSC(strval(@$y2[$b1])); + $tmp = "<del>$xx<ins>$yy"; + if (preg_match("/^<del>([\x09\x20-\x7e]+).*<ins>\\1/", $tmp, $m)) { + if(!$which && @$z2[$a1]) $z2[$a1] = $m[1] . "<del>" . substr($z2[$a1], strlen($m[1])+5); + if($which && @$z2[$b1]) $z2[$b1] = $m[1] . "<ins>" . substr($z2[$b1], strlen($m[1])+5); + } + } } } $line = array_shift($z2); @@ -275,8 +285,9 @@ function cb_diffsplit($m) { function DiffPrepareInline($x) { global $DiffSplitInlineDelims; SDV($DiffSplitInlineDelims, "-@!?#$%^&*()=+[]{}.'\"\\:|,<>_/;~"); - return preg_split("/([".preg_quote($DiffSplitInlineDelims, '/')."\\s])/", - "$x ", -1, PREG_SPLIT_DELIM_CAPTURE); + $quoted = preg_quote($DiffSplitInlineDelims, '/'); + preg_match_all("/^\\s+|[$quoted]|[^$quoted\\s]+\\s*|\\s+/", $x, $m); + return $m[0]; } SDV($WordDiffFunction, 'PHPDiff'); # faster than sysdiff for many calls |