[Home]WikiPatches/ThisPageAlreadyExisted

UseModWiki | WikiPatches | RecentChanges | Preferences

This patch is for providing warning about the pages you want to edit that before they existed.

It's an increment of WikiPatches/DeletedPages and so, is described.

The Patch

sub DoOtherRequest {
  ...
   } elsif ($action eq "deleted") { 
     &DoDeleted; 
  ...

+ sub GetEditConfirmLink {
+  my ($id, $name, $confirm) = @_;
+
+  if ($FreeLinks) {
+    $id = &FreeToNormal($id);
+    $name =~ s/_/ /g;
+  }
+  return &ScriptLink("action=edit&id=$id&confirm=$confirm", $name);
+}

sub DoEdit {
  ...
  if ($revision ne "") {
    print &GetHiddenValue("revision", $revision), "\n";
  }
  + if (!-f &GetPageFile($id) && (&GetParam('confirm', 1))) {
  +  &DoDeleted();
  +}
  + 
 ...
sub DoDeleted {
  my ($status, $fileData, $oldFileData);
  my (@firstTs, @firstAuthor);
  my (@full, @fullrc, @fullnewrc);
  my ($i, @i);
  my ($elem, @first);
  my @unique = ();
  my %seen = ();
  + my ($id, $action);
  
  + $id = &GetParam('id', '');
  + $action = &GetParam('action', '');
  + if ($action eq 'deleted') {   
  print &GetHeader('', T('Deleted Pages'), '');
  + }
  ($status, $fileData) = &ReadFile($RcFile);
  if ($status) {
    @fullnewrc = split(/\n/, $fileData);
  }
  ($status, $oldFileData) = &ReadFile($RcOldFile);
  if ($status) {
    @fullrc = split(/\n/, $oldFileData);
  }
  @full = (@fullrc, @fullnewrc);
  ($i, $j) =0;
  if ($#full > 0) { # Only false if no lines in file
    for ($i=0; $i<=$#full; $i++) {
      @firstTs = split(/$FS3/, $full[$i]);
      @firstAuthor = split(/$FS2/, $full[$i]);
      if ($firstAuthor[$#i-2] eq $firstAuthor[3]) { # line pattern ok
        if (!-f &GetPageFile($firstTs[1]) && $firstTs[1] ne '') { # page ok
          push(@first, $firstTs[1]);
        }
      }
    }
  }
  # http://perldoc.perl.org
  # /perlfaq4.html#How-can-I-remove-duplicate-elements-from-a-list-or-array%3f;
  foreach $elem (@first) {
    next if $seen{ $elem }++;
    push (@unique, $elem);
  }
  + if ($action eq 'edit' ) {
  +  foreach my $del (@unique) {
  +    if ($id eq $del && (!&GetParam('confirm', 0))) { 
  +      print T('File already existed --');
  +      print '<br>' . Ts('Confirm edit of %s by following this link:', $id);
  +      print '<br>' . &GetEditConfirmLink($id, T('Edit'), 0);
  +      print &GetFooterText();
  +      return;
  +    }
  +  }
  +}
  + if ($action eq 'deleted') {
    print '<ol>';
    foreach $elem (sort @unique) {
      print '<li>' . &ScriptLinkClass("action=edit&id=$elem", $elem, 'wikipageedit');
    }
  print '</ol>';  
  print &GetMinimumFooter();
  +}
  }
--JuanmaMP

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited February 15, 2011 6:44 pm by JuanmaMP (diff)
Search: