[Home]WikiPatches/PermaHistory

UseModWiki | WikiPatches | RecentChanges | Preferences

It offers permanent revision history with separate kept files. It can be conceived in coexistence with history or leaving it obsolete (at choice).

Note: work in progress.

Patch

# == You should not have to change anything below this line. =============
....
+ $PermaDir     = "$DataDir/perma";     # Stores perma kept (old) page data
@ sub DoBrowseRequest {
...
<pre>
  + } elsif ($action eq 'perma') {
    + $ClickEdit = 0;	  
    + &DoPermaHistory($id)   if &ValidIdOrDie($id);
    + return 1;
  }
new sub
sub DoPermaHistory {
  my ($id) = @_;
  my ($html, $canEdit, $row, $newText);
  my ($status, $filedata, $fname);

  if (&PageIsHidden($id)) { ### hide page
	print &GetHeader('' , Ts('Perma of %s', $id), '');
	print Ts('%s is a hidden page', $id);
	print &GetMinimumFooter();
	return;
  }
  print &GetHeader('', Ts('Perma of %s', $id), '');
  &OpenPage($id);
  &OpenDefaultText();
  $newText = $Text{'text'};
  $canEdit = 0;
  $canEdit = &UserCanEdit($id)  if ($HistoryEdit);
  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"/>
EOF
  }
  $html = &GetHistoryLine($id, $Page{'text_default'}, $canEdit, $row++);
  for ( 1 .. $Page{'revision'}) {
    $fname = $PermaDir . "/" . &GetPageDirectory($id)
    . "/$id" . "/" . (($Page{'revision'} - $_+1) % 10) ."/" . 
    ($Page{'revision'} - $_+1) . ".kp";
    if (-f $fname) { 
      ($status, $filedata) = &ReadFile($fname);
      $html .= &GetHistoryLine($id, $filedata, $canEdit, $row++);
  }
  }
  print $html;
  if ($UseDiff) {
    my $label = T('Compare');
    print "<div class=compare><input type='submit'"
          . "value='$label'/></div><div class=clear></div></form>\n";
    print ''.&GetDiffHTML(&GetParam('defaultdiff', 1), $id, '', '', $newText);
  }

  print &GetCommonFooter();
}
new sub
sub GetPermaHistoryLink {
  my ($id, $text) = @_;

  if ($FreeLinks) {
    $id =~ s/ /_/g;
  }
  return &ScriptLink("action=perma&id=$id", $text);
}
and new subs
sub PermaFileName {
  return $PermaDir . "/" . &GetPageDirectory($OpenPageName)
         . "/$OpenPageName" . "/" . ($Page{'revision'} % 10) ."/" . "$Page{'revision'}.kp";
}

sub SavePermaFile {
  my $file = &PermaFileName();
  my $data;

  return  if ($Section{'revision'} < 1);  # Don't keep "empty" revision
  $Section{'keepts'} = $Now;
  $data = $FS1 . join($FS2, %Section);
  &CreateKeepDir($PermaDir, $OpenPageName);
  &AppendStringToFileLimited($file, $data);
}

@ sub DoPost {
...
  &SaveKeepSection();
  + &SavePermaFile();
  &ExpireKeepFile();
}

@ sub GetFooterText {
...
$result .= &GetHistoryLink($id, T('View other revisions'));
+ $result .= ' :: ' . &GetPermaHistoryLink($id, T('Perma'));
}
--JuanmaMP

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited November 8, 2009 12:55 pm by JuanmaMP (diff)
Search: