]> sipb.mit.edu Git - ikiwiki.git/commitdiff
renamed the renamepage hook to renamelink, added rename hook
authorintrigeri <intrigeri@boum.org>
Tue, 30 Dec 2008 20:36:40 +0000 (21:36 +0100)
committerintrigeri <intrigeri@boum.org>
Tue, 30 Dec 2008 20:36:40 +0000 (21:36 +0100)
Signed-off-by: intrigeri <intrigeri@boum.org>
IkiWiki/Plugin/link.pm
IkiWiki/Plugin/po.pm
IkiWiki/Plugin/rename.pm
doc/plugins/write.mdwn
t/renamepage.t

index 3799209d062ad4308cebb3cead4e5f2617a87508..e9623035b92f7fea8d1a33b40cd20d26505a83cf 100644 (file)
@@ -12,7 +12,7 @@ sub import {
        hook(type => "checkconfig", id => "link", call => \&checkconfig);
        hook(type => "linkify", id => "link", call => \&linkify);
        hook(type => "scan", id => "link", call => \&scan);
        hook(type => "checkconfig", id => "link", call => \&checkconfig);
        hook(type => "linkify", id => "link", call => \&linkify);
        hook(type => "scan", id => "link", call => \&scan);
-       hook(type => "renamepage", id => "link", call => \&renamepage);
+       hook(type => "renamelink", id => "link", call => \&renamelink);
 }
 
 sub getsetup () {
 }
 
 sub getsetup () {
@@ -90,7 +90,7 @@ sub scan (@) {
        }
 }
 
        }
 }
 
-sub renamepage (@) {
+sub renamelink (@) {
        my %params=@_;
        my $page=$params{page};
        my $old=$params{oldpage};
        my %params=@_;
        my $page=$params{page};
        my $old=$params{oldpage};
index ae97a2f380bb9fbc0518ea865dda04bcccd5cae2..081752132887aa26ca9b964ea3c241289a71f39a 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 => "filter", id => "po", call => \&filter);
        hook(type => "htmlize", id => "po", call => \&htmlize);
        hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
-       hook(type => "renamepage", id => "po", call => \&renamepage);
+       hook(type => "rename", id => "po", call => \&renamepage);
        hook(type => "delete", id => "po", call => \&mydelete);
        hook(type => "change", id => "po", call => \&change);
        hook(type => "editcontent", id => "po", call => \&editcontent);
        hook(type => "delete", id => "po", call => \&mydelete);
        hook(type => "change", id => "po", call => \&change);
        hook(type => "editcontent", id => "po", call => \&editcontent);
@@ -330,22 +330,12 @@ sub pagetemplate (@) { #{{{
 # 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.
 # 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.
-#
-# FIXME:
-# This hook is called once per page linking to the old page, which
-# means our delete hook won't know it should not delete a renamed orphan
-# page's translation.
-#
-# Moreover, we can't recognize such pages at delete stage:
-# existing links are fixed in the renaming process, so every
-# renamed page's old location will be an orphan anyway at this time.
 sub renamepage(@) { #{{{
        my %params=@_;
        my $oldpage=$params{oldpage};
        my $newpage=$params{newpage};
 
        setrenamed($oldpage, $newpage) if istranslatable($oldpage);
 sub renamepage(@) { #{{{
        my %params=@_;
        my $oldpage=$params{oldpage};
        my $newpage=$params{newpage};
 
        setrenamed($oldpage, $newpage) if istranslatable($oldpage);
-       return $params{content};
 } #}}}
 
 sub mydelete(@) { #{{{
 } #}}}
 
 sub mydelete(@) { #{{{
@@ -822,9 +812,6 @@ sub homepageurl (;$) { #{{{
        return urlto('', $page);
 } #}}}
 
        return urlto('', $page);
 } #}}}
 
-# - do *not* implement this until the renamepage hook works
-# - do *not* delete translations of pages that were orphans
-#   before being renamed (see renamepage hook comments above)
 sub deletetranslations ($) { #{{{
        my $deletedmasterfile=shift;
 
 sub deletetranslations ($) { #{{{
        my $deletedmasterfile=shift;
 
@@ -832,7 +819,7 @@ sub deletetranslations ($) { #{{{
 } #}}}
 
 sub renametranslations (@) { #{{{
 } #}}}
 
 sub renametranslations (@) { #{{{
-       my ($oldpage, $newpage)=shift;
+       my ($oldpage, $newpage)=(shift, shift);
 
        debug "po(renametranslations): TODO: rename translations of $oldpage to $newpage";
 } #}}}
 
        debug "po(renametranslations): TODO: rename translations of $oldpage to $newpage";
 } #}}}
index b1bb1576728945a00238949ce48821fe6cc1d5f5..2200235f6df40794592bc5bba9969b797b7e5fcc 100644 (file)
@@ -195,7 +195,7 @@ sub postrename ($;$$$) {
                # Update edit form content to fix any links present
                # on it.
                $postrename->param("editcontent",
                # Update edit form content to fix any links present
                # on it.
                $postrename->param("editcontent",
-                       renamepage_hook($dest, $src, $dest,
+                       renamelink_hook($dest, $src, $dest,
                                 $postrename->param("editcontent")));
 
                # Get a new edit token; old was likely invalidated.
                                 $postrename->param("editcontent")));
 
                # Get a new edit token; old was likely invalidated.
@@ -338,10 +338,16 @@ sub sessioncgi ($$) {
                                sprintf(gettext("rename %s to %s"), $srcfile, $destfile),
                                $session->param("name"), $ENV{REMOTE_ADDR}) if $config{rcs};
 
                                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};
                        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) {
                                foreach my $p (fixlinks($rename, $session)) {
                                        # map old page names to new
                                        foreach my $r (@torename) {
@@ -420,10 +426,10 @@ sub sessioncgi ($$) {
        }
 }
 
        }
 }
 
-sub renamepage_hook ($$$$) {
+sub renamelink_hook ($$$$) {
        my ($page, $src, $dest, $content)=@_;
 
        my ($page, $src, $dest, $content)=@_;
 
-       IkiWiki::run_hooks(renamepage => sub {
+       IkiWiki::run_hooks(renamelink => sub {
                $content=shift->(
                        page => $page,
                        oldpage => $src,
                $content=shift->(
                        page => $page,
                        oldpage => $src,
@@ -480,7 +486,7 @@ sub fixlinks ($$$) {
                if ($needfix) {
                        my $file=$pagesources{$page};
                        my $oldcontent=readfile($config{srcdir}."/".$file);
                if ($needfix) {
                        my $file=$pagesources{$page};
                        my $oldcontent=readfile($config{srcdir}."/".$file);
-                       my $content=renamepage_hook($page, $rename->{src}, $rename->{dest}, $oldcontent);
+                       my $content=renamelink_hook($page, $rename->{src}, $rename->{dest}, $oldcontent);
                        if ($oldcontent ne $content) {
                                my $token=IkiWiki::rcs_prepedit($file);
                                eval { writefile($file, $config{srcdir}, $content) };
                        if ($oldcontent ne $content) {
                                my $token=IkiWiki::rcs_prepedit($file);
                                eval { writefile($file, $config{srcdir}, $content) };
index 9b5cf27f7c91028066cea797f197a8a5cc8601a1..79a9066ce7434dc96fa803661dba60bb0a119f48 100644 (file)
@@ -360,14 +360,24 @@ This hook is called whenever ikiwiki normally saves its state, just before
 the state is saved. The function can save other state, modify values before
 they're saved, etc.
 
 the state is saved. The function can save other state, modify values before
 they're saved, etc.
 
-### renamepage
+### renamelink
 
 
-       hook(type => "renamepage", id => "foo", call => \&renamepage);
+       hook(type => "renamelink", id => "foo", call => \&renamelink);
 
 This hook is called by the [[plugins/rename]] plugin when it renames
 
 This hook is called by the [[plugins/rename]] plugin when it renames
-something. The hook is passed named parameters: `page`, `oldpage`,
-`newpage`, and `content`, and should try to modify the content to reflect
-the name change. For example, by converting links to point to the new page.
+something, once per page linking to the renamed page's old location.
+The hook is passed named parameters: `page`, `oldpage`, `newpage`, and
+`content`, and should try to modify the content of `page` to reflect
+the name change. For example, by converting links to point to the
+new page.
+
+### rename
+
+       hook(type => "rename", id => "foo", call => \&renamepage);
+
+When a page or set of pages is renamed, the referenced function is
+called once per renamed page, and passed named parameters: `oldpage`,
+`newpage`.
 
 ### getsetup
 
 
 ### getsetup
 
index a706cbb46a15466c0adf9e579a0aeabf12f01ec6..0aa3a1c9fda8b127446516490429de1b2c01f164 100755 (executable)
@@ -11,7 +11,7 @@ BEGIN { use_ok("IkiWiki::Plugin::link"); }
 $config{srcdir}=$config{destdir}="/dev/null";
 IkiWiki::checkconfig();
 
 $config{srcdir}=$config{destdir}="/dev/null";
 IkiWiki::checkconfig();
 
-# tests of the link plugin's renamepage function
+# tests of the link plugin's renamelink function
 sub try {
        my ($page, $oldpage, $newpage, $content)=@_;
 
 sub try {
        my ($page, $oldpage, $newpage, $content)=@_;
 
@@ -23,7 +23,7 @@ sub try {
                $links{$page}=[];
        }
 
                $links{$page}=[];
        }
 
-       IkiWiki::Plugin::link::renamepage(
+       IkiWiki::Plugin::link::renamelink(
                        page => $page, 
                        oldpage => $oldpage,
                        newpage => $newpage,
                        page => $page, 
                        oldpage => $oldpage,
                        newpage => $newpage,