summaryrefslogtreecommitdiff
path: root/IkiWiki/Setup/Standard.pm
blob: f3f7bae5a746d0b6d0ef67b7866a8bcad80aa3f3 (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, 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. if (defined $setup{$c}) {
  41. if (! ref $setup{$c}) {
  42. $config{$c}=possibly_foolish_untaint($setup{$c});
  43. }
  44. elsif (ref $setup{$c} eq 'ARRAY') {
  45. $config{$c}=[map { possibly_foolish_untaint($_) } @{$setup{$c}}]
  46. }
  47. elsif (ref $setup{$c} eq 'HASH') {
  48. foreach my $key (keys %{$setup{$c}}) {
  49. $config{$c}{$key}=possibly_foolish_untaint($setup{$c}{$key});
  50. }
  51. }
  52. }
  53. else {
  54. $config{$c}=undef;
  55. }
  56. }
  57. if ($config{render}) {
  58. commandline_render();
  59. }
  60. elsif (! $config{refresh}) {
  61. $config{rebuild}=1;
  62. debug(gettext("rebuilding wiki.."));
  63. }
  64. else {
  65. debug(gettext("refreshing wiki.."));
  66. }
  67. loadplugins();
  68. checkconfig();
  69. lockwiki();
  70. loadindex();
  71. refresh();
  72. debug(gettext("done"));
  73. saveindex();
  74. }
  75. 1