2 package IkiWiki::Plugin::websetup;
9 hook(type => "sessioncgi", id => "websetup",
10 call => \&sessioncgi);
11 hook(type => "formbuilder_setup", id => "websetup",
12 call => \&formbuilder_setup);
23 next if ! $info{safe} || $info{type} eq "internal";
25 my $description=exists $info{description_html} ? $info{description_html} : $info{description};
27 my $value=$config{$key};
28 # multiple plugins can have the same key
29 my $name=$section.".".$key;
31 if ($info{type} eq "string") {
34 label => $description,
35 comment => exists $info{example} && length $info{example} && $info{example} ne $value ? "<br/ ><small>Example: <tt>$info{example}</tt></small>" : "",
42 elsif ($info{type} eq "integer") {
45 label => $description,
48 validate => '/^[0-9]+$/',
52 elsif ($info{type} eq "boolean") {
58 options => [ [ 1 => $description ] ],
65 sub showform ($$) { #{{{
69 if (! defined $session->param("name") ||
70 ! IkiWiki::is_admin($session->param("name"))) {
71 error(gettext("you are not logged in as an admin"));
74 eval q{use CGI::FormBuilder};
77 my $form = CGI::FormBuilder->new(
85 action => $config{cgiurl},
86 template => {type => 'div'},
87 stylesheet => IkiWiki::baseurl()."style.css",
89 my $buttons=["Save Setup", "Cancel"];
91 IkiWiki::decode_form_utf8($form);
92 IkiWiki::run_hooks(formbuilder_setup => sub {
93 shift->(form => $form, cgi => $cgi, session => $session,
96 IkiWiki::decode_form_utf8($form);
98 $form->field(name => "do", type => "hidden", value => "setup",
100 addfields($form, gettext("main"), IkiWiki::getsetup());
101 require IkiWiki::Setup;
102 foreach my $pair (IkiWiki::Setup::getsetup()) {
103 my $plugin=$pair->[0];
104 my $setup=$pair->[1];
105 addfields($form, $plugin." ".gettext("plugin"), @{$setup});
108 if ($form->submitted eq "Cancel") {
109 IkiWiki::redirect($cgi, $config{url});
112 elsif ($form->submitted eq 'Save Setup' && $form->validate) {
115 $form->text(gettext("Setup saved."));
118 IkiWiki::showform($form, $buttons, $session, $cgi);
121 sub sessioncgi ($$) { #{{{
125 if ($cgi->param("do") eq "setup") {
126 showform($cgi, $session);
131 sub formbuilder_setup (@) { #{{{
134 my $form=$params{form};
135 if ($form->title eq "preferences") {
136 push @{$params{buttons}}, "Wiki Setup";
137 if ($form->submitted && $form->submitted eq "Wiki Setup") {
138 showform($params{cgi}, $params{session});