Ticket #9467: diff.update.patch
File diff.update.patch, 8.6 KB (added by , 16 years ago) |
---|
-
wp-includes/Text/Diff.php
6 6 * The original PHP version of this code was written by Geoffrey T. Dairiki 7 7 * <dairiki@dairiki.org>, and is used/adapted with his permission. 8 8 * 9 * $Horde: framework/Text_Diff/Diff.php,v 1.2 6 2008/01/04 10:07:49jan Exp $9 * $Horde: framework/Text_Diff/Diff.php,v 1.27 2008/02/24 10:46:46 jan Exp $ 10 10 * 11 11 * Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org> 12 * Copyright 2004-200 8The Horde Project (http://www.horde.org/)12 * Copyright 2004-2009 The Horde Project (http://www.horde.org/) 13 13 * 14 14 * See the enclosed file COPYING for license information (LGPL). If you did 15 15 * not receive this file, see http://opensource.org/licenses/lgpl-license.php. … … 48 48 } else { 49 49 $engine = basename($engine); 50 50 } 51 52 // WP #739151 52 // WP path fix 53 53 require_once dirname(__FILE__).'/Diff/Engine/' . $engine . '.php'; 54 54 $class = 'Text_Diff_Engine_' . $engine; 55 55 $diff_engine = new $class(); … … 64 64 { 65 65 return $this->_edits; 66 66 } 67 68 /** 69 * returns the number of new (added) lines in a given diff. 70 * 71 * @since Text_Diff 1.1.0 72 * @since Horde 3.2 73 * 74 * @return integer The number of new lines 75 */ 76 function countAddedLines() 77 { 78 $count = 0; 79 foreach ($this->_edits as $edit) { 80 if (is_a($edit, 'Text_Diff_Op_add') || 81 is_a($edit, 'Text_Diff_Op_change')) { 82 $count += $edit->nfinal(); 83 } 84 } 85 return $count; 86 } 87 88 /** 89 * Returns the number of deleted (removed) lines in a given diff. 90 * 91 * @since Text_Diff 1.1.0 92 * @since Horde 3.2 93 * 94 * @return integer The number of deleted lines 95 */ 96 function countDeletedLines() 97 { 98 $count = 0; 99 foreach ($this->_edits as $edit) { 100 if (is_a($edit, 'Text_Diff_Op_delete') || 101 is_a($edit, 'Text_Diff_Op_change')) { 102 $count += $edit->norig(); 103 } 104 } 105 return $count; 106 } 67 107 68 108 /** 69 109 * Computes a reversed diff. -
wp-includes/Text/Diff/Engine/native.php
1 1 <?php 2 2 /** 3 * $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.10 2008/01/04 10:27:53 jan Exp $3 * Class used internally by Text_Diff to actually compute the diffs. 4 4 * 5 * Class used internally by Text_Diff to actually compute the diffs. This 6 * class is implemented using native PHP code. 5 * This class is implemented using native PHP code. 7 6 * 8 7 * The algorithm used here is mostly lifted from the perl module 9 8 * Algorithm::Diff (version 1.06) by Ned Konz, which is available at: … … 19 18 * Geoffrey T. Dairiki <dairiki@dairiki.org>. The original PHP version of this 20 19 * code was written by him, and is used/adapted with his permission. 21 20 * 22 * Copyright 2004-2008 The Horde Project (http://www.horde.org/)21 * $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.11 2008/09/10 08:34:37 jan Exp $ 23 22 * 23 * Copyright 2004-2009 The Horde Project (http://www.horde.org/) 24 * 24 25 * See the enclosed file COPYING for license information (LGPL). If you did 25 26 * not receive this file, see http://opensource.org/licenses/lgpl-license.php. 26 27 * -
wp-includes/Text/Diff/Engine/string.php
10 10 * echo $renderer->render($diff); 11 11 * </code> 12 12 * 13 * $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1. 7 2008/01/04 10:07:50jan Exp $13 * $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.9 2008/09/10 08:13:43 jan Exp $ 14 14 * 15 15 * Copyright 2005 Örjan Persson <o@42mm.org> 16 * Copyright 2005-200 8The Horde Project (http://www.horde.org/)16 * Copyright 2005-2009 The Horde Project (http://www.horde.org/) 17 17 * 18 18 * See the enclosed file COPYING for license information (LGPL). If you did 19 19 * not receive this file, see http://opensource.org/licenses/lgpl-license.php. … … 48 48 $unified = strpos($diff, '---'); 49 49 if ($context === $unified) { 50 50 return PEAR::raiseError('Type of diff could not be detected'); 51 } elseif ($context === false || $ context=== false) {51 } elseif ($context === false || $unified === false) { 52 52 $mode = $context !== false ? 'context' : 'unified'; 53 53 } else { 54 54 $mode = $context < $unified ? 'context' : 'unified'; 55 55 } 56 56 } 57 57 58 // split by new line and remove the diff header58 // Split by new line and remove the diff header, if there is one. 59 59 $diff = explode("\n", $diff); 60 array_shift($diff); 61 array_shift($diff); 60 if (($mode == 'context' && strpos($diff[0], '***') === 0) || 61 ($mode == 'unified' && strpos($diff[0], '---') === 0)) { 62 array_shift($diff); 63 array_shift($diff); 64 } 62 65 63 66 if ($mode == 'context') { 64 67 return $this->parseContextDiff($diff); … … 85 88 do { 86 89 $diff1[] = substr($diff[$i], 1); 87 90 } while (++$i < $end && substr($diff[$i], 0, 1) == ' '); 88 $edits[] = &new Text_Diff_Op_copy($diff1);91 $edits[] = new Text_Diff_Op_copy($diff1); 89 92 break; 90 93 91 94 case '+': … … 93 96 do { 94 97 $diff1[] = substr($diff[$i], 1); 95 98 } while (++$i < $end && substr($diff[$i], 0, 1) == '+'); 96 $edits[] = &new Text_Diff_Op_add($diff1);99 $edits[] = new Text_Diff_Op_add($diff1); 97 100 break; 98 101 99 102 case '-': … … 107 110 $diff2[] = substr($diff[$i++], 1); 108 111 } 109 112 if (count($diff2) == 0) { 110 $edits[] = &new Text_Diff_Op_delete($diff1);113 $edits[] = new Text_Diff_Op_delete($diff1); 111 114 } else { 112 $edits[] = &new Text_Diff_Op_change($diff1, $diff2);115 $edits[] = new Text_Diff_Op_change($diff1, $diff2); 113 116 } 114 117 break; 115 118 … … 175 178 $array[] = substr($diff[$j++], 2); 176 179 } 177 180 if (count($array) > 0) { 178 $edits[] = &new Text_Diff_Op_copy($array);181 $edits[] = new Text_Diff_Op_copy($array); 179 182 } 180 183 181 184 if ($i < $max_i) { … … 189 192 $diff2[] = substr($diff[$j++], 2); 190 193 } 191 194 } while (++$i < $max_i && substr($diff[$i], 0, 1) == '!'); 192 $edits[] = &new Text_Diff_Op_change($diff1, $diff2);195 $edits[] = new Text_Diff_Op_change($diff1, $diff2); 193 196 break; 194 197 195 198 case '+': 196 199 do { 197 200 $diff1[] = substr($diff[$i], 2); 198 201 } while (++$i < $max_i && substr($diff[$i], 0, 1) == '+'); 199 $edits[] = &new Text_Diff_Op_add($diff1);202 $edits[] = new Text_Diff_Op_add($diff1); 200 203 break; 201 204 202 205 case '-': 203 206 do { 204 207 $diff1[] = substr($diff[$i], 2); 205 208 } while (++$i < $max_i && substr($diff[$i], 0, 1) == '-'); 206 $edits[] = &new Text_Diff_Op_delete($diff1);209 $edits[] = new Text_Diff_Op_delete($diff1); 207 210 break; 208 211 } 209 212 } … … 215 218 do { 216 219 $diff2[] = substr($diff[$j++], 2); 217 220 } while ($j < $max_j && substr($diff[$j], 0, 1) == '+'); 218 $edits[] = &new Text_Diff_Op_add($diff2);221 $edits[] = new Text_Diff_Op_add($diff2); 219 222 break; 220 223 221 224 case '-': 222 225 do { 223 226 $diff2[] = substr($diff[$j++], 2); 224 227 } while ($j < $max_j && substr($diff[$j], 0, 1) == '-'); 225 $edits[] = &new Text_Diff_Op_delete($diff2);228 $edits[] = new Text_Diff_Op_delete($diff2); 226 229 break; 227 230 } 228 231 }