editpage: Avoid storing accidental state changes when previewing pages.
authorJoey Hess <joey@kitenet.net>
Wed, 9 Jun 2010 21:44:40 +0000 (17:44 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 9 Jun 2010 21:44:40 +0000 (17:44 -0400)
This is a slow, safe, stupid approach. Could make deep copies of the data
structures as backups instead of re-loading the index from disk.

IkiWiki/Plugin/editpage.pm
debian/changelog
doc/bugs/comments_preview_unsafe_with_allowdirectives.mdwn [new file with mode: 0644]
doc/bugs/preview_pagestate.mdwn

index af2c5ff4e5e9558ac3ee4d337637ef796235c69f..3d731d399f34e9b857616135574727b24abb1757 100644 (file)
@@ -170,10 +170,8 @@ sub cgi_editpage ($$) {
                $previewing=1;
 
                my $new=not exists $pagesources{$page};
-               if ($new) {
-                       # temporarily record its type
-                       $pagesources{$page}=$page.".".$type;
-               }
+               # temporarily record its type
+               $pagesources{$page}=$page.".".$type if $new;
                my %wasrendered=map { $_ => 1 } @{$renderedfiles{$page}};
 
                my $content=$form->field('editcontent');
@@ -198,18 +196,17 @@ sub cgi_editpage ($$) {
                });
                $form->tmpl_param("page_preview", $preview);
                
-               if ($new) {
-                       delete $pagesources{$page};
-               }
-
                # Previewing may have created files on disk.
                # Keep a list of these to be deleted later.
                my %previews = map { $_ => 1 } @{$wikistate{editpage}{previews}};
                foreach my $f (@{$renderedfiles{$page}}) {
                        $previews{$f}=1 unless $wasrendered{$f};
                }
+
+               # Throw out any other state changes made during previewing,
+               # and save the previews list.
+               loadindex();
                @{$wikistate{editpage}{previews}} = keys %previews;
-               $renderedfiles{$page}=[keys %wasrendered];
                saveindex();
        }
        elsif ($form->submitted eq "Save Page") {
index 5cfb9ce8981b8397d531a69a20ffb0f45bc58690..96188c093b2dd144d53a366716bc770f24ba6ad6 100644 (file)
@@ -8,6 +8,7 @@ ikiwiki (3.20100609) unstable; urgency=low
   * Fix support for globbing in tagged() pagespecs.
   * Fix display of sidebar when previewing page edit. (Thanks, privat)
   * relativedate: Fix problem with localised dates not working.
+  * editpage: Avoid storing accidental state changes when previewing pages.
 
  -- Joey Hess <joeyh@debian.org>  Mon, 31 May 2010 20:44:17 -0400
 
diff --git a/doc/bugs/comments_preview_unsafe_with_allowdirectives.mdwn b/doc/bugs/comments_preview_unsafe_with_allowdirectives.mdwn
new file mode 100644 (file)
index 0000000..7f9fb67
--- /dev/null
@@ -0,0 +1,8 @@
+If `comments_allowdirectives` is set, previewing a comment can run
+directives that create files. (Eg, img.) Unlike editpage, it does not
+keep track of those files and expire them. So the files will linger in
+destdir forever.
+
+Probably when the user then tries to save the comment, ikiwiki will refuse
+to overwrite the unknown file, and will crash.
+--[[Joey]]
index 14973908b0a6009f4d1892b49e6532456cf145b4..7f7ec09765e620cca369e0b833e3ea7ae2703785 100644 (file)
@@ -9,3 +9,5 @@ saves other state changes.
 
 Seems like it needs to isolate all state changes when previewing... ugh.
 --[[Joey]] 
+
+[[done]]