[Home]WikiPatches/TaviStyleHistory

UseModWiki | WikiPatches | RecentChanges | Preferences

As inspired by MeatBall:WikkiTikkiTavi, a better history interface. If you just apply the patch to BrowsePage, you will at least be able to do inter-revision diffs ala UseMod:action=browse&id=SandBox&diff=1&revision=5&diffrevision=3 to show the difference between v3 and v5. -- SunirShah

NextRelease


 sub BrowsePage {
   my ($id) = @_;
   my ($fullHtml, $oldId, $allDiff, $showDiff, $openKept);
   my ($revision, $goodRevision, $diffRevision, $newText);

   &OpenPage($id);
   &OpenDefaultText();
   $openKept = 0;
  # $newText = $Text{'text'};     # For differences
   $revision = &GetParam('revision', '');
   $revision =~ s/\D//g;           # Remove non-numeric chars
   $goodRevision = $revision;      # Non-blank only if exists
   if ($revision ne '') {
     &OpenKeptRevisions('text_default');
     $openKept = 1;
     if (!defined($KeptRevisions{$revision})) {
       $goodRevision = '';
     } else {
       &OpenKeptRevision($revision);
     }
   }
   $newText = $Text{'text'};     # For differences
   # Handle a single-level redirect
   ...
     $fullHtml .= &GetDiffHTML($showDiff, $id, $diffRevision, $revision, $newText);
     $fullHtml .= "<hr>\n";
   ...
 }

 sub DoHistory {
   my ($id) = @_;
   my ($html, $canEdit, $row, $newText);
 
   print &GetHeader("",Ts('History of %s', $id), "") . "<br>";
   &OpenPage($id);
   &OpenDefaultText();
   $newText = $Text{'text'};
   $canEdit = &UserCanEdit($id);
   $canEdit = 0;  # Turn off direct "Edit" links
   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, $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, $row) = @_;
   my ($html, $expirets, $rev, $summary, $host, $user, $uid, $ts, $minor);
   my (%sect, %revtext);

   %sect = split(/$FS2/, $section, -1);
   %revtext = split(/$FS3/, $sect{'data'});
   $rev = $sect{'revision'};
   $summary = $revtext{'summary'};
   if ((defined($sect{'host'})) && ($sect{'host'} ne '')) {
     $host = $sect{'host'};
   } else {
     $host = $sect{'ip'};
     $host =~ s/\d+$/xxx/;      # Be somewhat anonymous (if no host)
   }
   $user = $sect{'username'};
   $uid = $sect{'id'};
   $ts = $sect{'ts'};
   $minor = '';
   $minor = '<i>' . T('(edit)') . '</i> '  if ($revtext{'minor'});
   $expirets = $Now - ($KeepDays * 24 * 60 * 60);

   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')) . ' ';
     }
   } else {
     $html .= &GetOldPageLink('browse', $id, $rev, Ts('Revision %s', $rev)) . ' ';
     if ($canEdit) {
       $html .= &GetOldPageLink('edit',   $id, $rev, T('Edit')) . ' ';
     }
   }
   $html .= ". . " . $minor . &TimeToText($ts) . " ";
   $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 .= $UseDiff ? "</tr>\n" : "<br>\n";
   return $html;
 }

 sub GetDiffHTML {
   my ($diffType, $id, $revOld, $revNew, $newText) = @_;
 ...
     $useAuthor = 0;
 ...
   }
   if ($revOld ne "") {
     # Note: OpenKeptRevisions must have been done by caller.
     # Later optimize if same as cached revision
     $diffText = &GetKeptDiff($newText, $revOld, 1);  # 1 = get lock
     if ($diffText eq "") {
       $diffText = T('(The revisions are identical or unavailable.)');
 ...
     $diffText = T('No diff available.');
   }
   if ($revOld ne "") {
     my $currentRevision = T('current revision');
     $currentRevision = Ts('revision %s', $revNew) if $revNew;
     $html = '<b>'
             . 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";
     } else {
       $html = '<b>'
               . Ts('Difference (from prior %s revision)', $priorName)
               . "</b>\n$links<br>" . &DiffToHTML($diffText);
     }
   }
   return $html;
 }


The block "print <<EOF ; ... EOF" produced hideous errors; replacing it with "print qq{ ... }" fixes. I have no idea why... -- Tarquin

Try 1) adding double quotes 2) Making sure that code closing EOF is at start of line

print<<"EOF";
...
EOF

ManpreetSingh


Finally grokked it! -- AlexSchroeder


a Unix differ/Patch? version: WikiPatches/TaviStyleHistoryDiff -- Johnson


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited October 2, 2007 6:23 pm by MarkusLude (diff)
Search: