diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-08-02 13:27:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-08-02 16:41:35 -0400 |
commit | 680cd2fbc3c3df34409bfdc2bdb3f7473c1b1523 (patch) | |
tree | 4ca654a414d261ebac42434753385e814cc20796 /IkiWiki/Plugin | |
parent | 017f6787e7a656d08b61eb1a634c678ed63be597 (diff) |
skeleton of web setup plugin
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/websetup.pm | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/websetup.pm b/IkiWiki/Plugin/websetup.pm new file mode 100644 index 000000000..e1536a1a7 --- /dev/null +++ b/IkiWiki/Plugin/websetup.pm @@ -0,0 +1,90 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::websetup; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import { #{{{ + hook(type => "sessioncgi", id => "websetup", + call => \&sessioncgi); + hook(type => "formbuilder_setup", id => "websetup", + call => \&formbuilder_setup); +} # }}} + +sub showform ($$) { #{{{ + my $cgi=shift; + my $session=shift; + + if (! defined $session->param("name") || + ! IkiWiki::is_admin($session->param("name"))) { + error(gettext("you are not logged in as an admin")); + } + + eval q{use CGI::FormBuilder}; + error($@) if $@; + + my $form = CGI::FormBuilder->new( + title => "setup", + name => "setup", + header => 0, + charset => "utf-8", + method => 'POST', + params => $cgi, + action => $config{cgiurl}, + template => {type => 'div'}, + stylesheet => IkiWiki::baseurl()."style.css", + ); + my $buttons=["Save Setup", "Cancel"]; + + IkiWiki::decode_form_utf8($form); + IkiWiki::run_hooks(formbuilder_setup => sub { + shift->(form => $form, cgi => $cgi, session => $session, + buttons => $buttons); + }); + IkiWiki::decode_form_utf8($form); + + $form->field(name => "do", type => "hidden", value => "setup", + force => 1); + + if (! $form->submitted) { + # TODO + } + + if ($form->submitted eq "Cancel") { + IkiWiki::redirect($cgi, $config{url}); + return; + } + elsif ($form->submitted eq 'Save Setup' && $form->validate) { + # TODO + + $form->text(gettext("Setup saved.")); + } + + IkiWiki::showform($form, $buttons, $session, $cgi); +} #}}} + +sub sessioncgi ($$) { #{{{ + my $cgi=shift; + my $session=shift; + + if ($cgi->param("do") eq "setup") { + showform($cgi, $session); + exit; + } +} #}}} + +sub formbuilder_setup (@) { #{{{ + my %params=@_; + + my $form=$params{form}; + if ($form->title eq "preferences") { + push @{$params{buttons}}, "Wiki Setup"; + if ($form->submitted && $form->submitted eq "Wiki Setup") { + showform($params{cgi}, $params{session}); + exit; + } + } +} #}}} + +1 |