I find that sometimes I want to delete pages automatically without jumping through a lot of hoops. The changes below will allow you to automatically delete a page, providing you are logged in as administrator. No confirmation is asked for, though I would imagine that it would be relatively easy to add this function. Lines added to existing subs are prefixed with >, remove them when adding to code.
8/8/2003: Changed sub DoDeletePage so that it uses the global homepage name. Also changed to not allow deletion of locked pages. -Phillip Riley
1. Add the following function after Sub GetEditLink:
sub GetDeleteLink {
my ($id, $name) = @_;
if ($FreeLinks) {
$id = &FreeToNormal($id);
$name =~ s/_/ /g;
}
return &ScriptLink("action=delete&id=$id", $name);
}
2. Add the following lines to sub DoOtherRequest
if ($action eq "edit") {
&DoEdit($id, 0, 0, "", 0) if &ValidIdOrDie($id);
> } elsif ($action eq "delete") {
> &DoDeletePage($id);
3. Add the following function after sub BuildLinkIndexPage
sub DoDeletePage {
my ($id) = @_;
return if (!&UserIsAdminOrError());
print &GetHeader("", "Delete " . $id, "");
if ($id eq $HomePage) {
print "<p>" . $HomePage . " can not be deleted.</p>";
} else {
if (-f &GetLockedPageFile($id)) {
print "<p>". $id . " can not be deleted because it is locked.</p>";
} else {
DeletePage($id, 1, 1);
print "<p>" . $id . " has been deleted.</p>";
}
}
print &GetCommonFooter();
}
5a. Add the following to lines to sub GetFooterText
} else {
$result .= &GetEditLink($id, T('Edit text of this page'));
> if (&UserIsAdmin()) {
> $result .= " | " . &GetDeleteLink($id, T('Delete this page'));
> }
}
5b. If you have installed GetAdminBar, you should instead add the following line to Sub GetAdminBar
$result .=" ";
> $result .= " | " . &GetDeleteLink($id, T('Delete this page'));
$result .= " | " . &ScriptLink("action=editbanned",T("Edit Banned List"));
It's just as easy as that. You don't actually have to add the subs to the place I put them, you should be able to put them just about anywhere.