summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup.pm
blob: 778e1b495df26c14503fa0809ee10ce63d2fc292 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Setup;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  6. use open qw{:utf8 :std};
  7. # This hashref is where setup files store settings while they're being
  8. # loaded. It is not used otherwise.
  9. our $raw_setup;
  10. sub load ($) { # {{{
  11. my $setup=IkiWiki::possibly_foolish_untaint(shift);
  12. delete $config{setup};
  13. #translators: The first parameter is a filename, and the second
  14. #translators: is a (probably not translated) error message.
  15. open (IN, $setup) || error(sprintf(gettext("cannot read %s: %s"), $setup, $!));
  16. my $code;
  17. {
  18. local $/=undef;
  19. $code=<IN>;
  20. }
  21. ($code)=$code=~/(.*)/s;
  22. close IN;
  23. eval $code;
  24. error("$setup: ".$@) if $@;
  25. my $ret=$raw_setup;
  26. $raw_setup=undef;
  27. return %$ret;
  28. } #}}}
  29. package IkiWiki;
  30. sub setup () { #{{{
  31. my %setup=IkiWiki::Setup::load($config{setup});
  32. $setup{plugin}=$config{plugin};
  33. if (exists $setup{add_plugins}) {
  34. push @{$setup{plugin}}, @{$setup{add_plugins}};
  35. delete $setup{add_plugins};
  36. }
  37. if (exists $setup{exclude}) {
  38. push @{$config{wiki_file_prune_regexps}}, $setup{exclude};
  39. }
  40. if (! $config{render} && (! $config{refresh} || $config{wrappers})) {
  41. debug(gettext("generating wrappers.."));
  42. my @wrappers=@{$setup{wrappers}};
  43. delete $setup{wrappers};
  44. my %startconfig=(%config);
  45. foreach my $wrapper (@wrappers) {
  46. %config=(%startconfig, rebuild => 0, verbose => 0, %setup, %{$wrapper});
  47. checkconfig();
  48. if (! $config{cgi} && ! $config{post_commit}) {
  49. $config{post_commit}=1;
  50. }
  51. gen_wrapper();
  52. }
  53. %config=(%startconfig);
  54. }
  55. foreach my $c (keys %setup) {
  56. next if $c eq 'syslog';
  57. if (defined $setup{$c}) {
  58. if (! ref $setup{$c}) {
  59. $config{$c}=IkiWiki::possibly_foolish_untaint($setup{$c});
  60. }
  61. elsif (ref $setup{$c} eq 'ARRAY') {
  62. $config{$c}=[map { IkiWiki::possibly_foolish_untaint($_) } @{$setup{$c}}]
  63. }
  64. elsif (ref $setup{$c} eq 'HASH') {
  65. foreach my $key (keys %{$setup{$c}}) {
  66. $config{$c}{$key}=IkiWiki::possibly_foolish_untaint($setup{$c}{$key});
  67. }
  68. }
  69. }
  70. else {
  71. $config{$c}=undef;
  72. }
  73. }
  74. if (! $config{refresh}) {
  75. $config{rebuild}=1;
  76. }
  77. loadplugins();
  78. checkconfig();
  79. if ($config{render}) {
  80. commandline_render();
  81. }
  82. if (! $config{refresh}) {
  83. debug(gettext("rebuilding wiki.."));
  84. }
  85. else {
  86. debug(gettext("refreshing wiki.."));
  87. }
  88. lockwiki();
  89. loadindex();
  90. refresh();
  91. debug(gettext("done"));
  92. saveindex();
  93. } #}}}
  94. 1