aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/CGI.pm2
-rw-r--r--IkiWiki/Plugin/aggregate.pm2
-rw-r--r--IkiWiki/Plugin/amazon_s3.pm5
-rw-r--r--IkiWiki/Plugin/attachment.pm2
-rw-r--r--IkiWiki/Plugin/comments.pm4
-rw-r--r--IkiWiki/Plugin/editpage.pm2
-rw-r--r--IkiWiki/Plugin/po.pm2
-rw-r--r--IkiWiki/Plugin/remove.pm62
-rw-r--r--IkiWiki/Plugin/rename.pm32
-rw-r--r--IkiWiki/Plugin/transient.pm2
-rw-r--r--IkiWiki/Render.pm11
11 files changed, 84 insertions, 42 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index 62383b6fd..5baa6c179 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -131,7 +131,7 @@ sub needsignin ($$) {
if (! defined $session->param("name") ||
! userinfo_get($session->param("name"), "regdate")) {
- $session->param(postsignin => $ENV{QUERY_STRING});
+ $session->param(postsignin => $q->query_string);
cgi_signin($q, $session);
cgi_savesession($session);
exit;
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 5e22609c9..83bd670cb 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -201,7 +201,7 @@ sub migrate_to_internal {
if (-e $oldoutput) {
require IkiWiki::Render;
debug("removing output file $oldoutput");
- IkiWiki::prune($oldoutput);
+ IkiWiki::prune($oldoutput, $config{destdir});
}
}
diff --git a/IkiWiki/Plugin/amazon_s3.pm b/IkiWiki/Plugin/amazon_s3.pm
index cfd8cd347..a9da6bf12 100644
--- a/IkiWiki/Plugin/amazon_s3.pm
+++ b/IkiWiki/Plugin/amazon_s3.pm
@@ -232,8 +232,9 @@ sub writefile ($$$;$$) {
}
# This is a wrapper around the real prune.
-sub prune ($) {
+sub prune ($;$) {
my $file=shift;
+ my $up_to=shift;
my @keys=IkiWiki::Plugin::amazon_s3::file2keys($file);
@@ -250,7 +251,7 @@ sub prune ($) {
}
}
- return $IkiWiki::Plugin::amazon_s3::subs{'IkiWiki::prune'}->($file);
+ return $IkiWiki::Plugin::amazon_s3::subs{'IkiWiki::prune'}->($file, $up_to);
}
1
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm
index 133a54daf..aea70429d 100644
--- a/IkiWiki/Plugin/attachment.pm
+++ b/IkiWiki/Plugin/attachment.pm
@@ -286,7 +286,7 @@ sub attachments_save {
}
return unless @attachments;
require IkiWiki::Render;
- IkiWiki::prune($dir);
+ IkiWiki::prune($dir, $config{wikistatedir}."/attachments");
# Check the attachments in and trigger a wiki refresh.
if ($config{rcs}) {
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 0d5e3c078..285013e49 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -665,9 +665,11 @@ sub commentmoderation ($$) {
my $page=IkiWiki::dirname($f);
my $file="$config{srcdir}/$f";
+ my $filedir=$config{srcdir};
if (! -e $file) {
# old location
$file="$config{wikistatedir}/comments_pending/".$f;
+ $filedir="$config{wikistatedir}/comments_pending";
}
if ($action eq 'Accept') {
@@ -682,7 +684,7 @@ sub commentmoderation ($$) {
}
require IkiWiki::Render;
- IkiWiki::prune($file);
+ IkiWiki::prune($file, $filedir);
}
}
diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm
index 54051c58c..d3c695935 100644
--- a/IkiWiki/Plugin/editpage.pm
+++ b/IkiWiki/Plugin/editpage.pm
@@ -39,7 +39,7 @@ sub refresh () {
}
if ($delete) {
debug(sprintf(gettext("removing old preview %s"), $file));
- IkiWiki::prune("$config{destdir}/$file");
+ IkiWiki::prune("$config{destdir}/$file", $config{destdir});
}
}
elsif (defined $mtime) {
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 26c6463da..53e6af92f 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -1102,7 +1102,7 @@ sub deletetranslations ($) {
IkiWiki::rcs_remove($_);
}
else {
- IkiWiki::prune("$config{srcdir}/$_");
+ IkiWiki::prune("$config{srcdir}/$_", $config{srcdir});
}
} @todelete;
diff --git a/IkiWiki/Plugin/remove.pm b/IkiWiki/Plugin/remove.pm
index 14ac01c9b..d48b28f95 100644
--- a/IkiWiki/Plugin/remove.pm
+++ b/IkiWiki/Plugin/remove.pm
@@ -22,6 +22,13 @@ sub getsetup () {
},
}
+sub allowed_dirs {
+ return grep { defined $_ } (
+ $config{srcdir},
+ $IkiWiki::Plugin::transient::transientdir,
+ );
+}
+
sub check_canremove ($$$) {
my $page=shift;
my $q=shift;
@@ -33,12 +40,22 @@ sub check_canremove ($$$) {
htmllink("", "", $page, noimageinline => 1)));
}
- # Must exist on disk, and be a regular file.
+ # Must exist in either the srcdir or a suitable underlay (e.g.
+ # transient underlay), and be a regular file.
my $file=$pagesources{$page};
- if (! -e "$config{srcdir}/$file") {
+ my $dir;
+
+ foreach my $srcdir (allowed_dirs()) {
+ if (-e "$srcdir/$file") {
+ $dir = $srcdir;
+ last;
+ }
+ }
+
+ if (! defined $dir) {
error(sprintf(gettext("%s is not in the srcdir, so it cannot be deleted"), $file));
}
- elsif (-l "$config{srcdir}/$file" && ! -f _) {
+ elsif (-l "$dir/$file" && ! -f _) {
error(sprintf(gettext("%s is not a file"), $file));
}
@@ -46,7 +63,7 @@ sub check_canremove ($$$) {
# This is sorta overkill, but better safe than sorry.
if (! defined pagetype($pagesources{$page})) {
if (IkiWiki::Plugin::attachment->can("check_canattach")) {
- IkiWiki::Plugin::attachment::check_canattach($session, $page, "$config{srcdir}/$file");
+ IkiWiki::Plugin::attachment::check_canattach($session, $page, "$dir/$file");
}
else {
error("removal of attachments is not allowed");
@@ -124,7 +141,7 @@ sub removal_confirm ($$@) {
my $f=IkiWiki::Plugin::attachment::is_held_attachment($page);
if (defined $f) {
require IkiWiki::Render;
- IkiWiki::prune($f);
+ IkiWiki::prune($f, "$config{wikistatedir}/attachments");
}
}
}
@@ -223,21 +240,34 @@ sub sessioncgi ($$) {
require IkiWiki::Render;
if ($config{rcs}) {
IkiWiki::disable_commit_hook();
- foreach my $file (@files) {
- IkiWiki::rcs_remove($file);
+ }
+ my $rcs_removed = 1;
+
+ foreach my $file (@files) {
+ foreach my $srcdir (allowed_dirs()) {
+ if (-e "$srcdir/$file") {
+ if ($srcdir eq $config{srcdir} && $config{rcs}) {
+ IkiWiki::rcs_remove($file);
+ $rcs_removed = 1;
+ }
+ else {
+ IkiWiki::prune("$srcdir/$file", $srcdir);
+ }
+ }
}
- IkiWiki::rcs_commit_staged(
- message => gettext("removed"),
- session => $session,
- );
- IkiWiki::enable_commit_hook();
- IkiWiki::rcs_update();
}
- else {
- foreach my $file (@files) {
- IkiWiki::prune("$config{srcdir}/$file");
+
+ if ($config{rcs}) {
+ if ($rcs_removed) {
+ IkiWiki::rcs_commit_staged(
+ message => gettext("removed"),
+ session => $session,
+ );
}
+ IkiWiki::enable_commit_hook();
+ IkiWiki::rcs_update();
}
+
IkiWiki::refresh();
IkiWiki::saveindex();
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index 8e32d41ae..8387a1e32 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -206,14 +206,22 @@ sub rename_start ($$$$) {
exit 0;
}
-sub postrename ($;$$$) {
+sub postrename ($$$;$$) {
+ my $cgi=shift;
my $session=shift;
my $src=shift;
my $dest=shift;
my $attachment=shift;
- # Load saved form state and return to edit page.
- my $postrename=CGI->new($session->param("postrename"));
+ # Load saved form state and return to edit page, using stored old
+ # cgi state. Or, if the rename was not started on the edit page,
+ # return to the renamed page.
+ my $postrename=$session->param("postrename");
+ if (! defined $postrename) {
+ IkiWiki::redirect($cgi, urlto(defined $dest ? $dest : $src));
+ exit;
+ }
+ my $oldcgi=CGI->new($postrename);
$session->clear("postrename");
IkiWiki::cgi_savesession($session);
@@ -222,21 +230,21 @@ sub postrename ($;$$$) {
# They renamed the page they were editing. This requires
# fixups to the edit form state.
# Tweak the edit form to be editing the new page.
- $postrename->param("page", $dest);
+ $oldcgi->param("page", $dest);
}
# Update edit form content to fix any links present
# on it.
- $postrename->param("editcontent",
+ $oldcgi->param("editcontent",
renamepage_hook($dest, $src, $dest,
- $postrename->param("editcontent")));
+ $oldcgi->param("editcontent")));
# Get a new edit token; old was likely invalidated.
- $postrename->param("rcsinfo",
+ $oldcgi->param("rcsinfo",
IkiWiki::rcs_prepedit($pagesources{$dest}));
}
- IkiWiki::cgi_editpage($postrename, $session);
+ IkiWiki::cgi_editpage($oldcgi, $session);
}
sub formbuilder (@) {
@@ -291,16 +299,16 @@ sub sessioncgi ($$) {
my $session=shift;
my ($form, $buttons)=rename_form($q, $session, Encode::decode_utf8($q->param("page")));
IkiWiki::decode_form_utf8($form);
+ my $src=$form->field("page");
if ($form->submitted eq 'Cancel') {
- postrename($session);
+ postrename($q, $session, $src);
}
elsif ($form->submitted eq 'Rename' && $form->validate) {
IkiWiki::checksessionexpiry($q, $session, $q->param('sid'));
# These untaints are safe because of the checks
# performed in check_canrename later.
- my $src=$form->field("page");
my $srcfile=IkiWiki::possibly_foolish_untaint($pagesources{$src})
if exists $pagesources{$src};
my $dest=IkiWiki::possibly_foolish_untaint(titlepage($form->field("new_name")));
@@ -324,7 +332,7 @@ sub sessioncgi ($$) {
IkiWiki::Plugin::attachment::is_held_attachment($src);
if ($held) {
rename($held, IkiWiki::Plugin::attachment::attachment_holding_location($dest));
- postrename($session, $src, $dest, $q->param("attachment"))
+ postrename($q, $session, $src, $dest, $q->param("attachment"))
unless defined $srcfile;
}
@@ -430,7 +438,7 @@ sub sessioncgi ($$) {
$renamesummary.=$template->output;
}
- postrename($session, $src, $dest, $q->param("attachment"));
+ postrename($q, $session, $src, $dest, $q->param("attachment"));
}
else {
IkiWiki::showform($form, $buttons, $session, $q);
diff --git a/IkiWiki/Plugin/transient.pm b/IkiWiki/Plugin/transient.pm
index 4ea4317d4..d4eb005ea 100644
--- a/IkiWiki/Plugin/transient.pm
+++ b/IkiWiki/Plugin/transient.pm
@@ -43,7 +43,7 @@ sub rendered (@) {
my $casualty = "$transientdir/$file";
if (srcfile($file) ne $casualty && -e $casualty) {
debug(sprintf(gettext("removing transient version of %s"), $file));
- IkiWiki::prune($casualty);
+ IkiWiki::prune($casualty, $transientdir);
}
}
}
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index d6c1f4f4c..a90d202ee 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -262,12 +262,13 @@ sub render ($$) {
}
}
-sub prune ($) {
+sub prune ($;$) {
my $file=shift;
+ my $up_to=shift;
unlink($file);
my $dir=dirname($file);
- while (rmdir($dir)) {
+ while ((! defined $up_to || $dir =~ m{^\Q$up_to\E\/}) && rmdir($dir)) {
$dir=dirname($dir);
}
}
@@ -447,7 +448,7 @@ sub remove_del (@) {
}
foreach my $old (@{$oldrenderedfiles{$page}}) {
- prune($config{destdir}."/".$old);
+ prune($config{destdir}."/".$old, $config{destdir});
}
foreach my $source (keys %destsources) {
@@ -537,7 +538,7 @@ sub remove_unrendered () {
foreach my $file (@{$oldrenderedfiles{$page}}) {
if (! grep { $_ eq $file } @{$renderedfiles{$page}}) {
debug(sprintf(gettext("removing %s, no longer built by %s"), $file, $page));
- prune($config{destdir}."/".$file);
+ prune($config{destdir}."/".$file, $config{destdir});
}
}
}
@@ -844,7 +845,7 @@ sub clean_rendered {
remove_unrendered();
foreach my $page (keys %oldrenderedfiles) {
foreach my $file (@{$oldrenderedfiles{$page}}) {
- prune($config{destdir}."/".$file);
+ prune($config{destdir}."/".$file, $config{destdir});
}
}
}