summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: fb542be20d80dcca05ac7560b35c17e1932f3b32 (plain)
  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. use warnings;
  6. use strict;
  7. use IkiWiki::Wrapper;
  8. use IkiWiki::Render;
  9. package IkiWiki::Setup::Standard;
  10. sub import {
  11. IkiWiki::setup_standard(@_);
  12. }
  13. package IkiWiki;
  14. sub setup_standard {
  15. my %setup=%{$_[1]};
  16. $setup{plugin}=$config{plugin};
  17. if (exists $setup{add_plugins}) {
  18. push @{$setup{plugin}}, @{$setup{add_plugins}};
  19. delete $setup{add_plugins};
  20. }
  21. if (exists $setup{exclude}) {
  22. push @{$config{wiki_file_prune_regexps}}, $setup{exclude};
  23. }
  24. if (! $config{render} && (! $config{refresh} || $config{wrappers})) {
  25. debug(gettext("generating wrappers.."));
  26. my @wrappers=@{$setup{wrappers}};
  27. delete $setup{wrappers};
  28. my %startconfig=(%config);
  29. foreach my $wrapper (@wrappers) {
  30. %config=(%startconfig, rebuild => 0, verbose => 0, %setup, %{$wrapper});
  31. checkconfig();
  32. if (! $config{cgi} && ! $config{post_commit}) {
  33. $config{post_commit}=1;
  34. }
  35. gen_wrapper();
  36. }
  37. %config=(%startconfig);
  38. }
  39. foreach my $c (keys %setup) {
  40. next if $c eq 'syslog';
  41. if (defined $setup{$c}) {
  42. if (! ref $setup{$c}) {
  43. $config{$c}=possibly_foolish_untaint($setup{$c});
  44. }
  45. elsif (ref $setup{$c} eq 'ARRAY') {
  46. $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
  47. }
  48. elsif (ref $setup{$c} eq 'HASH') {
  49. foreach my $key (keys %{$setup{$c}}) {
  50. $config{$c}{$key}=possibly_foolish_untaint($setup{$c}{$key});
  51. }
  52. }
  53. }
  54. else {
  55. $config{$c}=undef;
  56. }
  57. }
  58. loadplugins();
  59. checkconfig();
  60. if ($config{render}) {
  61. commandline_render();
  62. }
  63. if (! $config{refresh}) {
  64. $config{rebuild}=1;
  65. debug(gettext("rebuilding wiki.."));
  66. }
  67. else {
  68. debug(gettext("refreshing wiki.."));
  69. }
  70. lockwiki();
  71. loadindex();
  72. refresh();
  73. debug(gettext("done"));
  74. saveindex();
  75. }
  76. 1