summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/img.pm10
-rw-r--r--IkiWiki/Plugin/remove.pm189
-rw-r--r--IkiWiki/Rcs/Stub.pm6
-rw-r--r--IkiWiki/Rcs/bzr.pm6
-rw-r--r--IkiWiki/Rcs/git.pm8
-rw-r--r--IkiWiki/Rcs/mercurial.pm6
-rw-r--r--IkiWiki/Rcs/monotone.pm6
-rw-r--r--IkiWiki/Rcs/svn.pm17
-rw-r--r--IkiWiki/Rcs/tla.pm6
9 files changed, 251 insertions, 3 deletions
diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm
index 17a9367d3..748d28ace 100644
--- a/IkiWiki/Plugin/img.pm
+++ b/IkiWiki/Plugin/img.pm
@@ -41,6 +41,10 @@ sub preprocess (@) { #{{{
}
my $file = bestlink($params{page}, $image);
+ my $srcfile = srcfile($file, 1);
+ if (! length $file || ! defined $srcfile) {
+ return htmllink($params{page}, $params{destpage}, $image);
+ }
my $dir = $params{page};
my $base = IkiWiki::basename($file);
@@ -61,12 +65,12 @@ sub preprocess (@) { #{{{
will_render($params{page}, $imglink);
- if (-e $outfile && (-M srcfile($file) >= -M $outfile)) {
+ if (-e $outfile && (-M $srcfile >= -M $outfile)) {
$r = $im->Read($outfile);
error sprintf(gettext("failed to read %s: %s"), $outfile, $r) if $r;
}
else {
- $r = $im->Read(srcfile($file));
+ $r = $im->Read($srcfile);
error sprintf(gettext("failed to read %s: %s"), $file, $r) if $r;
$r = $im->Resize(geometry => "${w}x${h}");
@@ -83,7 +87,7 @@ sub preprocess (@) { #{{{
}
}
else {
- $r = $im->Read(srcfile($file));
+ $r = $im->Read($srcfile);
error sprintf(gettext("failed to read %s: %s"), $file, $r) if $r;
$imglink = $file;
}
diff --git a/IkiWiki/Plugin/remove.pm b/IkiWiki/Plugin/remove.pm
new file mode 100644
index 000000000..91f133ab6
--- /dev/null
+++ b/IkiWiki/Plugin/remove.pm
@@ -0,0 +1,189 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::remove;
+
+use warnings;
+use strict;
+use IkiWiki 2.00;
+
+sub import { #{{{
+ hook(type => "formbuilder_setup", id => "remove", call => \&formbuilder_setup);
+ hook(type => "formbuilder", id => "remove", call => \&formbuilder);
+ hook(type => "sessioncgi", id => "remove", call => \&sessioncgi);
+
+} # }}}
+
+sub formbuilder_setup (@) { #{{{
+ my %params=@_;
+ my $form=$params{form};
+ my $q=$params{cgi};
+
+ if (defined $form->field("do") && $form->field("do") eq "edit") {
+ # Removal button for the page, and also for attachments.
+ push @{$params{buttons}}, "Remove";
+ $form->tmpl_param("field-remove" => '<input name="_submit" type="submit" value="Remove Attachments" />');
+ }
+} #}}}
+
+sub confirmation_form ($$) { #{{{
+ my $q=shift;
+ my $session=shift;
+
+ eval q{use CGI::FormBuilder};
+ error($@) if $@;
+ my @fields=qw(do page);
+ my $f = CGI::FormBuilder->new(
+ name => "remove",
+ header => 0,
+ charset => "utf-8",
+ method => 'POST',
+ javascript => 0,
+ params => $q,
+ action => $config{cgiurl},
+ stylesheet => IkiWiki::baseurl()."style.css",
+ fields => \@fields,
+ );
+
+ $f->field(name => "do", type => "hidden", value => "remove", force => 1);
+
+ return $f, ["Remove", "Cancel"];
+} #}}}
+
+sub removal_confirm ($$@) {
+ my $q=shift;
+ my $session=shift;
+ my $attachment=shift;
+ my @pages=@_;
+
+ # Save current form state to allow returning to it later
+ # without losing any edits.
+ # (But don't save what button was submitted, to avoid
+ # looping back to here.)
+ # Note: "_submit" is CGI::FormBuilder internals.
+ $q->param(-name => "_submit", -value => "");
+ $session->param(postremove => scalar $q->Vars);
+ IkiWiki::cgi_savesession($session);
+
+ my ($f, $buttons)=confirmation_form($q, $session);
+ $f->title(sprintf(gettext("confirm removal of %s"),
+ join(", ", map { IkiWiki::pagetitle($_) } @pages)));
+ $f->field(name => "page", type => "hidden", value => \@pages, force => 1);
+ if (defined $attachment) {
+ $f->field(name => "attachment", type => "hidden",
+ value => $attachment, force => 1);
+ }
+
+ IkiWiki::showform($f, $buttons, $session, $q);
+ exit 0;
+}
+
+sub postremove ($) {
+ my $session=shift;
+
+ # Load saved form state and return to edit form.
+ my $postremove=CGI->new($session->param("postremove"));
+ $session->clear("postremove");
+ IkiWiki::cgi_savesession($session);
+ IkiWiki::cgi($postremove, $session);
+}
+
+sub formbuilder (@) { #{{{
+ my %params=@_;
+ my $form=$params{form};
+
+ if (defined $form->field("do") && $form->field("do") eq "edit") {
+ my $q=$params{cgi};
+ my $session=$params{session};
+
+ if ($form->submitted eq "Remove") {
+ removal_confirm($q, $session, 0, $form->field("page"));
+ }
+ elsif ($form->submitted eq "Remove Attachments") {
+ removal_confirm($q, $session, 1, $q->param("attachment_select"));
+ }
+ }
+} #}}}
+
+sub sessioncgi ($$) { #{{{
+ my $q=shift;
+
+ if ($q->param("do") eq 'remove') {
+ my $session=shift;
+ my ($form, $buttons)=confirmation_form($q, $session);
+ IkiWiki::decode_form_utf8($form);
+
+ if ($form->submitted eq 'Cancel') {
+ postremove($session);
+ }
+ elsif ($form->submitted eq 'Remove' && $form->validate) {
+ my @pages=$q->param("page");
+
+ # Validate removal by checking that the page exists,
+ # and that the user is allowed to edit(/remove) it.
+ my @files;
+ foreach my $page (@pages) {
+ if (! exists $pagesources{$page}) {
+ error(sprintf(gettext("%s does not exist"),
+ htmllink("", "", $page, noimageinline => 1)));
+ }
+ IkiWiki::check_canedit($page, $q, $session);
+
+ my $file=$pagesources{$page};
+ if (! -e "$config{srcdir}/$file") {
+ error(sprintf(gettext("%s is not in the srcdir, so it cannot be deleted"), $file));
+ }
+ elsif (! -f "$config{srcdir}/$file") {
+ error(sprintf(gettext("%s is not a file"), $file));
+ }
+
+ # This untaint is safe because we've
+ # verified the file is a known source file,
+ # and is in the srcdir, and is a regular
+ # file.
+ push @files, IkiWiki::possibly_foolish_untaint($file);
+ }
+
+ # Do removal, and update the wiki.
+ require IkiWiki::Render;
+ if ($config{rcs}) {
+ IkiWiki::disable_commit_hook();
+ foreach my $file (@files) {
+ my $token=IkiWiki::rcs_prepedit($file);
+ IkiWiki::rcs_remove($file);
+ IkiWiki::rcs_commit($file, gettext("removed"),
+ $token, $session->param("name"), $ENV{REMOTE_ADDR});
+ }
+ IkiWiki::enable_commit_hook();
+ IkiWiki::rcs_update();
+ }
+ else {
+ foreach my $file (@files) {
+ IkiWiki::prune("$config{srcdir}/$file");
+ }
+ }
+ IkiWiki::refresh();
+ IkiWiki::saveindex();
+
+ if ($q->param("attachment")) {
+ # Attachments were deleted, so redirect
+ # back to the edit form.
+ postremove($session);
+ }
+ else {
+ # The page is gone, so redirect to parent
+ # of the page.
+ my $parent=IkiWiki::dirname($pages[0]);
+ if (! exists $pagesources{$parent}) {
+ $parent="index";
+ }
+ IkiWiki::redirect($q, $config{url}."/".htmlpage($parent));
+ }
+ }
+ else {
+ IkiWiki::showform($form, $buttons, $session, $q);
+ }
+
+ exit 0;
+ }
+}
+
+1
diff --git a/IkiWiki/Rcs/Stub.pm b/IkiWiki/Rcs/Stub.pm
index 6b69e65dc..375591c96 100644
--- a/IkiWiki/Rcs/Stub.pm
+++ b/IkiWiki/Rcs/Stub.pm
@@ -33,6 +33,12 @@ sub rcs_add ($) {
# prepare for it to be checked in when rcs_commit is called.
}
+sub rcs_remove ($) {
+ # Remove a file. The filename is relative to the root of the srcdir.
+ # Note that this should not check the removal in, it should only
+ # prepare for it to be checked in when rcs_commit is called.
+}
+
sub rcs_recentchanges ($) {
# Examine the RCS history and generate a list of recent changes.
# The data structure returned for each change is:
diff --git a/IkiWiki/Rcs/bzr.pm b/IkiWiki/Rcs/bzr.pm
index 0dc456de2..ca60190ea 100644
--- a/IkiWiki/Rcs/bzr.pm
+++ b/IkiWiki/Rcs/bzr.pm
@@ -89,6 +89,12 @@ sub rcs_add ($) { # {{{
}
} #}}}
+sub rcs_remove ($) { # {{{
+ my ($file) = @_;
+
+ error("rcs_remove not implemented for bzr"); # TODO
+} #}}}
+
sub rcs_recentchanges ($) { #{{{
my ($num) = @_;
diff --git a/IkiWiki/Rcs/git.pm b/IkiWiki/Rcs/git.pm
index 7fb612a39..b02b286bd 100644
--- a/IkiWiki/Rcs/git.pm
+++ b/IkiWiki/Rcs/git.pm
@@ -348,6 +348,14 @@ sub rcs_add ($) { # {{{
run_or_cry('git', 'add', $file);
} #}}}
+sub rcs_remove ($) { # {{{
+ # Remove file from archive.
+
+ my ($file) = @_;
+
+ run_or_cry('git', 'rm', '-f', $file);
+} #}}}
+
sub rcs_recentchanges ($) { #{{{
# List of recent changes.
diff --git a/IkiWiki/Rcs/mercurial.pm b/IkiWiki/Rcs/mercurial.pm
index bfe6ba49c..1bfcf6242 100644
--- a/IkiWiki/Rcs/mercurial.pm
+++ b/IkiWiki/Rcs/mercurial.pm
@@ -101,6 +101,12 @@ sub rcs_add ($) { # {{{
}
} #}}}
+sub rcs_remove ($) { # {{{
+ my ($file) = @_;
+
+ error("rcs_remove not implemented for mercurial"); # TODO
+} #}}}
+
sub rcs_recentchanges ($) { #{{{
my ($num) = @_;
diff --git a/IkiWiki/Rcs/monotone.pm b/IkiWiki/Rcs/monotone.pm
index ce4a2a3ed..948edac0a 100644
--- a/IkiWiki/Rcs/monotone.pm
+++ b/IkiWiki/Rcs/monotone.pm
@@ -370,6 +370,12 @@ sub rcs_add ($) { #{{{
}
} #}}}
+sub rcs_remove ($) { # {{{
+ my $file = shift;
+
+ error("rcs_remove not implemented for monotone"); # TODO
+} #}}}
+
sub rcs_recentchanges ($) { #{{{
my $num=shift;
my @ret;
diff --git a/IkiWiki/Rcs/svn.pm b/IkiWiki/Rcs/svn.pm
index 6a822e896..6c15c2ca9 100644
--- a/IkiWiki/Rcs/svn.pm
+++ b/IkiWiki/Rcs/svn.pm
@@ -134,6 +134,23 @@ sub rcs_add ($) { #{{{
}
} #}}}
+sub rcs_remove ($) { #{{{
+ # filename is relative to the root of the srcdir
+ my $file=shift;
+
+ if (-d "$config{srcdir}/.svn") {
+ my $parent=dirname($file);
+ while (! -d "$config{srcdir}/$parent/.svn") {
+ $file=$parent;
+ $parent=dirname($file);
+ }
+
+ if (system("svn", "rm", "--force", "--quiet", "$config{srcdir}/$file") != 0) {
+ warn("svn rm failed\n");
+ }
+ }
+} #}}}
+
sub rcs_recentchanges ($) { #{{{
my $num=shift;
my @ret;
diff --git a/IkiWiki/Rcs/tla.pm b/IkiWiki/Rcs/tla.pm
index e7fed9ad8..29dbd092a 100644
--- a/IkiWiki/Rcs/tla.pm
+++ b/IkiWiki/Rcs/tla.pm
@@ -88,6 +88,12 @@ sub rcs_add ($) { #{{{
}
} #}}}
+sub rcs_remove ($) { # {{{
+ my $file = shift;
+
+ error("rcs_remove not implemented for tla"); # TODO
+} #}}}
+
sub rcs_recentchanges ($) {
my $num=shift;
my @ret;