]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
web commit by JonasSmedegaard: Corrected typo: imge -> image.
[ikiwiki.git] / IkiWiki.pm
index d369d7da839589f3d440a47e083a241e3cf45389..2face7082dc78e9be743fb65a91f29d36c56524b 100644 (file)
@@ -11,7 +11,7 @@ use Memoize;
 memoize("abs2rel");
 
 use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
-            %renderedfiles %pagesources %depends %hooks};
+            %renderedfiles %pagesources %depends %hooks %forcerebuild};
 
 sub defaultconfig () { #{{{
        wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
@@ -93,11 +93,7 @@ sub checkconfig () { #{{{
                require IkiWiki::Rcs::Stub;
        }
 
-       if (exists $hooks{checkconfig}) {
-                foreach my $id (keys %{$hooks{checkconfig}}) {
-                        $hooks{checkconfig}{$id}{call}->();
-                }
-        }
+       run_hooks(checkconfig => sub { shift->() });
 } #}}}
 
 sub loadplugins () { #{{{
@@ -108,6 +104,12 @@ sub loadplugins () { #{{{
                        error("Failed to load plugin $mod: $@");
                }
        }
+       run_hooks(getopt => sub { shift->() });
+       if (grep /^-/, @ARGV) {
+               print STDERR "Unknown option: $_\n"
+                       foreach grep /^-/, @ARGV;
+               usage();
+       }
 } #}}}
 
 sub error ($) { #{{{
@@ -399,6 +401,8 @@ sub loadindex () { #{{{
 } #}}}
 
 sub saveindex () { #{{{
+       run_hooks(savestate => sub { shift->() });
+
        if (! -d $config{wikistatedir}) {
                mkdir($config{wikistatedir});
        }
@@ -503,4 +507,17 @@ sub hook (@) { # {{{
        $hooks{$param{type}}{$param{id}}=\%param;
 } # }}}
 
+sub run_hooks ($$) { # {{{
+       # Calls the given sub for each hook of the given type,
+       # passing it the hook function to call.
+       my $type=shift;
+       my $sub=shift;
+
+       if (exists $hooks{$type}) {
+               foreach my $id (keys %{$hooks{$type}}) {
+                       $sub->($hooks{$type}{$id}{call});
+               }
+       }
+} #}}}
+
 1