2 # Ikiwiki setup files are perl files that 'use IkiWiki::Setup::foo',
3 # passing it some sort of configuration data.
5 package IkiWiki
::Setup
;
10 use open qw{:utf8
:std
};
14 my $setup=IkiWiki
::possibly_foolish_untaint
(shift);
15 $config{setupfile
}=File
::Spec
->rel2abs($setup);
17 #translators: The first parameter is a filename, and the second
18 #translators: is a (probably not translated) error message.
19 open (IN
, $setup) || error
(sprintf(gettext
("cannot read %s: %s"), $setup, $!));
25 ($code)=$code=~/(.*)/s;
29 error
("$setup: ".$@
) if $@
;
33 # Merge setup into existing config and untaint.
36 if (exists $setup{add_plugins
} && exists $config{add_plugins
}) {
37 push @
{$setup{add_plugins
}}, @
{$config{add_plugins
}};
39 if (exists $setup{exclude
}) {
40 push @
{$config{wiki_file_prune_regexps
}}, $setup{exclude
};
42 foreach my $c (keys %setup) {
43 if (defined $setup{$c}) {
44 if (! ref $setup{$c} || ref $setup{$c} eq 'Regexp') {
45 $config{$c}=IkiWiki
::possibly_foolish_untaint
($setup{$c});
47 elsif (ref $setup{$c} eq 'ARRAY') {
48 if ($c eq 'wrappers') {
49 # backwards compatability code
50 $config{$c}=$setup{$c};
53 $config{$c}=[map { IkiWiki
::possibly_foolish_untaint
($_) } @
{$setup{$c}}]
56 elsif (ref $setup{$c} eq 'HASH') {
57 foreach my $key (keys %{$setup{$c}}) {
58 $config{$c}{$key}=IkiWiki
::possibly_foolish_untaint
($setup{$c}{$key});
67 if (length $config{cgi_wrapper
}) {
68 push @
{$config{wrappers
}}, {
70 wrapper
=> $config{cgi_wrapper
},
71 wrappermode
=> (defined $config{cgi_wrappermode
} ?
$config{cgi_wrappermode
} : "06755"),
77 # Gets all available setup data from all plugins. Returns an
78 # ordered list of [plugin, setup] pairs.
81 # disable logging to syslog while dumping, broken plugins may
83 my $syslog=$config{syslog
};
84 $config{syslog
}=undef;
86 # Load all plugins, so that all setup options are available.
87 my @plugins=grep { $_ ne $config{rcs
} } sort(IkiWiki
::listplugins
());
88 unshift @plugins, $config{rcs
} if $config{rcs
}; # rcs plugin 1st
89 foreach my $plugin (@plugins) {
90 eval { IkiWiki
::loadplugin
($plugin) };
91 if (exists $IkiWiki::hooks
{checkconfig
}{$plugin}{call
}) {
92 my @s=eval { $IkiWiki::hooks
{checkconfig
}{$plugin}{call
}->() };
96 foreach my $plugin (@plugins) {
97 if (exists $IkiWiki::hooks
{getsetup
}{$plugin}{call
}) {
98 # use an array rather than a hash, to preserve order
99 my @s=eval { $IkiWiki::hooks
{getsetup
}{$plugin}{call
}->() };
101 push @ret, [ $plugin, \
@s ],
105 $config{syslog
}=$syslog;
111 my $file=IkiWiki
::possibly_foolish_untaint
(shift);
113 require IkiWiki
::Setup
::Standard
;
114 my @dump=IkiWiki
::Setup
::Standard
::gendump
("Setup file for ikiwiki.");
116 open (OUT
, ">", $file) || die "$file: $!";
117 print OUT
"$_\n" foreach @dump;