From 8cfe428a28b2714c57282566466f4f7bdbdfdffb Mon Sep 17 00:00:00 2001 From: intrigeri Date: Sun, 8 Mar 2009 11:44:00 +0100 Subject: 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 --- IkiWiki/Plugin/rename.pm | 51 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'IkiWiki/Plugin/rename.pm') 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; -- cgit v1.2.3