safe => 0,
rebuild => 0,
},
+ websetup_unsafe => {
+ type => "string",
+ example => [],
+ description => "list of additional setup field keys to treat as unsafe",
+ safe => 0,
+ rebuild => 0,
+ },
websetup_show_unsafe => {
type => "boolean",
example => 1,
}
}
+sub issafe ($) {
+ my $key=shift;
+
+ return ! grep { $_ eq $key } @{$config{websetup_unsafe}};
+}
+
sub showfields ($$$@) {
my $form=shift;
my $plugin=shift;
# XXX hashes not handled yet
next if ref $config{$key} && ref $config{$key} eq 'HASH' || ref $info{example} eq 'HASH';
# maybe skip unsafe settings
- next if ! $info{safe} && ! ($config{websetup_show_unsafe} && $config{websetup_advanced});
+ next if ! ($config{websetup_show_unsafe} && $config{websetup_advanced}) &&
+ (! $info{safe} || ! issafe($key));
# maybe skip advanced settings
next if $info{advanced} && ! $config{websetup_advanced};
# these are handled specially, so don't show
}
my $section=defined $plugin
- ? sprintf(gettext("%s plugin:"), $plugininfo{section}).$plugin
+ ? sprintf(gettext("%s plugin:"), $plugininfo{section})." ".$plugin
: "main";
my %enabledfields;
my $shownfields=0;
my %info=%{shift @show};
my $description=$info{description};
- if (exists $info{link} && length $info{link}) {
+ if (exists $info{htmldescription}) {
+ $description=$info{htmldescription};
+ }
+ elsif (exists $info{link} && length $info{link}) {
if ($info{link} =~ /^\w+:\/\//) {
$description="<a href=\"$info{link}\">$description</a>";
}
if (ref $value eq 'ARRAY' || ref $info{example} eq 'ARRAY') {
$value=[(ref $value eq 'ARRAY' ? map { Encode::encode_utf8($_) } @{$value} : "")];
- push @$value, "", "" if $info{safe}; # blank items for expansion
+ push @$value, "", "" if $info{safe} && issafe($key); # blank items for expansion
}
else {
$value=Encode::encode_utf8($value);
options => [ [ 1 => $description ] ],
fieldset => $section,
);
- if (! $form->submitted) {
+ if (! $form->submitted ||
+ ($info{advanced} && $form->submitted eq 'Advanced Mode')) {
$form->field(name => $name, value => $value);
}
}
- if (! $info{safe}) {
+ if (! $info{safe} || ! issafe($key)) {
$form->field(name => $name, disabled => 1);
}
else {
sub disable_plugin ($) {
my $plugin=shift;
- if (grep { $_ eq $plugin } @{$config{add_plugins}}) {
- $config{add_plugins}=[grep { $_ ne $plugin } @{$config{add_plugins}}];
- }
- else {
- push @{$config{disable_plugins}}, $plugin;
- }
+ $config{add_plugins}=[grep { $_ ne $plugin } @{$config{add_plugins}}];
+ push @{$config{disable_plugins}}, $plugin;
}
sub showform ($$) {
my $cgi=shift;
my $session=shift;
+ IkiWiki::needsignin($cgi, $session);
+
if (! defined $session->param("name") ||
! IkiWiki::is_admin($session->param("name"))) {
error(gettext("you are not logged in as an admin"));
fieldsets => [
[main => gettext("main")],
],
- action => $config{cgiurl},
+ action => IkiWiki::cgiurl(),
template => {type => 'div'},
- stylesheet => IkiWiki::baseurl()."style.css",
+ stylesheet => 1,
);
$form->field(name => "do", type => "hidden", value => "setup",
force => 1);
$form->field(name => "rebuild_asked", type => "hidden");
+ $form->field(name => "showadvanced", type => "hidden");
if ($form->submitted eq 'Basic Mode') {
$form->field(name => "showadvanced", type => "hidden",
IkiWiki::decode_form_utf8($form);
if ($form->submitted eq "Cancel") {
- IkiWiki::redirect($cgi, $config{url});
+ IkiWiki::redirect($cgi, IkiWiki::baseurl(undef));
return;
}
elsif (($form->submitted eq 'Save Setup' || $form->submitted eq 'Rebuild Wiki') && $form->validate) {
@value=0;
}
- if (! $info{safe}) {
+ if (! $info{safe} || ! issafe($key)) {
error("unsafe field $key"); # should never happen
}
IkiWiki::saveindex();
IkiWiki::unlockwiki();
- # Print the top part of a standard misctemplate,
- # then show the rebuild or refresh.
- my $divider="xxx";
- my $html=IkiWiki::misctemplate("setup", $divider);
+ # Print the top part of a standard cgitemplate,
+ # then show the rebuild or refresh, live.
+ my $divider="\0";
+ my $html=IkiWiki::cgitemplate($cgi, "setup", $divider);
IkiWiki::printheader($session);
my ($head, $tail)=split($divider, $html, 2);
print $head."<pre>\n";
my @command;
if ($form->submitted eq 'Rebuild Wiki') {
- @command=("ikiwiki", "-setup", $config{setupfile},
- "-rebuild", "-v");
+ @command=("ikiwiki", "--setup", $config{setupfile},
+ "--rebuild", "-v");
}
else {
- @command=("ikiwiki", "-setup", $config{setupfile},
- "-refresh", "-wrappers", "-v");
+ @command=("ikiwiki", "--setup", $config{setupfile},
+ "--refresh", "--wrappers", "-v");
}
close STDERR;
join(" ", @command), $ret).
'</p>';
open(OUT, ">", $config{setupfile}) || error("$config{setupfile}: $!");
- print OUT $oldsetup;
+ print OUT Encode::encode_utf8($oldsetup);
close OUT;
}
my %params=@_;
my $form=$params{form};
- if ($form->title eq "preferences") {
- push @{$params{buttons}}, "Wiki Setup";
- if ($form->submitted && $form->submitted eq "Wiki Setup") {
+ if ($form->title eq "preferences" &&
+ IkiWiki::is_admin($params{session}->param("name"))) {
+ push @{$params{buttons}}, "Setup";
+ if ($form->submitted && $form->submitted eq "Setup") {
showform($params{cgi}, $params{session});
exit;
}