renamed the renamepage hook to renamelink, added rename hook
Signed-off-by: intrigeri <intrigeri@boum.org>master
parent
4e4fb18dbe
commit
c01485ae1a
|
@ -12,7 +12,7 @@ sub import {
|
||||||
hook(type => "checkconfig", id => "link", call => \&checkconfig);
|
hook(type => "checkconfig", id => "link", call => \&checkconfig);
|
||||||
hook(type => "linkify", id => "link", call => \&linkify);
|
hook(type => "linkify", id => "link", call => \&linkify);
|
||||||
hook(type => "scan", id => "link", call => \&scan);
|
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 %params=@_;
|
||||||
my $page=$params{page};
|
my $page=$params{page};
|
||||||
my $old=$params{oldpage};
|
my $old=$params{oldpage};
|
||||||
|
|
|
@ -35,7 +35,7 @@ sub import { #{{{
|
||||||
hook(type => "filter", id => "po", call => \&filter);
|
hook(type => "filter", id => "po", call => \&filter);
|
||||||
hook(type => "htmlize", id => "po", call => \&htmlize);
|
hook(type => "htmlize", id => "po", call => \&htmlize);
|
||||||
hook(type => "pagetemplate", id => "po", call => \&pagetemplate, last => 1);
|
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 => "delete", id => "po", call => \&mydelete);
|
||||||
hook(type => "change", id => "po", call => \&change);
|
hook(type => "change", id => "po", call => \&change);
|
||||||
hook(type => "editcontent", id => "po", call => \&editcontent);
|
hook(type => "editcontent", id => "po", call => \&editcontent);
|
||||||
|
@ -330,22 +330,12 @@ sub pagetemplate (@) { #{{{
|
||||||
# Save information about master page rename, so that:
|
# Save information about master page rename, so that:
|
||||||
# - our delete hook can ignore the translations not renamed already
|
# - our delete hook can ignore the translations not renamed already
|
||||||
# - our change hook can rename the translations accordingly.
|
# - 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(@) { #{{{
|
sub renamepage(@) { #{{{
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
my $oldpage=$params{oldpage};
|
my $oldpage=$params{oldpage};
|
||||||
my $newpage=$params{newpage};
|
my $newpage=$params{newpage};
|
||||||
|
|
||||||
setrenamed($oldpage, $newpage) if istranslatable($oldpage);
|
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 ($) { #{{{
|
sub deletetranslations ($) { #{{{
|
||||||
my $deletedmasterfile=shift;
|
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";
|
||||||
} #}}}
|
} #}}}
|
||||||
|
|
|
@ -195,7 +195,7 @@ sub postrename ($;$$$) {
|
||||||
# Update edit form content to fix any links present
|
# Update edit form content to fix any links present
|
||||||
# on it.
|
# on it.
|
||||||
$postrename->param("editcontent",
|
$postrename->param("editcontent",
|
||||||
renamepage_hook($dest, $src, $dest,
|
renamelink_hook($dest, $src, $dest,
|
||||||
$postrename->param("editcontent")));
|
$postrename->param("editcontent")));
|
||||||
|
|
||||||
# Get a new edit token; old was likely invalidated.
|
# Get a new edit token; old was likely invalidated.
|
||||||
|
@ -338,10 +338,16 @@ sub sessioncgi ($$) {
|
||||||
sprintf(gettext("rename %s to %s"), $srcfile, $destfile),
|
sprintf(gettext("rename %s to %s"), $srcfile, $destfile),
|
||||||
$session->param("name"), $ENV{REMOTE_ADDR}) if $config{rcs};
|
$session->param("name"), $ENV{REMOTE_ADDR}) if $config{rcs};
|
||||||
|
|
||||||
# Then link fixups.
|
|
||||||
foreach my $rename (@torename) {
|
foreach my $rename (@torename) {
|
||||||
next if $rename->{src} eq $rename->{dest};
|
next if $rename->{src} eq $rename->{dest};
|
||||||
next if $rename->{error};
|
next if $rename->{error};
|
||||||
|
IkiWiki::run_hooks(rename => sub {
|
||||||
|
shift->(
|
||||||
|
oldpage => $src,
|
||||||
|
newpage => $dest,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
# Then link fixups.
|
||||||
foreach my $p (fixlinks($rename, $session)) {
|
foreach my $p (fixlinks($rename, $session)) {
|
||||||
# map old page names to new
|
# map old page names to new
|
||||||
foreach my $r (@torename) {
|
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->(
|
$content=shift->(
|
||||||
page => $page,
|
page => $page,
|
||||||
oldpage => $src,
|
oldpage => $src,
|
||||||
|
@ -480,7 +486,7 @@ sub fixlinks ($$$) {
|
||||||
if ($needfix) {
|
if ($needfix) {
|
||||||
my $file=$pagesources{$page};
|
my $file=$pagesources{$page};
|
||||||
my $oldcontent=readfile($config{srcdir}."/".$file);
|
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) {
|
if ($oldcontent ne $content) {
|
||||||
my $token=IkiWiki::rcs_prepedit($file);
|
my $token=IkiWiki::rcs_prepedit($file);
|
||||||
eval { writefile($file, $config{srcdir}, $content) };
|
eval { writefile($file, $config{srcdir}, $content) };
|
||||||
|
|
|
@ -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
|
the state is saved. The function can save other state, modify values before
|
||||||
they're saved, etc.
|
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`,
|
something, once per page linking to the renamed page's old location.
|
||||||
`newpage`, and `content`, and should try to modify the content to reflect
|
The hook is passed named parameters: `page`, `oldpage`, `newpage`, and
|
||||||
the name change. For example, by converting links to point to the new page.
|
`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
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ BEGIN { use_ok("IkiWiki::Plugin::link"); }
|
||||||
$config{srcdir}=$config{destdir}="/dev/null";
|
$config{srcdir}=$config{destdir}="/dev/null";
|
||||||
IkiWiki::checkconfig();
|
IkiWiki::checkconfig();
|
||||||
|
|
||||||
# tests of the link plugin's renamepage function
|
# tests of the link plugin's renamelink function
|
||||||
sub try {
|
sub try {
|
||||||
my ($page, $oldpage, $newpage, $content)=@_;
|
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,
|
page => $page,
|
||||||
oldpage => $oldpage,
|
oldpage => $oldpage,
|
||||||
newpage => $newpage,
|
newpage => $newpage,
|
||||||
|
|
Loading…
Reference in New Issue