* Add getopt hook type, this allows plugins to add new command-line options.
[ikiwiki] / 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
34         debug("generating wrappers..");
35         my @wrappers=@{$setup{wrappers}};
36         delete $setup{wrappers};
37         my %startconfig=(%config);
38         foreach my $wrapper (@wrappers) {
39                 %config=(%startconfig, verbose => 0, %setup, %{$wrapper});
40                 checkconfig();
41                 gen_wrapper();
42         }
43         %config=(%startconfig);
44         
45         foreach my $c (keys %setup) {
46                 if (defined $setup{$c}) {
47                         if (! ref $setup{$c}) {
48                                 $config{$c}=possibly_foolish_untaint($setup{$c});
49                         }
50                         elsif (ref $setup{$c} eq 'ARRAY') {
51                                 $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
52                         }
53                 }
54                 else {
55                         $config{$c}=undef;
56                 }
57         }
58
59         if (! $config{refresh}) {
60                 $config{rebuild}=1;
61                 debug("rebuilding wiki..");
62         }
63         else {
64                 debug("refreshing wiki..");
65         }
66
67         loadplugins();
68         checkconfig();
69         lockwiki();
70         loadindex();
71         refresh();
72
73         debug("done");
74         saveindex();
75 }
76
77 1