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:", size => 60,
49 # Validate page by checking that the page exists, and that
50 # the user is allowed to edit(/delete) it.
51 my $page=IkiWiki::titlepage(shift);
52 if (! exists $pagesources{$page}) {
53 $f->field(name => "page", message => gettext("page does not exist"));
57 IkiWiki::check_canedit($page, $q, $session);
62 return $f, ["Remove", "Cancel"];
65 sub formbuilder (@) { #{{{
67 my $form=$params{form};
69 if (defined $form->field("do") && $form->field("do") eq "edit" &&
70 $form->submitted eq "Remove") {
72 my $session=$params{session};
74 # Save current form state to allow returning to it later
75 # without losing any edits.
76 # (But don't save what button was submitted, to avoid
77 # looping back to here.)
78 # Note: "_submit" is CGI::FormBuilder internals.
79 $q->param(-name => "_submit", -value => "");
80 $session->param(postremove => scalar $q->Vars);
81 IkiWiki::cgi_savesession($session);
83 # Display a small confirmation form.
84 my ($f, $buttons)=confirmation_form($q, $session);
85 $f->field(name => "page",
86 value => IkiWiki::pagetitle($form->field("page")),
88 IkiWiki::showform($f, $buttons, $session, $q);
93 sub sessioncgi ($$) { #{{{
96 if ($q->param("do") eq 'remove') {
98 my ($form, $buttons)=confirmation_form($q, $session);
99 IkiWiki::decode_form_utf8($form);
100 if ($form->submitted eq 'Cancel') {
101 # Load saved form state and return to edit form.
102 my $postremove=CGI->new($session->param("postremove"));
103 $session->clear("postremove");
104 IkiWiki::cgi_savesession($session);
105 IkiWiki::cgi($postremove, $session);
108 elsif ($form->submitted eq 'Remove' && $form->validate) {
109 error("removal not yet implemented"); # TODO
112 IkiWiki::showform($form, $buttons, $session, $q);