error(gettext("no change to the file name was specified"));
}
- # Must be a legal filename.
- if (IkiWiki::file_pruned($destfile, $config{srcdir})) {
+ # Must be a legal filename, and not absolute.
+ if (IkiWiki::file_pruned($destfile, $config{srcdir}) ||
+ $destfile=~/^\//) {
error(sprintf(gettext("illegal name")));
}
# Must be editable.
IkiWiki::check_canedit($dest, $q, $session);
if ($attachment) {
- IkiWiki::Plugin::attachment::check_canattach($session, $dest, $destfile);
+ # Note that $srcfile is used here, not $destfile,
+ # because it wants the current file, to check it.
+ IkiWiki::Plugin::attachment::check_canattach($session, $dest, $srcfile);
}
}
} #}}}
-sub formbuilder_setup (@) { #{{{
- my %params=@_;
- my $form=$params{form};
- my $q=$params{cgi};
-
- if (defined $form->field("do") && $form->field("do") eq "edit") {
- # Rename button for the page, and also for attachments.
- push @{$params{buttons}}, "Rename";
- $form->tmpl_param("field-rename" => '<input name="_submit" type="submit" value="Rename Attachment" />');
- }
-} #}}}
-
sub rename_form ($$$) { #{{{
my $q=shift;
my $session=shift;
exit 0;
}
-sub postrename ($;$) {
+sub postrename ($;$$) {
my $session=shift;
- my $newname=shift;
+ my $dest=shift;
+ my $attachment=shift;
- # Load saved form state and return to edit form.
+ # Load saved form state and return to edit page.
my $postrename=CGI->new($session->param("postrename"));
- if (defined $newname) {
- # They renamed the page they were editing.
- # Tweak the edit form to be editing the new
- # page name, and redirect back to it.
- # (Deep evil here.)
- error("don't know how to redir back!"); ## FIXME
- }
$session->clear("postrename");
IkiWiki::cgi_savesession($session);
- IkiWiki::cgi($postrename, $session);
+
+ if (defined $dest && ! $attachment) {
+ # They renamed the page they were editing. This requires
+ # fixups to the edit form state.
+ # Tweak the edit form to be editing the new page.
+ $postrename->param("page", $dest);
+ # Get a new edit token; old one might not be valid for the
+ # renamed file.
+ $postrename->param("rcsinfo", IkiWiki::rcs_prepedit($pagesources{$dest}));
+ }
+
+ IkiWiki::cgi_editpage($postrename, $session);
}
sub formbuilder (@) { #{{{
}
} #}}}
+my $renamesummary;
+
+sub formbuilder_setup (@) { #{{{
+ my %params=@_;
+ my $form=$params{form};
+ my $q=$params{cgi};
+
+ if (defined $form->field("do") && $form->field("do") eq "edit") {
+ # Rename button for the page, and also for attachments.
+ push @{$params{buttons}}, "Rename";
+ $form->tmpl_param("field-rename" => '<input name="_submit" type="submit" value="Rename Attachment" />');
+
+ if (defined $renamesummary) {
+ $form->tmpl_param(message => $renamesummary);
+ }
+ }
+} #}}}
+
sub sessioncgi ($$) { #{{{
my $q=shift;
check_canrename($src, $srcfile, $dest, $destfile,
$q, $session, $q->param("attachment"));
+ # Ensures that the dest directory exists and is ok.
+ IkiWiki::prep_writefile($destfile, $config{srcdir});
+
# Do rename, and update the wiki.
require IkiWiki::Render;
if ($config{rcs}) {
IkiWiki::disable_commit_hook();
- my $token=IkiWiki::rcs_prepedit($srcfile);
IkiWiki::rcs_rename($srcfile, $destfile);
- # TODO commit destfile too
- IkiWiki::rcs_commit($srcfile, gettext("rename $srcfile to $destfile"),
- $token, $session->param("name"), $ENV{REMOTE_ADDR});
+ IkiWiki::rcs_commit_staged(
+ sprintf(gettext("rename %s to %s"), $src, $dest),
+ $session->param("name"), $ENV{REMOTE_ADDR});
IkiWiki::enable_commit_hook();
IkiWiki::rcs_update();
}
IkiWiki::refresh();
IkiWiki::saveindex();
- if ($q->param("attachment")) {
- postrename($session);
- }
- else {
- postrename($session, $dest);
+ # scan for broken links to $src
+ my @brokenlinks;
+ foreach my $page (keys %links) {
+ foreach my $link (@{$links{$page}}) {
+ my $bestlink=bestlink($page, $link);
+ if ($bestlink eq $src) {
+ push @brokenlinks, $page;
+ }
+ }
}
+
+ # Generate a rename summary, that will be shown at the top
+ # of the edit template.
+ my $template=template("renamesummary.tmpl");
+ $template->param(src => $src);
+ $template->param(dest => $dest);
+ $template->param(linklist => [
+ map {
+ {
+ page => htmllink($dest, $dest, $_,
+ noimageinline => 1)
+ }
+ } @brokenlinks
+ ]);
+ $renamesummary=$template->output;
+
+ postrename($session, $dest, $q->param("attachment"));
}
else {
IkiWiki::showform($form, $buttons, $session, $q);