summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: 0a34968855a2cd26ac4609d27b73b2d0e440ea76 (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. if (! $config{refresh}) {
  59. $config{rebuild}=1;
  60. }
  61. loadplugins();
  62. checkconfig();
  63. if ($config{render}) {
  64. commandline_render();
  65. }
  66. if (! $config{refresh}) {
  67. debug(gettext("rebuilding wiki.."));
  68. }
  69. else {
  70. debug(gettext("refreshing wiki.."));
  71. }
  72. lockwiki();
  73. loadindex();
  74. refresh();
  75. debug(gettext("done"));
  76. saveindex();
  77. }
  78. 1