2 # Ikiwiki setup files are perl files that 'use IkiWiki::Setup::foo',
3 # passing it some sort of configuration data.
5 package IkiWiki::Setup;
10 use open qw{:utf8 :std};
13 my $setup=IkiWiki::possibly_foolish_untaint(shift);
14 delete $config{setup};
15 #translators: The first parameter is a filename, and the second
16 #translators: is a (probably not translated) error message.
17 open (IN, $setup) || error(sprintf(gettext("cannot read %s: %s"), $setup, $!));
23 ($code)=$code=~/(.*)/s;
27 error("$setup: ".$@) if $@;
33 # Merge setup into existing config and untaint.
34 if (exists $setup{add_plugins}) {
35 push @{$setup{add_plugins}}, @{$config{add_plugins}};
37 if (exists $setup{exclude}) {
38 push @{$config{wiki_file_prune_regexps}}, $setup{exclude};
40 foreach my $c (keys %setup) {
41 if (defined $setup{$c}) {
42 if (! ref $setup{$c} || ref $setup{$c} eq 'Regexp') {
43 $config{$c}=IkiWiki::possibly_foolish_untaint($setup{$c});
45 elsif (ref $setup{$c} eq 'ARRAY') {
46 if ($c eq 'wrappers') {
47 # backwards compatability code
48 $config{$c}=$setup{$c};
51 $config{$c}=[map { IkiWiki::possibly_foolish_untaint($_) } @{$setup{$c}}]
54 elsif (ref $setup{$c} eq 'HASH') {
55 foreach my $key (keys %{$setup{$c}}) {
56 $config{$c}{$key}=IkiWiki::possibly_foolish_untaint($setup{$c}{$key});
65 if (length $config{cgi_wrapper}) {
66 push @{$config{wrappers}}, {
68 wrapper => $config{cgi_wrapper},
69 wrappermode => (defined $config{cgi_wrappermode} ? $config{cgi_wrappermode} : "06755"),
75 my $file=IkiWiki::possibly_foolish_untaint(shift);
77 require IkiWiki::Setup::Standard;
78 my @dump=IkiWiki::Setup::Standard::gendump("Setup file for ikiwiki.");
80 open (OUT, ">", $file) || die "$file: $!";
81 print OUT "$_\n" foreach @dump;