summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/po.pm37
-rw-r--r--IkiWiki/Plugin/rename.pm51
2 files changed, 62 insertions, 26 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 9a3df79ac..f25beba72 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -295,7 +295,7 @@ sub pagetemplate (@) {
sub renamepages(@) {
my %params = @_;
- my @torename = @{$params{torename}};
+ my %torename = %{$params{torename}};
my $session = $params{session};
# Save the page(s) the user asked to rename, so that our
@@ -305,24 +305,25 @@ sub renamepages(@) {
# - a user trying to directly rename a translation
# This is why this hook has to be run first, before the list of pages
# to rename is modified by other plugins.
- $session->param(po_orig_torename => \@torename);
+ my @orig_torename;
+ @orig_torename=@{$session->param("po_orig_torename")}
+ if defined $session->param("po_orig_torename");
+ push @orig_torename, $torename{src};
+ $session->param(po_orig_torename => \@orig_torename);
IkiWiki::cgi_savesession($session);
- my @ret=@torename;
- # iterate on @torename and push onto @ret, so that we don't iterate
- # on the items we added ourselves
- foreach my $rename (@torename) {
- next unless istranslatable($rename->{src});
- my %otherpages=%{otherlanguages($rename->{src})};
- while (my ($lang, $otherpage) = each %otherpages) {
- push @ret, {
- src => $otherpage,
- srcfile => $pagesources{$otherpage},
- dest => otherlanguage($rename->{dest}, $lang),
- destfile => $rename->{dest}.".".$lang.".po",
- required => 0,
- };
- }
+ return () unless istranslatable($torename{src});
+
+ my @ret;
+ my %otherpages=%{otherlanguages($torename{src})};
+ while (my ($lang, $otherpage) = each %otherpages) {
+ push @ret, {
+ src => $otherpage,
+ srcfile => $pagesources{$otherpage},
+ dest => otherlanguage($torename{dest}, $lang),
+ destfile => $torename{dest}.".".$lang.".po",
+ required => 0,
+ };
}
return @ret;
}
@@ -443,7 +444,7 @@ sub canrename (@) {
# by looking for the master page in the list of to-be-renamed pages we
# saved early in the renaming process.
my $orig_torename = $session->param("po_orig_torename");
- unless (grep { $_->{src} eq $masterpage } @{$orig_torename}) {
+ unless (grep { $_ eq $masterpage } @{$orig_torename}) {
return gettext("Can not rename a translation. Renaming the master page, ".
"though, renames its translations as well.");
}
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;