supports things like conditionals and loops in templates and is pretty easy
to learn.
+I aim to keep almost all html out of ikiwiki and in the templates.
+
It ships with some basic templates which can be customised:
* `templates/page.tmpl` - Used for displaying all regular wiki pages.
* `templates/passwordmail.tmpl` - Not a html template, this is used to
generate the mail with the user's password in it.
-If you like, you can add this to further customise it:
+If you like, you can add these to further customise it:
* `templates/signin.tmpl` - If it exists, it is used for customising the
layout of the SignIn form and all assciated forms. The misc.tmpl is
wrapped around this, so it should only be a template for the form.
+* `templates/prefs.tmpl` - If it exists, it is used for customising the
+ layout of the Prefs form and all assciated forms. The misc.tmpl is
+ wrapped around this, so it should only be a template for the form.
- Note that the SignIn form is implemented using CGI::FormBuilder, which
- interfaces to HTML::Template, so not all of it can be customised with
- templates, although most of it can, by creating this template. Without
- the template, CGI::FormBuilder creates the page body by itself.
-
-I aim to keep almost all html out of ikiwiki and in the templates.
+Note that the SignIn and Prefs forms are implemented using
+CGI::FormBuilder, which interfaces to HTML::Template, so not all of it can
+be customised with templates, although most of it can, by creating these
+templates. Without the templates, CGI::FormBuilder creates the page bodies
+by itself.
if (length $config{cgiurl}) {
$template->param(editurl => "$config{cgiurl}?do=edit&page=$page");
+ $template->param(prefsurl => "$config{cgiurl}?do=prefs");
if ($config{svn}) {
$template->param(recentchangesurl => "$config{cgiurl}?do=recentchanges");
}
return $userdata->{$user}->{$field};
} #}}}
-sub userinfo_set ($$) { #{{{
+sub userinfo_set ($$$) { #{{{
+ my $user=shift;
+ my $field=shift;
+ my $value=shift;
+
+ eval q{use Storable};
+ my $userdata=eval{ Storable::lock_retrieve("$config{srcdir}/.ikiwiki/userdb") };
+ if (! defined $userdata || ! ref $userdata ||
+ ! exists $userdata->{$user} || ! ref $userdata->{$user}) {
+ return "";
+ }
+
+ $userdata->{$user}->{$field}=$value;
+ my $oldmask=umask(077);
+ my $ret=Storable::lock_store($userdata, "$config{srcdir}/.ikiwiki/userdb");
+ umask($oldmask);
+ return $ret;
+} #}}}
+
+sub userinfo_setall ($$) { #{{{
my $user=shift;
my $info=shift;
eval q{use CGI::FormBuilder};
my $form = CGI::FormBuilder->new(
- title => "$config{wikiname} signin",
+ title => "signin",
fields => [qw(do page from name password confirm_password email)],
header => 1,
method => 'POST',
$form->field(name => "confirm_password", type => "password", required => 0);
$form->field(name => "email", required => 0);
if ($q->param("do") ne "signin") {
- $form->text("You need to log in before you can edit pages.");
+ $form->text("You need to log in first.");
}
if ($form->submitted) {
}
elsif ($form->submitted eq 'Register') {
my $user_name=$form->field('name');
- if (userinfo_set($user_name, {
+ if (userinfo_setall($user_name, {
'email' => $form->field('email'),
'password' => $form->field('password'),
'regdate' => time
}
} #}}}
+sub cgi_prefs ($$) { #{{{
+ my $q=shift;
+ my $session=shift;
+
+ eval q{use CGI::FormBuilder};
+ my $form = CGI::FormBuilder->new(
+ title => "preferences",
+ fields => [qw(do name password confirm_password email)],
+ header => 0,
+ method => 'POST',
+ validate => {
+ confirm_password => {
+ perl => q{eq $form->field("password")},
+ },
+ email => 'EMAIL',
+ },
+ required => 'NONE',
+ javascript => 0,
+ params => $q,
+ action => $q->request_uri,
+ template => (-e "$config{templatedir}/prefs.tmpl" ?
+ "$config{templatedir}/prefs.tmpl" : "")
+ );
+ my @buttons=("Save Preferences", "Logout", "Cancel");
+
+ my $user_name=$session->param("name");
+ $form->field(name => "do", type => "hidden");
+ $form->field(name => "name", disabled => 1,
+ value => $user_name, force => 1);
+ $form->field(name => "password", type => "password");
+ $form->field(name => "confirm_password", type => "password");
+
+ if (! $form->submitted) {
+ $form->field(name => "email", value => userinfo_get($user_name, "email"));
+ }
+
+ if ($form->submitted eq 'Logout') {
+ $session->delete();
+ print $q->redirect($config{url});
+ return;
+ }
+ elsif ($form->submitted eq 'Cancel') {
+ print $q->redirect($config{url});
+ return;
+ }
+ elsif ($form->submitted eq "Save Preferences" && $form->validate) {
+ foreach my $field (qw(password email)) {
+ if (length $form->field($field)) {
+ userinfo_set($user_name, $field, $form->field($field)) || error("failed to set $field");
+ }
+ }
+ $form->text("Preferences saved.");
+ }
+
+ print $session->header();
+ print misctemplate($form->title, $form->render(submit => \@buttons));
+} #}}}
+
sub cgi_editpage ($$) { #{{{
my $q=shift;
my $session=shift;
# Everything below this point needs the user to be signed in.
if ((! $config{anonok} && ! defined $session->param("name") ||
- ! userinfo_get($session->param("name"), "regdate")) || $do eq 'signin') {
+ ! defined $session->param("name") ||
+ ! userinfo_get($session->param("name"), "regdate")) || $do eq 'signin') {
cgi_signin($q, $session);
# Force session flush with safe umask.
if ($do eq 'create' || $do eq 'edit') {
cgi_editpage($q, $session);
}
+ elsif ($do eq 'prefs') {
+ cgi_prefs($q, $session);
+ }
else {
error("unknown do parameter");
}