summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2009-01-27 16:57:52 +0100
committerintrigeri <intrigeri@boum.org>2009-01-27 17:08:55 +0100
commit51badc960d933f6d0670cc76390c332a31b35d63 (patch)
tree6adcb19e6f07399791ca150a19b0ad7acca89817 /IkiWiki
parent58481dcdf623aed8ab840ab86e3ac065c4bcb8a1 (diff)
rename hook: instead of modifying the passed-by-name array, return a copy
This is intended to solve Joey's concerns expressed on http://ikiwiki.info/todo/need_global_renamepage_hook/, i.e. the need to make it possible to use this hook from external plugins. A plugin using this hook still can add/modify/remove elements of the @torename array. Signed-off-by: intrigeri <intrigeri@boum.org>
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/po.pm22
-rw-r--r--IkiWiki/Plugin/rename.pm8
-rw-r--r--IkiWiki/Plugin/skeleton.pm.example4
3 files changed, 21 insertions, 13 deletions
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index 6f716a91f..6c6bb2cd1 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -329,29 +329,30 @@ sub postscan (@) {
}
# Add the renamed page translations to the list of to-be-renamed pages.
-sub renamepages($$$) {
- my ($torename, $cgi, $session) = (shift, shift, shift);
+sub renamepages(@) {
+ my %params = @_;
- # copy the initial array, so that we can iterate on it AND
- # modify it at the same time, without iterating on the items we
- # pushed on it ourselves
- my @torename=@{$torename};
+ my @torename = @{$params{torename}};
+ my $session = $params{session};
# Save the page(s) the user asked to rename, so that our
# canrename hook can tell the difference between:
# - a translation being renamed as a consequence of its master page
# being renamed
# - a user trying to directly rename a translation
- # This is why this hook has to be run first, before @torename is modified
- # by other plugins.
- $session->param(po_orig_torename => [ @torename ]);
+ # 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);
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 @{$torename}, {
+ push @ret, {
src => $otherpage,
srcfile => $pagesources{$otherpage},
dest => otherlanguage($rename->{dest}, $lang),
@@ -360,6 +361,7 @@ sub renamepages($$$) {
};
}
}
+ return @ret;
}
sub mydelete(@) {
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index 90af1b4a9..f39c93332 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -312,7 +312,13 @@ sub sessioncgi ($$) {
required => 1,
};
- IkiWiki::run_hooks(rename => sub { shift->(\@torename, $q, $session); });
+ 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) {
diff --git a/IkiWiki/Plugin/skeleton.pm.example b/IkiWiki/Plugin/skeleton.pm.example
index 62eeaf51d..573510191 100644
--- a/IkiWiki/Plugin/skeleton.pm.example
+++ b/IkiWiki/Plugin/skeleton.pm.example
@@ -229,8 +229,8 @@ sub renamepage (@) {
debug("skeleton plugin running in renamepage");
}
-sub rename ($$$) {
- my ($torename, $cgi, $session) = (shift, shift, shift);
+sub rename (@) {
+ my %params=@_;
debug("skeleton plugin running in rename");
}