web commit by http://ethan.betacantrips.com/: about time
[ikiwiki.git] / doc / patchqueue / disappearing_pages.mdwn
1 If one user (via SVN or otherwise) deletes or moves a page while another user 
2 is editing it via the web, bad things happen. This patch addresses this by
3 failing gracefully, and allowing the user to commit a new file with the same 
4 name if desired.
5
6 The patch is [here](http://ikidev.betacantrips.com//patches/disappear.patch).
7 It requires a strip level of 4 -- sorry about that. --Ethan
8
9     diff -urX /home/glasserc/ignorepats /home/glasserc/ikiclean/IkiWiki/CGI.pm /home/glasserc/ikidev/IkiWiki/CGI.pm
10     --- /home/glasserc/ikiclean/IkiWiki/CGI.pm  2007-02-11 21:40:32.419641000 -0800
11     +++ /home/glasserc/ikidev/IkiWiki/CGI.pm    2007-02-12 15:35:55.178886000 -0800
12     @@ -278,7 +278,7 @@
13         my $q=shift;
14         my $session=shift;
15      
16     -   my @fields=qw(do rcsinfo subpage from page type editcontent comments);
17     +   my @fields=qw(do rcsinfo subpage from page type editcontent comments newfile);
18         my @buttons=("Save Page", "Preview", "Cancel");
19         
20         eval q{use CGI::FormBuilder};
21     @@ -340,10 +340,6 @@
22                 $file=$page.".".$type;
23         }
24      
25     -   my $newfile=0;
26     -   if (! -e "$config{srcdir}/$file") {
27     -           $newfile=1;
28     -   }
29      
30         $form->field(name => "do", type => 'hidden');
31         $form->field(name => "from", type => 'hidden');
32     @@ -354,6 +350,7 @@
33         $form->field(name => "comments", type => "text", size => 80);
34         $form->field(name => "editcontent", type => "textarea", rows => 20,
35                 cols => 80);
36     +   $form->field(name => "newfile", type => 'hidden');
37         $form->tmpl_param("can_commit", $config{rcs});
38         $form->tmpl_param("indexlink", indexlink());
39         $form->tmpl_param("helponformattinglink",
40     @@ -362,8 +359,12 @@
41         if (! $form->submitted) {
42                 $form->field(name => "rcsinfo", value => rcs_prepedit($file),
43                         force => 1);
44     +           $form->field(name => "newfile", 
45     +                        value => ! -e "$config{srcdir}/$file",
46     +                        force => 1);
47         }
48     -   
49     +   my $newfile = $form->field(name => "newfile");
50     +
51         if ($form->submitted eq "Cancel") {
52                 if ($newfile && defined $from) {
53                         redirect($q, "$config{url}/".htmlpage($from));
54     @@ -482,6 +485,16 @@
55         else {
56                 # save page
57                 check_canedit($page, $q, $session);
58     +           if (! -e "$config{srcdir}/$file" && ! $form->field(name => 'newfile')){
59     +                   $form->tmpl_param("page_gone", 1);
60     +                   $form->field(name => "newfile",
61     +                                value => 1, force => 1);
62     +                   $form->tmpl_param("page_select", 0);
63     +                   $form->field(name => "page", type => 'hidden');
64     +                   $form->field(name => "type", type => 'hidden');
65     +                   print $form->render(submit => \@buttons);
66     +                   return;
67     +           }
68                 
69                 my $content=$form->field('editcontent');
70      
71     @@ -512,8 +525,7 @@
72                                         force => 1);
73                                 $form->tmpl_param("page_conflict", 1);
74                                 $form->field("editcontent", value => $conflict, force => 1);
75     -                           $form->field(name => "comments", value => $form->field('comments'), force => 1);
76     -                           $form->field("do", "edit)");
77     +                           $form->field("do", "edit");
78                                 $form->tmpl_param("page_select", 0);
79                                 $form->field(name => "page", type => 'hidden');
80                                 $form->field(name => "type", type => 'hidden');
81     diff -urX /home/glasserc/ignorepats /home/glasserc/ikiclean/templates/editpage.tmpl /home/glasserc/ikidev/templates/editpage.tmpl
82     --- /home/glasserc/ikiclean/templates/editpage.tmpl 2007-02-11 21:40:35.046470000 -0800
83     +++ /home/glasserc/ikidev/templates/editpage.tmpl   2007-02-12 15:33:38.503571000 -0800
84     @@ -21,6 +21,15 @@
85      conflict and commit again to save your changes.
86      </p>
87      </TMPL_IF>
88     +<TMPL_IF NAME="PAGE_GONE">
89     +<p>
90     +<b>The page you were editing has disappeared.</b>
91     +</p>
92     +<p>
93     +Perhaps someone else has deleted it or moved it. If you want to recreate
94     +this page with your text, click "Save Page" again.
95     +</p>
96     +</TMPL_IF>
97      <TMPL_VAR FORM-START>
98      <div class="header">
99      <span><TMPL_VAR INDEXLINK>/ <TMPL_VAR FORM-TITLE></span>
100     @@ -28,6 +37,7 @@
101      <TMPL_VAR FIELD-DO>
102      <TMPL_VAR FIELD-FROM>
103      <TMPL_VAR FIELD-RCSINFO>
104     +<TMPL_VAR FIELD-NEWFILE>
105      <TMPL_IF NAME="PAGE_SELECT">
106      Page location: <TMPL_VAR FIELD-PAGE>
107      Page type: <TMPL_VAR FIELD-TYPE>