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