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;
16 use open qw{:utf8 :std};
21 my $setup=IkiWiki::possibly_foolish_untaint(shift);
22 delete $config{setup};
23 #translators: The first parameter is a filename, and the second
24 #translators: is a (probably not translated) error message.
25 open (IN, $setup) || error(sprintf(gettext("cannot read %s: %s"), $setup, $!));
31 ($code)=$code=~/(.*)/s;
35 error("$setup: ".$@) if $@;
46 my %setup=IkiWiki::Setup::load($config{setup});
48 $setup{plugin}=$config{plugin};
49 if (exists $setup{add_plugins}) {
50 push @{$setup{plugin}}, @{$setup{add_plugins}};
51 delete $setup{add_plugins};
53 if (exists $setup{exclude}) {
54 push @{$config{wiki_file_prune_regexps}}, $setup{exclude};
57 if (! $config{render} && (! $config{refresh} || $config{wrappers})) {
58 debug(gettext("generating wrappers.."));
59 my @wrappers=@{$setup{wrappers}};
60 delete $setup{wrappers};
61 my %startconfig=(%config);
62 foreach my $wrapper (@wrappers) {
63 %config=(%startconfig, rebuild => 0, verbose => 0, %setup, %{$wrapper});
65 if (! $config{cgi} && ! $config{post_commit}) {
66 $config{post_commit}=1;
70 %config=(%startconfig);
73 foreach my $c (keys %setup) {
74 next if $c eq 'syslog';
75 if (defined $setup{$c}) {
76 if (! ref $setup{$c}) {
77 $config{$c}=possibly_foolish_untaint($setup{$c});
79 elsif (ref $setup{$c} eq 'ARRAY') {
80 $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
82 elsif (ref $setup{$c} eq 'HASH') {
83 foreach my $key (keys %{$setup{$c}}) {
84 $config{$c}{$key}=possibly_foolish_untaint($setup{$c}{$key});
93 if (! $config{refresh}) {
100 require IkiWiki::Render;
102 if ($config{render}) {
103 commandline_render();
106 if (! $config{refresh}) {
107 debug(gettext("rebuilding wiki.."));
110 debug(gettext("refreshing wiki.."));
117 debug(gettext("done"));