rebuild detection

master
Joey Hess 2008-08-02 23:32:40 -04:00
parent 8c02d670d0
commit 7baa6320e0
1 changed files with 35 additions and 8 deletions

View File

@ -85,7 +85,7 @@ sub showfields ($$$@) { #{{{
my %shownfields; my %shownfields;
if (defined $plugin) { if (defined $plugin) {
if (showplugintoggle($form, $plugin, $enabled, $section)) { if (showplugintoggle($form, $plugin, $enabled, $section)) {
$shownfields{"enable.$plugin"}=$plugin; $shownfields{"enable.$plugin"}=[$plugin];
} }
elsif (! $enabled) { elsif (! $enabled) {
# plugin not enabled and cannot be, so skip showing # plugin not enabled and cannot be, so skip showing
@ -154,7 +154,7 @@ sub showfields ($$$@) { #{{{
$form->text(gettext("Note: Disabled options cannot be configured here, but only by editing the setup file.")); $form->text(gettext("Note: Disabled options cannot be configured here, but only by editing the setup file."));
} }
else { else {
$shownfields{$name}=$key; $shownfields{$name}=[$key, \%info];
} }
} }
@ -249,7 +249,7 @@ sub showform ($$) { #{{{
# list all remaining plugins (with no setup options) at the end # list all remaining plugins (with no setup options) at the end
foreach (sort keys %plugins) { foreach (sort keys %plugins) {
if (showplugintoggle($form, $_, $enabled_plugins{$_}, gettext("other plugins"))) { if (showplugintoggle($form, $_, $enabled_plugins{$_}, gettext("other plugins"))) {
$fields{"enable.$_"}=$_; $fields{"enable.$_"}=[$_];
} }
} }
@ -257,24 +257,51 @@ sub showform ($$) { #{{{
IkiWiki::redirect($cgi, $config{url}); IkiWiki::redirect($cgi, $config{url});
return; return;
} }
elsif ($form->submitted eq 'Save Setup' && $form->validate) { elsif (($form->submitted eq 'Save Setup' || $form->submitted eq 'Rebuild Wiki') && $form->validate) {
my %rebuild;
foreach my $field (keys %fields) { foreach my $field (keys %fields) {
# TODO plugin enable/disable # TODO plugin enable/disable
next if $field=~/^enable\./; # plugin next if $field=~/^enable\./; # plugin
my $key=$fields{$field}; my $key=$fields{$field}->[0];
my %info=%{$fields{$field}->[1]};
my $value=$form->field($field); my $value=$form->field($field);
if (! $info{safe}) {
error("unsafe field $key"); # should never happen
}
next unless defined $value; next unless defined $value;
# Avoid setting fields to empty strings, # Avoid setting fields to empty strings,
# if they were not set before. # if they were not set before.
next if ! defined $config{$key} && ! length $value; next if ! defined $config{$key} && ! length $value;
if ($info{rebuild} && (! defined $config{$key} || $config{$key} ne $value)) {
$rebuild{$field}=1;
}
$config{$key}=$value; $config{$key}=$value;
} }
# TODO save to real path
IkiWiki::Setup::dump("/tmp/s"); if (%rebuild && $form->submitted eq 'Save Setup') {
$form->text(gettext("Setup saved.")); $form->text(gettext("The configuration changes shown below require a wiki rebuild to take effect."));
foreach my $field ($form->field) {
next if $rebuild{$field};
$form->field(name => $field, type => "hidden",
force => 1);
}
$form->reset(0); # doesn't really make sense here
$buttons=["Rebuild Wiki", "Cancel"];
}
else {
# TODO save to real path
IkiWiki::Setup::dump("/tmp/s");
$form->text(gettext("Setup saved."));
if (%rebuild) {
# TODO rebuild
}
}
} }
IkiWiki::showform($form, $buttons, $session, $cgi); IkiWiki::showform($form, $buttons, $session, $cgi);