b1418ae34743272c583e35cdbe915026a236c258
[ikiwiki.git] / IkiWiki / Setup / Standard.pm
1 #!/usr/bin/perl
2 # Standard ikiwiki setup module.
3 # Parameters to import should be all the standard ikiwiki config stuff,
4 # plus an array of wrappers to set up.
5
6 use warnings;
7 use strict;
8 use IkiWiki::Wrapper;
9 use IkiWiki::Render;
10
11 package IkiWiki::Setup::Standard;
12
13 sub import {
14         IkiWiki::setup_standard(@_);
15 }
16         
17 package IkiWiki;
18
19 sub setup_standard {
20         my %setup=%{$_[1]};
21
22         $setup{plugin}=$config{plugin};
23         if (exists $setup{add_plugins}) {
24                 push @{$setup{plugin}}, @{$setup{add_plugins}};
25                 delete $setup{add_plugins};
26         }
27         if (exists $setup{disable_plugins}) {
28                 foreach my $plugin (@{$setup{disable_plugins}}) {
29                         $setup{plugin}=[grep { $_ ne $plugin } @{$setup{plugin}}];
30                 }
31                 delete $setup{disable_plugins};
32         }
33         if (exists $setup{exclude}) {
34                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$setup{exclude}/;
35         }
36
37         debug("generating wrappers..");
38         my @wrappers=@{$setup{wrappers}};
39         delete $setup{wrappers};
40         my %startconfig=(%config);
41         foreach my $wrapper (@wrappers) {
42                 %config=(%startconfig, verbose => 0, %setup, %{$wrapper});
43                 checkconfig();
44                 gen_wrapper();
45         }
46         %config=(%startconfig);
47         
48         foreach my $c (keys %setup) {
49                 if (defined $setup{$c}) {
50                         if (! ref $setup{$c}) {
51                                 $config{$c}=possibly_foolish_untaint($setup{$c});
52                         }
53                         elsif (ref $setup{$c} eq 'ARRAY') {
54                                 $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
55                         }
56                 }
57                 else {
58                         $config{$c}=undef;
59                 }
60         }
61
62         if (! $config{refresh}) {
63                 $config{rebuild}=1;
64                 debug("rebuilding wiki..");
65         }
66         else {
67                 debug("refreshing wiki..");
68         }
69
70         loadplugins();
71         checkconfig();
72         lockwiki();
73         loadindex();
74         refresh();
75
76         debug("done");
77         saveindex();
78 }
79
80 1