diff options
author | intrigeri <intrigeri@boum.org> | 2009-03-08 11:44:00 +0100 |
---|---|---|
committer | intrigeri <intrigeri@boum.org> | 2009-03-08 11:44:00 +0100 |
commit | 8cfe428a28b2714c57282566466f4f7bdbdfdffb (patch) | |
tree | 3548f3deab8249300ae72813f3ee5399db715377 /IkiWiki/Plugin/rename.pm | |
parent | ae474d8e14631ff519ed7d54bb64eaa0538f56d9 (diff) | |
download | ikiwiki-8cfe428a28b2714c57282566466f4f7bdbdfdffb.tar ikiwiki-8cfe428a28b2714c57282566466f4f7bdbdfdffb.tar.gz |
rename hook: run once per file to be renamed
... as Joey suggested on todo/need_global_renamepage_hook
This hook is applied recursively to returned additional rename
hashes, so that it handles the case where two plugins use the hook:
plugin A would see when plugin B adds a new file to be renamed.
The full set of rename hashes can no longer be changed by hook functions, that
are only allowed to return any additional rename hashes it wants to add.
Rationale: the correct behavior of the recursion would be hard, if not
impossible, to define, if already considered pages were changing on the run.
Signed-off-by: intrigeri <intrigeri@boum.org>
Diffstat (limited to 'IkiWiki/Plugin/rename.pm')
-rw-r--r-- | IkiWiki/Plugin/rename.pm | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm index f39c93332..ccbf09c3f 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm @@ -312,14 +312,6 @@ sub sessioncgi ($$) { required => 1, }; - IkiWiki::run_hooks(rename => sub { - @torename=shift->( - torename => \@torename, - cgi => $q, - session => $session - ); - }); - # See if any subpages need to be renamed. if ($q->param("subpages") && $src ne $dest) { foreach my $p (keys %pagesources) { @@ -341,6 +333,13 @@ sub sessioncgi ($$) { } } + @torename=rename_hook( + torename => \@torename, + done => {}, + cgi => $q, + session => $session, + ); + require IkiWiki::Render; IkiWiki::disable_commit_hook() if $config{rcs}; my %origpagesources=%pagesources; @@ -466,6 +465,42 @@ sub renamepage_hook ($$$$) { return $content; } + +sub rename_hook (@) { + my %params = @_; + + my @torename=@{$params{torename}}; + my %done=%{$params{done}}; + my $q=$params{cgi}; + my $session=$params{session}; + + debug("rename_hook called with ".scalar(@torename)." args."); + my @nextset; + if (@torename) { + foreach my $torename (@torename) { + unless (exists $done{$torename->{src}} && $done{$torename->{src}}) { + IkiWiki::run_hooks(rename => sub { + push @nextset, shift->( + torename => $torename, + cgi => $q, + session => $session, + ); + }); + $done{$torename->{src}}=1; + } + } + push @torename, rename_hook( + torename => \@nextset, + done => \%done, + cgi => $q, + session => $session, + ); + return @torename; + } + else { + return (); + } +} sub do_rename ($$$) { my $rename=shift; |