WordPress.org

Make WordPress Core

Ticket #11648: 11648.2.patch

File 11648.2.patch, 11.7 KB (added by hakre, 6 years ago)
  • wp-includes/Text/Diff.php

    ### Eclipse Workspace Patch 1.0
    #P wordpress-trunk
     
    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.11.2.11 2008/02/24 10:57:46 jan Exp $ 
    1010 * 
    1111 * Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org> 
    1212 * Copyright 2004-2008 The Horde Project (http://www.horde.org/) 
     
    5252        // WP #7391 
    5353        require_once dirname(__FILE__).'/Diff/Engine/' . $engine . '.php'; 
    5454        $class = 'Text_Diff_Engine_' . $engine; 
    55         $diff_engine = new $class(); 
     55        $diff_engine =& new $class(); 
    5656 
    5757        $this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params); 
    5858    } 
     
    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/xdiff.php

     
    55 * This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff) 
    66 * to compute the differences between the two input arrays. 
    77 * 
    8  * $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.6 2008/01/04 10:07:50 jan Exp $ 
     8 * $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.4.2.3 2008/01/04 10:37:27 jan Exp $ 
    99 * 
    1010 * Copyright 2004-2008 The Horde Project (http://www.horde.org/) 
    1111 * 
  • wp-includes/Text/Diff/Engine/shell.php

     
    55 * This class uses the Unix `diff` program via shell_exec to compute the 
    66 * differences between the two input arrays. 
    77 * 
    8  * $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.8 2008/01/04 10:07:50 jan Exp $ 
     8 * $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.6.2.3 2008/01/04 10:37:27 jan Exp $ 
    99 * 
    1010 * Copyright 2007-2008 The Horde Project (http://www.horde.org/) 
    1111 * 
  • wp-includes/Text/Diff/Renderer.php

     
    55 * This class renders the diff in classic diff format. It is intended that 
    66 * this class be customized via inheritance, to obtain fancier outputs. 
    77 * 
    8  * $Horde: framework/Text_Diff/Diff/Renderer.php,v 1.21 2008/01/04 10:07:50 jan Exp $ 
     8 * $Horde: framework/Text_Diff/Diff/Renderer.php,v 1.5.10.10 2008/01/04 10:37:27 jan Exp $ 
    99 * 
    1010 * Copyright 2004-2008 The Horde Project (http://www.horde.org/) 
    1111 * 
  • 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 * 
     21 * $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.7.2.4 2008/01/04 10:38:10 jan Exp $ 
     22 * 
    2223 * Copyright 2004-2008 The Horde Project (http://www.horde.org/) 
    2324 * 
    2425 * See the enclosed file COPYING for license information (LGPL). If you did 
  • 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.5.2.5 2008/09/10 08:31:58 jan Exp $ 
    1414 * 
    15  * Copyright 2005 Örjan Persson <o@42mm.org> 
     15 * Copyright 2005 �rjan Persson <o@42mm.org> 
    1616 * Copyright 2005-2008 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. 
    2020 * 
    21  * @author  Örjan Persson <o@42mm.org> 
     21 * @author  �rjan Persson <o@42mm.org> 
    2222 * @package Text_Diff 
    2323 * @since   0.2.0 
    2424 */ 
     
    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            } 
  • wp-includes/Text/Diff/Renderer/inline.php

     
    22/** 
    33 * "Inline" diff renderer. 
    44 * 
    5  * $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.21 2008/01/04 10:07:51 jan Exp $ 
     5 * $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.4.10.14 2008/01/04 10:37:27 jan Exp $ 
    66 * 
    77 * Copyright 2004-2008 The Horde Project (http://www.horde.org/) 
    88 * 
     
    133133        /* We want to split on word boundaries, but we need to 
    134134         * preserve whitespace as well. Therefore we split on words, 
    135135         * but include all blocks of whitespace in the wordlist. */ 
    136         $diff = new Text_Diff($this->_splitOnWords($text1, $nl), 
     136        $diff =& new Text_Diff($this->_splitOnWords($text1, $nl), 
    137137                              $this->_splitOnWords($text2, $nl)); 
    138138 
    139139        /* Get the diff in inline format. */ 
    140         $renderer = new Text_Diff_Renderer_inline(array_merge($this->getParams(), 
     140        $renderer =& new Text_Diff_Renderer_inline(array_merge($this->getParams(), 
    141141                                                              array('split_level' => 'words'))); 
    142142 
    143143        /* Run the diff and get the output. */