2 package IkiWiki::Plugin::remove;
9 hook(type => "formbuilder_setup", id => "remove", call => \&formbuilder_setup);
10 hook(type => "formbuilder", id => "remove", call => \&formbuilder);
11 hook(type => "sessioncgi", id => "remove", call => \&sessioncgi);
15 sub formbuilder_setup (@) { #{{{
17 my $form=$params{form};
20 if (defined $form->field("do") && $form->field("do") eq "edit") {
21 push @{$params{buttons}}, "Remove";
22 # TODO button for attachments
26 sub confirmation_form ($$) { #{{{
30 eval q{use CGI::FormBuilder};
32 my @fields=qw(do page);
33 my $f = CGI::FormBuilder->new(
34 title => "confirm removal",
41 action => $config{cgiurl},
42 stylesheet => IkiWiki::baseurl()."style.css",
46 $f->field(name => "do", type => "hidden", value => "remove", force => 1);
47 $f->field(name => "page", label => "Will remove:", validate => sub {
49 if (! exists $pagesources{$page}) {
50 $f->field(name => "page", message => gettext("page does not exist"));
54 IkiWiki::check_canedit($page, $q, $session);
59 return $f, ["Remove", "Cancel"];
62 sub formbuilder (@) { #{{{
64 my $form=$params{form};
66 if (defined $form->field("do") && $form->field("do") eq "edit" &&
67 $form->submitted eq "Remove") {
69 my $session=$params{session};
70 # Save current form state to allow returning to it later
71 # without losing any edits.
72 # (But don't save what button was submitted.)
73 $q->param(-name => "_submit", -value => "");
74 $session->param(postremove => scalar $q->Vars);
75 IkiWiki::cgi_savesession($session);
77 # Display a small confirmation form.
78 my ($f, $buttons)=confirmation_form($q, $session);
79 $f->field(name => "page", value => $form->field("page"),
81 IkiWiki::showform($f, $buttons, $session, $q);
86 sub sessioncgi ($$) { #{{{
89 if ($q->param("do") eq 'remove') {
91 my ($form, $buttons)=confirmation_form($q, $session);
92 IkiWiki::decode_form_utf8($form);
93 if ($form->submitted eq 'Cancel') {
94 # Load saved form state and return to edit form.
95 my $postremove=CGI->new($session->param("postremove"));
96 $session->clear("postremove");
97 IkiWiki::cgi_savesession($session);
98 IkiWiki::cgi($postremove, $session);
101 elsif ($form->submitted eq 'Remove' && $form->validate) {
102 error("removal not yet implemented"); # TODO
105 IkiWiki::showform($form, $buttons, $session, $q);