]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/rename.pm
add a rename summary
[ikiwiki.git] / IkiWiki / Plugin / rename.pm
index 32888877f6523a08a2cfe9a2717474706badaf0b..fdd9dc71c83dba820e4f5249918f3391f189ddd7 100644 (file)
@@ -47,8 +47,9 @@ sub check_canrename ($$$$$$$) { #{{{
                        error(gettext("no change to the file name was specified"));
                }
 
                        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")));
                }
 
                        error(sprintf(gettext("illegal name")));
                }
 
@@ -73,18 +74,6 @@ sub check_canrename ($$$$$$$) { #{{{
        }
 } #}}}
 
        }
 } #}}}
 
-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;
 sub rename_form ($$$) { #{{{ 
        my $q=shift;
        my $session=shift;
@@ -140,24 +129,56 @@ sub rename_start ($$$$) {
        exit 0;
 }
 
        exit 0;
 }
 
-sub postrename ($;$) {
+my $renamesummary;
+sub postrename ($;$$$) {
        my $session=shift;
        my $session=shift;
-       my $newname=shift;
+       my $src=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"));
        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);
        $session->clear("postrename");
        IkiWiki::cgi_savesession($session);
-       IkiWiki::cgi($postrename, $session);
+
+       if (defined $src) {
+               # 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);
+               $renamesummary=$template->output;
+       }
+
+       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_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 formbuilder (@) { #{{{
        my %params=@_;
        my $form=$params{form};
 sub formbuilder (@) { #{{{
        my %params=@_;
        my $form=$params{form};
@@ -213,14 +234,15 @@ sub sessioncgi ($$) { #{{{
                                $q, $session, $q->param("attachment"));
 
                        # Ensures that the dest directory exists and is ok.
                                $q, $session, $q->param("attachment"));
 
                        # Ensures that the dest directory exists and is ok.
-                       IkIWiki::prep_writefile($destfile, $config{srcdir});
+                       IkiWiki::prep_writefile($destfile, $config{srcdir});
 
                        # Do rename, and update the wiki.
                        require IkiWiki::Render;
                        if ($config{rcs}) {
                                IkiWiki::disable_commit_hook();
                                IkiWiki::rcs_rename($srcfile, $destfile);
 
                        # Do rename, and update the wiki.
                        require IkiWiki::Render;
                        if ($config{rcs}) {
                                IkiWiki::disable_commit_hook();
                                IkiWiki::rcs_rename($srcfile, $destfile);
-                               IkiWiki::rcs_commit_staged(gettext("rename $srcfile to $destfile"),
+                               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();
                                        $session->param("name"), $ENV{REMOTE_ADDR});
                                IkiWiki::enable_commit_hook();
                                IkiWiki::rcs_update();
@@ -233,12 +255,7 @@ sub sessioncgi ($$) { #{{{
                        IkiWiki::refresh();
                        IkiWiki::saveindex();
 
                        IkiWiki::refresh();
                        IkiWiki::saveindex();
 
-                       if ($q->param("attachment")) {
-                               postrename($session);
-                       }
-                       else {
-                               postrename($session, $dest);
-                       }
+                       postrename($session, $src, $dest, $q->param("attachment"));
                }
                else {
                        IkiWiki::showform($form, $buttons, $session, $q);
                }
                else {
                        IkiWiki::showform($form, $buttons, $session, $q);