[Home]WikiPatches/TaviStyleHistoryDiff

UseModWiki | WikiPatches | RecentChanges | Preferences

A Unix Differ for WikiPatches/TaviStyleHistory


--- wiki_92.pl
+++ wiki.pl
@@ -397,7 +397,7 @@
 
   &OpenPage($id);
   &OpenDefaultText();
-  $newText = $Text{'text'};     # For differences
+  #$newText = $Text{'text'};     # For differences
   $openKept = 0;
   $revision = &GetParam('revision', '');
   $revision =~ s/\D//g;           # Remove non-numeric chars
@@ -411,6 +411,7 @@
       &OpenKeptRevision($revision);
     }
   }
+  $newText = $Text{'text'};     # For differences
   # Handle a single-level redirect
   $oldId = &GetParam('oldid', '');
   if (($oldId eq '') && (substr($Text{'text'}, 0, 10) eq '#REDIRECT ')) {
@@ -458,7 +459,8 @@
     $diffRevision = &GetParam('diffrevision', $diffRevision);
     # Later try to avoid the following keep-loading if possible?
     &OpenKeptRevisions('text_default')  if (!$openKept);
-    $fullHtml .= &GetDiffHTML($showDiff, $id, $diffRevision, $newText);
+    $fullHtml .= &GetDiffHTML($showDiff, $id, $diffRevision, $revision, $newText);
+    $fullHtml .= "<hr>\n";
   }
   $fullHtml .= &WikiToHTML($Text{'text'});
   $fullHtml .= "<hr>\n"  if (!&GetParam('embed', $EmbedWiki));
@@ -706,25 +708,42 @@
 
 sub DoHistory {
   my ($id) = @_;
-  my ($html, $canEdit);
+  my ($html, $canEdit, $row, $newText);
+
 
   print &GetHeader("",&QuoteHtml(Ts('History of %s', $id)), "") . "<br>";
   &OpenPage($id);
   &OpenDefaultText();
   $canEdit = &UserCanEdit($id);
   $canEdit = 0;  # Turn off direct "Edit" links
-  $html = &GetHistoryLine($id, $Page{'text_default'}, $canEdit, 1);
+  if( $UseDiff ) {
+    print <<EOF ;
+      <form action='$ScriptName' METHOD='GET'>
+          <input type='hidden' name='action' value='browse'/>
+          <input type='hidden' name='diff' value='1'/>
+          <input type='hidden' name='id' value='$id'/>
+      <table border='0' width='100%'><tr>
+EOF
+  }
+  $html = &GetHistoryLine($id, $Page{'text_default'}, $canEdit, $row++);
   &OpenKeptRevisions('text_default');
   foreach (reverse sort {$a <=> $b} keys %KeptRevisions) {
     next  if ($_ eq "");  # (needed?)
-    $html .= &GetHistoryLine($id, $KeptRevisions{$_}, $canEdit, 0);
+    $html .= &GetHistoryLine($id, $KeptRevisions{$_}, $canEdit, $row++);
   }
   print $html;
+  if( $UseDiff )
+  {
+    my $label = T('Compare');
+    print "<tr><td align='center'><input type='submit' value='$label'/>  </td></table></form>\n";
+    print "<hr>\n";
+    print &GetDiffHTML( &GetParam('defaultdiff',1), $id, '', '', $newText );
+  }
   print &GetCommonFooter();
 }
 
 sub GetHistoryLine {
-  my ($id, $section, $canEdit, $isCurrent) = @_;
+  my ($id, $section, $canEdit, $row) = @_;
   my ($html, $expirets, $rev, $summary, $host, $user, $uid, $ts, $minor);
   my (%sect, %revtext);
 
@@ -745,31 +764,32 @@
   $minor = '<i>' . T('(edit)') . '</i> '  if ($revtext{'minor'});
   $expirets = $Now - ($KeepDays * 24 * 60 * 60);
 
-  $html = Ts('Revision %s', $rev) . ": ";
-  if ($isCurrent) {
-    $html .= &GetPageLinkText($id, T('View')) . ' ';
+  if ($UseDiff) {
+    my ($c1, $c2);
+    $c1 = 'checked="checked"' if 1 == $row;
+    $c2 = 'checked="checked"' if 0 == $row;
+    $html .= "<tr><td align='center'><input type='radio' name='diffrevision' value='$rev' $c1/> ";
+    $html .= "<input type='radio' name='revision' value='$rev' $c2/></td><td>";
+  }
+  if (0 == $row) { # current revision
+    $html .= &GetPageLinkText($id, Ts('Revision %s', $rev)) . ' ';
     if ($canEdit) {
       $html .= &GetEditLink($id, T('Edit')) . ' ';
     }
-    if ($UseDiff) {
-      $html .= T('Diff') . ' ';
-    }
   } else {
-    $html .= &GetOldPageLink('browse', $id, $rev, T('View')) . ' ';
+    $html .= &GetOldPageLink('browse', $id, $rev, Ts('Revision %s', $rev)) . ' ';
     if ($canEdit) {
       $html .= &GetOldPageLink('edit',   $id, $rev, T('Edit')) . ' ';
     }
-    if ($UseDiff) {
-      $html .= &ScriptLinkDiffRevision(1, $id, $rev, T('Diff')) . ' ';
-    }
   }
+
   $html .= ". . " . $minor . &TimeToText($ts) . " ";
   $html .= T('by') . ' ' . &GetAuthorLink($host, $user, $uid) . " ";
   if (defined($summary) && ($summary ne "") && ($summary ne "*")) {
     $summary = &QuoteHtml($summary);   # Thanks Sunir! :-)
     $html .= "<b>[$summary]</b> ";
   }
-  $html .= "<br>\n";
+  $html .= $UseDiff ? "</tr>\n" : "<br>\n";
   return $html;
 }
 
@@ -1522,7 +1542,7 @@
 
 # ==== Difference markup and HTML ====
 sub GetDiffHTML {
-  my ($diffType, $id, $rev, $newText) = @_;
+  my ($diffType, $id, $revOld, $revNew, $newText) = @_;
   my ($html, $diffText, $diffTextTwo, $priorName, $links, $usecomma);
   my ($major, $minor, $author, $useMajor, $useMinor, $useAuthor, $cacheName);
 
@@ -1547,10 +1567,10 @@
     $cacheName = 'author';
     $useAuthor = 0;
   }
-  if ($rev ne "") {
+  if ($revOld ne "") {
     # Note: OpenKeptRevisions must have been done by caller.
     # Later optimize if same as cached revision
-    $diffText = &GetKeptDiff($newText, $rev, 1);  # 1 = get lock
+    $diffText = &GetKeptDiff($newText, $revOld, 1);  # 1 = get lock
     if ($diffText eq "") {
       $diffText = T('(The revisions are identical or unavailable.)');
     }
@@ -1585,21 +1605,24 @@
   if ((!defined($diffText)) || ($diffText eq "")) {
     $diffText = T('No diff available.');
   }
-  if ($rev ne "") {
+  if ($revOld ne "") {
+    my $currentRevision = T('current revision');
+    $currentRevision = Ts('revision %s', $revNew) if $revNew;
     $html = '<b>'
-            . Ts('Difference (from revision %s to current revision)', $rev)
-            . "</b>\n" . "$links<br>" . &DiffToHTML($diffText) . "<hr>\n";
+            . Ts('Difference (from revision %s', $revOld)
+            . Ts(' to %s)', $currentRevision)
+            . "</b>\n$links<br>" . &DiffToHTML($diffText);
   } else {
     if (($diffType != 2) &&
         ((!defined(&GetPageCache("old$cacheName"))) ||
          (&GetPageCache("old$cacheName") < 1))) {
       $html = '<b>'
               . Ts('No diff available--this is the first %s revision.',
-                   $priorName) . "</b>\n$links<hr>";
+                   $priorName) . "</b>\n$links";
     } else {
       $html = '<b>'
               . Ts('Difference (from prior %s revision)', $priorName)
-              . "</b>\n$links<br>" . &DiffToHTML($diffText) . "<hr>\n";
+              . "</b>\n$links<br>" . &DiffToHTML($diffText);
     }
   }
   return $html;


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited July 11, 2003 7:55 am by Johnson (diff)
Search: