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 renamepage (@) {
+sub renamelink (@) {
my %params=@_;
my $page=$params{page};
my $old=$params{oldpage};
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);
# 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(@) { #{{{
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 renametranslations (@) { #{{{
- my ($oldpage, $newpage)=shift;
+ my ($oldpage, $newpage)=(shift, shift);
debug "po(renametranslations): TODO: rename translations of $oldpage to $newpage";
} #}}}
# 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.
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) {
}
}
-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,
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) };
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
$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)=@_;
$links{$page}=[];
}
- IkiWiki::Plugin::link::renamepage(
+ IkiWiki::Plugin::link::renamelink(
page => $page,
oldpage => $oldpage,
newpage => $newpage,