Make WordPress Core

Ticket #9467: diff.update.patch

File diff.update.patch, 8.6 KB (added by simek, 16 years ago)
  • wp-includes/Text/Diff.php

     
    66 * The original PHP version of this code was written by Geoffrey T. Dairiki
    77 * <dairiki@dairiki.org>, and is used/adapted with his permission.
    88 *
    9  * $Horde: framework/Text_Diff/Diff.php,v 1.26 2008/01/04 10:07:49 jan Exp $
     9 * $Horde: framework/Text_Diff/Diff.php,v 1.27 2008/02/24 10:46:46 jan Exp $
    1010 *
    1111 * Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org>
    12  * Copyright 2004-2008 The Horde Project (http://www.horde.org/)
     12 * Copyright 2004-2009 The Horde Project (http://www.horde.org/)
    1313 *
    1414 * See the enclosed file COPYING for license information (LGPL). If you did
    1515 * not receive this file, see http://opensource.org/licenses/lgpl-license.php.
     
    4848        } else {
    4949            $engine = basename($engine);
    5050        }
    51 
    52         // WP #7391
     51               
     52        // WP path fix
    5353        require_once dirname(__FILE__).'/Diff/Engine/' . $engine . '.php';
    5454        $class = 'Text_Diff_Engine_' . $engine;
    5555        $diff_engine = new $class();
     
    6464    {
    6565        return $this->_edits;
    6666    }
     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    }
    67107
    68108    /**
    69109     * Computes a reversed diff.
  • wp-includes/Text/Diff/Engine/native.php

     
    11<?php
    22/**
    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.
    44 *
    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.
    76 *
    87 * The algorithm used here is mostly lifted from the perl module
    98 * Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
     
    1918 * Geoffrey T. Dairiki <dairiki@dairiki.org>. The original PHP version of this
    2019 * code was written by him, and is used/adapted with his permission.
    2120 *
    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 $
    2322 *
     23 * Copyright 2004-2009 The Horde Project (http://www.horde.org/)
     24 *
    2425 * See the enclosed file COPYING for license information (LGPL). If you did
    2526 * not receive this file, see http://opensource.org/licenses/lgpl-license.php.
    2627 *
  • wp-includes/Text/Diff/Engine/string.php

     
    1010 * echo $renderer->render($diff);
    1111 * </code>
    1212 *
    13  * $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.7 2008/01/04 10:07:50 jan Exp $
     13 * $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.9 2008/09/10 08:13:43 jan Exp $
    1414 *
    1515 * Copyright 2005 Örjan Persson <o@42mm.org>
    16  * Copyright 2005-2008 The Horde Project (http://www.horde.org/)
     16 * Copyright 2005-2009 The Horde Project (http://www.horde.org/)
    1717 *
    1818 * See the enclosed file COPYING for license information (LGPL). If you did
    1919 * not receive this file, see http://opensource.org/licenses/lgpl-license.php.
     
    4848            $unified = strpos($diff, '---');
    4949            if ($context === $unified) {
    5050                return PEAR::raiseError('Type of diff could not be detected');
    51             } elseif ($context === false || $context === false) {
     51            } elseif ($context === false || $unified === false) {
    5252                $mode = $context !== false ? 'context' : 'unified';
    5353            } else {
    5454                $mode = $context < $unified ? 'context' : 'unified';
    5555            }
    5656        }
    5757
    58         // split by new line and remove the diff header
     58        // Split by new line and remove the diff header, if there is one.
    5959        $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        }
    6265
    6366        if ($mode == 'context') {
    6467            return $this->parseContextDiff($diff);
     
    8588                do {
    8689                    $diff1[] = substr($diff[$i], 1);
    8790                } while (++$i < $end && substr($diff[$i], 0, 1) == ' ');
    88                 $edits[] = &new Text_Diff_Op_copy($diff1);
     91                $edits[] = new Text_Diff_Op_copy($diff1);
    8992                break;
    9093
    9194            case '+':
     
    9396                do {
    9497                    $diff1[] = substr($diff[$i], 1);
    9598                } while (++$i < $end && substr($diff[$i], 0, 1) == '+');
    96                 $edits[] = &new Text_Diff_Op_add($diff1);
     99                $edits[] = new Text_Diff_Op_add($diff1);
    97100                break;
    98101
    99102            case '-':
     
    107110                    $diff2[] = substr($diff[$i++], 1);
    108111                }
    109112                if (count($diff2) == 0) {
    110                     $edits[] = &new Text_Diff_Op_delete($diff1);
     113                    $edits[] = new Text_Diff_Op_delete($diff1);
    111114                } else {
    112                     $edits[] = &new Text_Diff_Op_change($diff1, $diff2);
     115                    $edits[] = new Text_Diff_Op_change($diff1, $diff2);
    113116                }
    114117                break;
    115118
     
    175178                $array[] = substr($diff[$j++], 2);
    176179            }
    177180            if (count($array) > 0) {
    178                 $edits[] = &new Text_Diff_Op_copy($array);
     181                $edits[] = new Text_Diff_Op_copy($array);
    179182            }
    180183
    181184            if ($i < $max_i) {
     
    189192                            $diff2[] = substr($diff[$j++], 2);
    190193                        }
    191194                    } 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);
    193196                    break;
    194197
    195198                case '+':
    196199                    do {
    197200                        $diff1[] = substr($diff[$i], 2);
    198201                    } 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);
    200203                    break;
    201204
    202205                case '-':
    203206                    do {
    204207                        $diff1[] = substr($diff[$i], 2);
    205208                    } 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);
    207210                    break;
    208211                }
    209212            }
     
    215218                    do {
    216219                        $diff2[] = substr($diff[$j++], 2);
    217220                    } 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);
    219222                    break;
    220223
    221224                case '-':
    222225                    do {
    223226                        $diff2[] = substr($diff[$j++], 2);
    224227                    } 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);
    226229                    break;
    227230                }
    228231            }