]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Setup.pm
clarifications, comments
[git.ikiwiki.info.git] / IkiWiki / Setup.pm
1 #!/usr/bin/perl
2 # Ikiwiki setup files are perl files that 'use IkiWiki::Setup::foo',
3 # passing it some sort of configuration data.
4 #
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;
11 use warnings;
12 use strict;
13 use IkiWiki;
14 use open qw{:utf8 :std};
16 our $raw_setup;
18 sub load ($) { # {{{
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, $!));
24         my $code;
25         {
26                 local $/=undef;
27                 $code=<IN>;
28         }
29         ($code)=$code=~/(.*)/s;
30         close IN;
32         eval $code;
33         error("$setup: ".$@) if $@;
35         my $ret=$raw_setup;
36         $raw_setup=undef;
38         return %$ret;
39 } #}}}
41 package IkiWiki;
43 sub setup () { #{{{
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};
50         }
51         if (exists $setup{exclude}) {
52                 push @{$config{wiki_file_prune_regexps}}, $setup{exclude};
53         }
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});
62                         checkconfig();
63                         if (! $config{cgi} && ! $config{post_commit}) {
64                                 $config{post_commit}=1;
65                         }
66                         gen_wrapper();
67                 }
68                 %config=(%startconfig);
69         }
70         
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});
76                         }
77                         elsif (ref $setup{$c} eq 'ARRAY') {
78                                 $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
79                         }
80                         elsif (ref $setup{$c} eq 'HASH') {
81                                 foreach my $key (keys %{$setup{$c}}) {
82                                         $config{$c}{$key}=possibly_foolish_untaint($setup{$c}{$key});
83                                 }
84                         }
85                 }
86                 else {
87                         $config{$c}=undef;
88                 }
89         }
90         
91         if (! $config{refresh}) {
92                 $config{rebuild}=1;
93         }
94         
95         loadplugins();
96         checkconfig();
98         if ($config{render}) {
99                 commandline_render();
100         }
102         if (! $config{refresh}) {
103                 debug(gettext("rebuilding wiki.."));
104         }
105         else {
106                 debug(gettext("refreshing wiki.."));
107         }
109         lockwiki();
110         loadindex();
111         refresh();
113         debug(gettext("done"));
114         saveindex();
115 } #}}}