]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
the rename hook can now change the list of pages to rename
authorintrigeri <intrigeri@boum.org>
Tue, 30 Dec 2008 21:55:04 +0000 (22:55 +0100)
committerintrigeri <intrigeri@boum.org>
Tue, 30 Dec 2008 21:55:04 +0000 (22:55 +0100)
Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/po.pm
IkiWiki/Plugin/rename.pm
doc/plugins/write.mdwn

index 081752132887aa26ca9b964ea3c241289a71f39a..15b07e84b481c6a82f5930ce14c79828303e26ec 100644 (file)
@@ -35,7 +35,7 @@ sub import { #{{{
        hook(type => "filter", id => "po", call => \&filter);
        hook(type => "htmlize", id => "po", call => \&htmlize);
        hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
-       hook(type => "rename", id => "po", call => \&renamepage);
+       hook(type => "rename", id => "po", call => \&renamepages);
        hook(type => "delete", id => "po", call => \&mydelete);
        hook(type => "change", id => "po", call => \&change);
        hook(type => "editcontent", id => "po", call => \&editcontent);
@@ -327,15 +327,30 @@ sub pagetemplate (@) { #{{{
        }
 } # }}}
 
+# Add the renamed page translations to the list of to-be-renamed pages.
 # Save information about master page rename, so that:
 # - our delete hook can ignore the translations not renamed already
 # - our change hook can rename the translations accordingly.
-sub renamepage(@) { #{{{
-       my %params=@_;
-       my $oldpage=$params{oldpage};
-       my $newpage=$params{newpage};
-
-       setrenamed($oldpage, $newpage) if istranslatable($oldpage);
+sub renamepages() { #{{{
+       my $torename=shift;
+       my @torename=@{$torename};
+
+       foreach my $rename (@torename) {
+               next unless istranslatable($rename->{src});
+               setrenamed($rename->{src}, $rename->{dest});
+               my %otherpages=%{otherlanguages($rename->{src})};
+               debug "bla".$rename->{src};
+               while (my ($lang, $otherpage) = each %otherpages) {
+                       push @{$torename}, {
+                               src => $otherpage,
+                               srcfile => $pagesources{$otherpage},
+                               dest => otherlanguage($rename->{dest}, $lang),
+                               destfile => $rename->{dest}.".".$lang.".po",
+                               required => 0,
+                       };
+                       debug "po(renamepages): pushed src=$otherpage, dest=".otherlanguage($rename->{dest}, $lang);
+               }
+       }
 } #}}}
 
 sub mydelete(@) { #{{{
@@ -821,7 +836,8 @@ sub deletetranslations ($) { #{{{
 sub renametranslations (@) { #{{{
        my ($oldpage, $newpage)=(shift, shift);
 
-       debug "po(renametranslations): TODO: rename translations of $oldpage to $newpage";
+       # FIXME - not needed anymore : debug "po(renametranslations): TODO: rename translations of $oldpage to $newpage";
+       
 } #}}}
 
 
index 2200235f6df40794592bc5bba9969b797b7e5fcc..227f59bfa45baf719e93cf8163f59659d74df004 100644 (file)
@@ -291,6 +291,8 @@ sub sessioncgi ($$) {
                                required => 1,
                        };
 
+                       IkiWiki::run_hooks(rename => sub { shift->(\@torename); });
+
                        # See if any subpages need to be renamed.
                        if ($q->param("subpages") && $src ne $dest) {
                                foreach my $p (keys %pagesources) {
@@ -338,16 +340,10 @@ sub sessioncgi ($$) {
                                sprintf(gettext("rename %s to %s"), $srcfile, $destfile),
                                $session->param("name"), $ENV{REMOTE_ADDR}) if $config{rcs};
 
+                       # Then link fixups.
                        foreach my $rename (@torename) {
                                next if $rename->{src} eq $rename->{dest};
                                next if $rename->{error};
-                               IkiWiki::run_hooks(rename => sub {
-                                       shift->(
-                                               oldpage => $src,
-                                               newpage => $dest,
-                                       );
-                               });
-                               # Then link fixups.
                                foreach my $p (fixlinks($rename, $session)) {
                                        # map old page names to new
                                        foreach my $r (@torename) {
index 79a9066ce7434dc96fa803661dba60bb0a119f48..d024a5dd47b6fe9066ece1413ad97e241536ba11 100644 (file)
@@ -373,11 +373,12 @@ new page.
 
 ### rename
 
-       hook(type => "rename", id => "foo", call => \&renamepage);
+       hook(type => "rename", id => "foo", call => \&renamepages);
 
 When a page or set of pages is renamed, the referenced function is
-called once per renamed page, and passed named parameters: `oldpage`,
-`newpage`.
+called, and passed a reference to an array of hashes with keys:
+`src`, `srcfile`, `dest`, `destfile`, `required`. It can modify
+the array.
 
 ### getsetup