From: Joey Hess Date: Sun, 3 Aug 2008 03:06:25 +0000 (-0400) Subject: collect a hash of shown fields X-Git-Tag: 2.60~116 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/94c59d3254dd97be541cd8ff03ccf3c29b5a55b8 collect a hash of shown fields Need to do this to know what fields to take from CGI. (Can't trust that only safe ones are sent..) --- diff --git a/.IkiWiki.pm.swp b/.IkiWiki.pm.swp deleted file mode 100644 index adf830d94..000000000 Binary files a/.IkiWiki.pm.swp and /dev/null differ diff --git a/IkiWiki/Plugin/websetup.pm b/IkiWiki/Plugin/websetup.pm index 150c792a5..64c4d0991 100644 --- a/IkiWiki/Plugin/websetup.pm +++ b/IkiWiki/Plugin/websetup.pm @@ -78,15 +78,19 @@ sub showfields ($$$@) { #{{{ push @show, $key, \%info; } - return 0 unless @show; + return unless @show; my $section=defined $plugin ? $plugin." ".gettext("plugin") : gettext("main"); + my %shownfields; if (defined $plugin) { - if (! showplugintoggle($form, $plugin, $enabled, $section) && ! $enabled) { + if (showplugintoggle($form, $plugin, $enabled, $section)) { + $shownfields{"enable.$plugin"}=$plugin; + } + elsif (! $enabled) { # plugin not enabled and cannot be, so skip showing # its configuration - return 0; + return; } } @@ -149,9 +153,12 @@ sub showfields ($$$@) { #{{{ $form->field(name => $name, disabled => 1); $form->text(gettext("Note: Disabled options cannot be configured here, but only by editing the setup file.")); } + else { + $shownfields{$name}=$key; + } } - return 1; + return %shownfields; } #}}} sub showplugintoggle ($$$$) { #{{{ @@ -170,7 +177,7 @@ sub showplugintoggle ($$$$) { #{{{ } $form->field( - name => "enable.$plugin", + ame => "enable.$plugin", label => "", type => "checkbox", options => [ [ 1 => sprintf(gettext("enable %s?"), $plugin) ] ], @@ -217,7 +224,7 @@ sub showform ($$) { #{{{ $form->field(name => "do", type => "hidden", value => "setup", force => 1); - showfields($form, undef, undef, IkiWiki::getsetup()); + my %fields=showfields($form, undef, undef, IkiWiki::getsetup()); # record all currently enabled plugins before all are loaded my %enabled_plugins=%IkiWiki::loaded_plugins; @@ -232,19 +239,31 @@ sub showform ($$) { #{{{ # skip all rcs plugins except for the one in use next if $plugin ne $config{rcs} && grep { $_ eq $plugin } @rcs_plugins; - delete $plugins{$plugin} if showfields($form, $plugin, $enabled_plugins{$plugin}, @{$setup}); + my %shown=showfields($form, $plugin, $enabled_plugins{$plugin}, @{$setup}); + if (%shown) { + delete $plugins{$plugin}; + $fields{$_}=$shown{$_} foreach keys %shown; + } } # list all remaining plugins (with no setup options) at the end - showplugintoggle($form, $_, $enabled_plugins{$_}, gettext("other plugins")) - foreach sort keys %plugins; + foreach (sort keys %plugins) { + if (showplugintoggle($form, $_, $enabled_plugins{$_}, gettext("other plugins"))) { + $fields{"enable.$_"}=$_; + } + } if ($form->submitted eq "Cancel") { IkiWiki::redirect($cgi, $config{url}); return; } elsif ($form->submitted eq 'Save Setup' && $form->validate) { - # TODO + foreach my $field (keys %fields) { + # TODO plugin enable/disable + next if $field=~/^enable\./; # plugin + $config{$fields{$field}}=$form->field($field); + } + # TODO save to real path IkiWiki::Setup::dump("/tmp/s"); $form->text(gettext("Setup saved.")); }