2 # Ikiwiki setup files are perl files that 'use IkiWiki::Setup::foo',
3 # passing it some sort of configuration data.
5 # There can be multiple modules, with different configuration styles.
6 # The setup modules each convert the data into the hashes used by ikiwiki
7 # internally (if it's not already in that format), and store it in
8 # IkiWiki::Setup::$raw_setup, to pass it back to this module.
10 package IkiWiki::Setup;
14 use open qw{:utf8 :std};
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 $@;
44 my %setup=IkiWiki::Setup::load($config{setup});
46 $setup{plugin}=$config{plugin};
47 if (exists $setup{add_plugins}) {
48 push @{$setup{plugin}}, @{$setup{add_plugins}};
49 delete $setup{add_plugins};
51 if (exists $setup{exclude}) {
52 push @{$config{wiki_file_prune_regexps}}, $setup{exclude};
55 if (! $config{render} && (! $config{refresh} || $config{wrappers})) {
56 debug(gettext("generating wrappers.."));
57 my @wrappers=@{$setup{wrappers}};
58 delete $setup{wrappers};
59 my %startconfig=(%config);
60 foreach my $wrapper (@wrappers) {
61 %config=(%startconfig, rebuild => 0, verbose => 0, %setup, %{$wrapper});
63 if (! $config{cgi} && ! $config{post_commit}) {
64 $config{post_commit}=1;
68 %config=(%startconfig);
71 foreach my $c (keys %setup) {
72 next if $c eq 'syslog';
73 if (defined $setup{$c}) {
74 if (! ref $setup{$c}) {
75 $config{$c}=possibly_foolish_untaint($setup{$c});
77 elsif (ref $setup{$c} eq 'ARRAY') {
78 $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
80 elsif (ref $setup{$c} eq 'HASH') {
81 foreach my $key (keys %{$setup{$c}}) {
82 $config{$c}{$key}=possibly_foolish_untaint($setup{$c}{$key});
91 if (! $config{refresh}) {
98 if ($config{render}) {
102 if (! $config{refresh}) {
103 debug(gettext("rebuilding wiki.."));
106 debug(gettext("refreshing wiki.."));
113 debug(gettext("done"));