Migrate to sebastian/diff
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 3 Aug 2022 10:55:27 +0000 (12:55 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 3 Aug 2022 10:55:27 +0000 (12:55 +0200)
wcfsetup/install/files/acp/templates/templateDiff.tpl
wcfsetup/install/files/lib/acp/page/TemplateDiffPage.class.php
wcfsetup/install/files/lib/acp/page/VersionTrackerListPage.class.php
wcfsetup/install/files/lib/page/EditHistoryPage.class.php

index 441d636d1c04aa931d77bdef6fe016403b30cb1b..b83cb235a8ac6231dc652603a01351c9ee4c2b7b 100644 (file)
@@ -10,7 +10,7 @@
                <nav class="contentHeaderNavigation">
                        <ul>
                                {content}
-                                       {if $diff}
+                                       {if $diff !== null}
                                                {if $parent->templateGroupID}
                                                        <li><a href="{link controller='TemplateEdit' id=$parent->templateID}{/link}" class="button"><span class="icon icon16 fa-pencil"></span> <span>{lang}wcf.global.button.edit{/lang}</span></a></li>
                                                {/if}
@@ -50,7 +50,7 @@
        </div>
 </form>
 
-{if $diff}
+{if $diff !== null}
        <div id="fullscreenContainer">
                <div class="sideBySide">
                        <div class="section">
@@ -66,7 +66,7 @@
                                <pre id="left" class="monospace" style="overflow: auto; height: 700px;">{*
                                        *}<span style="display: inline-block;">{* <-- wrapper span to prevent content from overflowing the <li>
                                                *}<ol class="nativeList">{*
-                                                       *}{foreach from=$diff->getRawDiff() item='line'}{*
+                                                       *}{foreach from=$diff item='line'}{*
                                                                *}{if $line[0] == ' '}{*
                                                                        *}{assign var=removeOffset value=0}{assign var=lineNo value=$lineNo + 1}{*
                                                                        *}<li value="{@$lineNo}" style="margin: 0">{$line[1]}</li>{*
@@ -94,7 +94,7 @@
                                <pre id="right" class="monospace" style="overflow: auto; height: 700px;">{*
                                        *}<span style="display: inline-block;">{* <-- wrapper span to prevent content from overflowing the <li>
                                                *}<ol class="nativeList">{*
-                                                       *}{foreach from=$diff->getRawDiff() item='line'}{*
+                                                       *}{foreach from=$diff item='line'}{*
                                                                *}{if $line[0] == ' '}{*
                                                                        *}{if $removeOffset > 0}{*
                                                                                *}{@'<li style="list-style-type: none;margin: 0">&nbsp;</li>'|str_repeat:$removeOffset}{*
index e6d57b295e52db53afa99016fce5b170b2adab25..b2dbc32ef01024b33e2dcca75f164c03e821dd32 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace wcf\acp\page;
 
+use SebastianBergmann\Diff\Differ;
 use wcf\data\template\group\TemplateGroupList;
 use wcf\data\template\Template;
 use wcf\data\template\TemplateList;
@@ -52,7 +53,7 @@ class TemplateDiffPage extends AbstractPage
 
     /**
      * differences between both templates
-     * @var Diff
+     * @var array
      */
     public $diff;
 
@@ -127,7 +128,8 @@ class TemplateDiffPage extends AbstractPage
         if ($this->parent->templateID) {
             $a = \explode("\n", StringUtil::unifyNewlines($this->parent->getSource()));
             $b = \explode("\n", StringUtil::unifyNewlines($this->template->getSource()));
-            $this->diff = new Diff($a, $b);
+            $differ = new Differ();
+            $this->diff = Diff::rawDiffFromSebastianDiff($differ->diffToArray($a, $b));
         }
     }
 
index 11c7d85aa141f4a4d0a88f02f5c47bf0e610b823..cbe975afc59b5eb6d853b44a4d4e799d0eee0f16 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace wcf\acp\page;
 
+use SebastianBergmann\Diff\Differ;
 use wcf\data\IVersionTrackerObject;
 use wcf\data\language\Language;
 use wcf\page\AbstractPage;
@@ -75,7 +76,7 @@ class VersionTrackerListPage extends AbstractPage
 
     /**
      * differences between both versions
-     * @var Diff[]
+     * @var array
      */
     public $diffs = [];
 
@@ -171,6 +172,8 @@ class VersionTrackerListPage extends AbstractPage
     {
         parent::readData();
 
+        $differ = new Differ();
+
         // valid IDs were given, calculate diff
         if ($this->old && $this->new) {
             $languageIDs = $this->new->getLanguageIDs();
@@ -199,8 +202,7 @@ class VersionTrackerListPage extends AbstractPage
                         continue;
                     }
 
-                    $diff = new Diff($a, $b);
-                    $rawDiff = $diff->getRawDiff();
+                    $rawDiff = Diff::rawDiffFromSebastianDiff($differ->diffToArray($a, $b));
 
                     // create word diff for small changes (only one consecutive paragraph modified)
                     for ($i = 0, $max = \count($rawDiff); $i < $max;) {
@@ -213,10 +215,10 @@ class VersionTrackerListPage extends AbstractPage
                             $a = \preg_split('/(\\W)/u', $rawDiff[$i][1], -1, \PREG_SPLIT_DELIM_CAPTURE);
                             $b = \preg_split('/(\\W)/u', $rawDiff[$i + 1][1], -1, \PREG_SPLIT_DELIM_CAPTURE);
 
-                            $diff = new Diff($a, $b);
+                            $diff = Diff::rawDiffFromSebastianDiff($differ->diffToArray($a, $b));
                             $rawDiff[$i][1] = '';
                             $rawDiff[$i + 1][1] = '';
-                            foreach ($diff->getRawDiff() as $entry) {
+                            foreach ($diff as $entry) {
                                 $entry[1] = StringUtil::encodeHTML($entry[1]);
 
                                 if ($entry[0] === Diff::SAME) {
index bd8eca33d6c2e2f10df1f7efc39ba94a10924023..89034db7b000133b2c4a65e0fcd3e619b0be9c2e 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace wcf\page;
 
+use SebastianBergmann\Diff\Differ;
 use wcf\data\DatabaseObjectList;
 use wcf\data\edit\history\entry\EditHistoryEntry;
 use wcf\data\edit\history\entry\EditHistoryEntryList;
@@ -63,7 +64,7 @@ class EditHistoryPage extends AbstractPage
 
     /**
      * differences between both versions
-     * @var Diff
+     * @var array
      */
     public $diff;
 
@@ -176,12 +177,13 @@ class EditHistoryPage extends AbstractPage
         $this->objectList->getConditionBuilder()->add('objectID = ?', [$this->objectID]);
         $this->objectList->readObjects();
 
+        $differ = new Differ();
+
         // valid IDs were given, calculate diff
         if ($this->old && $this->new) {
             $a = \explode("\n", StringUtil::unifyNewlines(StringUtil::trim($this->old->getMessage())));
             $b = \explode("\n", StringUtil::unifyNewlines(StringUtil::trim($this->new->getMessage())));
-            $diff = new Diff($a, $b);
-            $this->diff = $diff->getRawDiff();
+            $this->diff = Diff::rawDiffFromSebastianDiff($differ->diffToArray($a, $b));
 
             // create word diff for small changes (only one consecutive paragraph modified)
             for ($i = 0, $max = \count($this->diff); $i < $max;) {
@@ -194,10 +196,10 @@ class EditHistoryPage extends AbstractPage
                     $a = \preg_split('/(\\W)/u', $this->diff[$i][1], -1, \PREG_SPLIT_DELIM_CAPTURE);
                     $b = \preg_split('/(\\W)/u', $this->diff[$i + 1][1], -1, \PREG_SPLIT_DELIM_CAPTURE);
 
-                    $diff = new Diff($a, $b);
+                    $diff = Diff::rawDiffFromSebastianDiff($differ->diffToArray($a, $b));
                     $this->diff[$i][1] = '';
                     $this->diff[$i + 1][1] = '';
-                    foreach ($diff->getRawDiff() as $entry) {
+                    foreach ($diff as $entry) {
                         $entry[1] = StringUtil::encodeHTML($entry[1]);
 
                         if ($entry[0] === Diff::SAME) {