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};
12 # There can be multiple modules, with different configuration styles.
13 # The setup modules each convert the data into the hashes used by ikiwiki
14 # internally (if it's not already in that format), and store it in
15 # IkiWiki::Setup::$raw_setup, to pass it back to this module.
19 my $setup=IkiWiki::possibly_foolish_untaint(shift);
20 delete $config{setup};
21 #translators: The first parameter is a filename, and the second
22 #translators: is a (probably not translated) error message.
23 open (IN, $setup) || error(sprintf(gettext("cannot read %s: %s"), $setup, $!));
29 ($code)=$code=~/(.*)/s;
33 error("$setup: ".$@) if $@;
35 my %setup=%{$raw_setup};
38 # Merge setup into existing config and untaint.
39 $setup{plugin}=$config{plugin};
40 if (exists $setup{add_plugins}) {
41 push @{$setup{plugin}}, @{$setup{add_plugins}};
42 delete $setup{add_plugins};
44 if (exists $setup{exclude}) {
45 push @{$config{wiki_file_prune_regexps}}, $setup{exclude};
47 foreach my $c (keys %setup) {
48 if (defined $setup{$c}) {
49 if (! ref $setup{$c}) {
50 $config{$c}=IkiWiki::possibly_foolish_untaint($setup{$c});
52 elsif (ref $setup{$c} eq 'ARRAY') {
53 $config{$c}=[map { IkiWiki::possibly_foolish_untaint($_) } @{$setup{$c}}]
55 elsif (ref $setup{$c} eq 'HASH') {
56 foreach my $key (keys %{$setup{$c}}) {
57 $config{$c}{$key}=IkiWiki::possibly_foolish_untaint($setup{$c}{$key});