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