]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/rename.pm
edit page fixup in postrename
[ikiwiki.git] / IkiWiki / Plugin / rename.pm
index c0ccb25ce8d4ac69b4159ff9500854560b0b0857..e19a11cc434657f88edc34ac3bb5174485c4fb7f 100644 (file)
@@ -47,8 +47,9 @@ sub check_canrename ($$$$$$$) { #{{{
                        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")));
                }
 
@@ -66,7 +67,9 @@ sub check_canrename ($$$$$$$) { #{{{
                # 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);
                }
        }
 } #}}}
@@ -138,22 +141,27 @@ sub rename_start ($$$$) {
        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 (@) { #{{{
@@ -210,15 +218,16 @@ sub sessioncgi ($$) { #{{{
                        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(gettext("rename $srcfile to $destfile"),
+                                       $session->param("name"), $ENV{REMOTE_ADDR});
                                IkiWiki::enable_commit_hook();
                                IkiWiki::rcs_update();
                        }
@@ -230,12 +239,7 @@ sub sessioncgi ($$) { #{{{
                        IkiWiki::refresh();
                        IkiWiki::saveindex();
 
-                       if ($q->param("attachment")) {
-                               postrename($session);
-                       }
-                       else {
-                               postrename($session, $dest);
-                       }
+                       postrename($session, $dest, $q->param("attachment"));
                }
                else {
                        IkiWiki::showform($form, $buttons, $session, $q);