summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/Plugin/link.pm4
-rw-r--r--IkiWiki/Plugin/po.pm17
-rw-r--r--IkiWiki/Plugin/rename.pm16
-rw-r--r--doc/plugins/write.mdwn20
-rwxr-xr-xt/renamepage.t4
5 files changed, 32 insertions, 29 deletions
diff --git a/IkiWiki/Plugin/link.pm b/IkiWiki/Plugin/link.pm
index 3799209d0..e9623035b 100644
--- a/IkiWiki/Plugin/link.pm
+++ b/IkiWiki/Plugin/link.pm
@@ -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 => "renamepage", id => "link", call => \&renamepage);
+ hook(type => "renamelink", id => "link", call => \&renamelink);
}
sub getsetup () {
@@ -90,7 +90,7 @@ sub scan (@) {
}
}
-sub renamepage (@) {
+sub renamelink (@) {
my %params=@_;
my $page=$params{page};
my $old=$params{oldpage};
diff --git a/IkiWiki/Plugin/po.pm b/IkiWiki/Plugin/po.pm
index ae97a2f38..081752132 100644
--- a/IkiWiki/Plugin/po.pm
+++ b/IkiWiki/Plugin/po.pm
@@ -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 => "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);
@@ -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.
-#
-# 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);
- return $params{content};
} #}}}
sub mydelete(@) { #{{{
@@ -822,9 +812,6 @@ sub homepageurl (;$) { #{{{
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;
@@ -832,7 +819,7 @@ sub deletetranslations ($) { #{{{
} #}}}
sub renametranslations (@) { #{{{
- my ($oldpage, $newpage)=shift;
+ my ($oldpage, $newpage)=(shift, shift);
debug "po(renametranslations): TODO: rename translations of $oldpage to $newpage";
} #}}}
diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm
index b1bb15767..2200235f6 100644
--- a/IkiWiki/Plugin/rename.pm
+++ b/IkiWiki/Plugin/rename.pm
@@ -195,7 +195,7 @@ sub postrename ($;$$$) {
# 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.
@@ -338,10 +338,16 @@ 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) {
@@ -420,10 +426,10 @@ sub sessioncgi ($$) {
}
}
-sub renamepage_hook ($$$$) {
+sub renamelink_hook ($$$$) {
my ($page, $src, $dest, $content)=@_;
- IkiWiki::run_hooks(renamepage => sub {
+ IkiWiki::run_hooks(renamelink => sub {
$content=shift->(
page => $page,
oldpage => $src,
@@ -480,7 +486,7 @@ sub fixlinks ($$$) {
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) };
diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn
index 9b5cf27f7..79a9066ce 100644
--- a/doc/plugins/write.mdwn
+++ b/doc/plugins/write.mdwn
@@ -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.
-### 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
-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
diff --git a/t/renamepage.t b/t/renamepage.t
index a706cbb46..0aa3a1c9f 100755
--- a/t/renamepage.t
+++ b/t/renamepage.t
@@ -11,7 +11,7 @@ BEGIN { use_ok("IkiWiki::Plugin::link"); }
$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)=@_;
@@ -23,7 +23,7 @@ sub try {
$links{$page}=[];
}
- IkiWiki::Plugin::link::renamepage(
+ IkiWiki::Plugin::link::renamelink(
page => $page,
oldpage => $oldpage,
newpage => $newpage,