]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/websetup.pm
e1536a1a7a238c1422960845ab49c3e6943721c4
[git.ikiwiki.info.git] / IkiWiki / Plugin / websetup.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::websetup;
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
8 sub import { #{{{
9         hook(type => "sessioncgi", id => "websetup",
10              call => \&sessioncgi);
11         hook(type => "formbuilder_setup", id => "websetup",
12              call => \&formbuilder_setup);
13 } # }}}
15 sub showform ($$) { #{{{
16         my $cgi=shift;
17         my $session=shift;
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         }
24         eval q{use CGI::FormBuilder};
25         error($@) if $@;
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"];
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);
47         $form->field(name => "do", type => "hidden", value => "setup",
48                 force => 1);
50         if (! $form->submitted) {
51                 # TODO
52         }
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
61                 $form->text(gettext("Setup saved."));
62         }
64         IkiWiki::showform($form, $buttons, $session, $cgi);
65 } #}}}
67 sub sessioncgi ($$) { #{{{
68         my $cgi=shift;
69         my $session=shift;
71         if ($cgi->param("do") eq "setup") {
72                 showform($cgi, $session);
73                 exit;
74         }
75 } #}}}
77 sub formbuilder_setup (@) { #{{{
78         my %params=@_;
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 } #}}}
90 1