skeleton of web setup plugin
[ikiwiki.git] / IkiWiki / Plugin / websetup.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::websetup;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7
8 sub import { #{{{
9         hook(type => "sessioncgi", id => "websetup",
10              call => \&sessioncgi);
11         hook(type => "formbuilder_setup", id => "websetup",
12              call => \&formbuilder_setup);
13 } # }}}
14
15 sub showform ($$) { #{{{
16         my $cgi=shift;
17         my $session=shift;
18
19         if (! defined $session->param("name") || 
20             ! IkiWiki::is_admin($session->param("name"))) {
21                 error(gettext("you are not logged in as an admin"));
22         }
23
24         eval q{use CGI::FormBuilder};
25         error($@) if $@;
26
27         my $form = CGI::FormBuilder->new(
28                 title => "setup",
29                 name => "setup",
30                 header => 0,
31                 charset => "utf-8",
32                 method => 'POST',
33                 params => $cgi,
34                 action => $config{cgiurl},
35                 template => {type => 'div'},
36                 stylesheet => IkiWiki::baseurl()."style.css",
37         );
38         my $buttons=["Save Setup", "Cancel"];
39
40         IkiWiki::decode_form_utf8($form);
41         IkiWiki::run_hooks(formbuilder_setup => sub {
42                 shift->(form => $form, cgi => $cgi, session => $session,
43                         buttons => $buttons);
44         });
45         IkiWiki::decode_form_utf8($form);
46
47         $form->field(name => "do", type => "hidden", value => "setup",
48                 force => 1);
49
50         if (! $form->submitted) {
51                 # TODO
52         }
53
54         if ($form->submitted eq "Cancel") {
55                 IkiWiki::redirect($cgi, $config{url});
56                 return;
57         }
58         elsif ($form->submitted eq 'Save Setup' && $form->validate) {
59                 # TODO
60
61                 $form->text(gettext("Setup saved."));
62         }
63
64         IkiWiki::showform($form, $buttons, $session, $cgi);
65 } #}}}
66
67 sub sessioncgi ($$) { #{{{
68         my $cgi=shift;
69         my $session=shift;
70
71         if ($cgi->param("do") eq "setup") {
72                 showform($cgi, $session);
73                 exit;
74         }
75 } #}}}
76
77 sub formbuilder_setup (@) { #{{{
78         my %params=@_;
79
80         my $form=$params{form};
81         if ($form->title eq "preferences") {
82                 push @{$params{buttons}}, "Wiki Setup";
83                 if ($form->submitted && $form->submitted eq "Wiki Setup") {
84                         showform($params{cgi}, $params{session});
85                         exit;
86                 }
87         }
88 } #}}}
89
90 1