]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/move_page.mdwn
web commit by http://per.bothner.com/: Alternate simple patch to view "A/B/C/index...
[ikiwiki.git] / doc / patchqueue / move_page.mdwn
1 This is my first cut at a feature like that requested in [[todo/Moving_Pages]]. In case it gets mangled you can find it on [my site](http://www.betacantrips.com//attic/move.patch).
2
3 A bunch of obvious shortcomings exist: 
4
5 * I'm not sure all the untaints are safe.
6 * No precautions whatsoever are made to protect against race conditions or failures
7   in the rcs\_move function.
8 * movepage.tmpl doesn't exist yet.
9 * Some code is duplicated between cgi\_movepage and cgi\_editpage, as well
10   as rcs\_commit and rcs\_move.
11 * The user interface is pretty lame -- there's no handy select list full 
12   of possible places to move it or anything.
13 * I don't think I implemented cancelling.
14 * from is redundant with page.
15 * I don't think I called the right hook functions.
16 * No redirect pages like those mentioned on [[todo/Moving_Pages]] exist yet, 
17   so none are created.
18 * It's not possible to get there through the actions listed on the wiki page.
19   Instead you can select "Edit" and then change "edit" to "move" in the 
20   location bar.
21
22 Anyhow, here's the patch, for whatever good it does.
23
24 > Looks like a good start, although I agree about many of the points above,
25 > and also feel that something needs to be done about rcses that don't
26 > implement a move operation -- falling back to an add and delete.
27 > --[[Joey]]
28
29 Hmm. Shouldn't that be done on a by-RCS basis, though? (i.e. implemented
30 by backends in the `rcs_move` function)
31
32 > Probably, yes, but maybe there's a way to avoid duplicating code for that
33 > in several of them.
34
35 Also, how should ikiwiki react if a page is edited (say, by another user)
36 before it is moved? Bail, or shrug and proceed?
37
38 > The important thing is to keep in mind that the page could be edited,
39 > moved, deleted, etc in between the user starting the move and the move
40 > happening. So, the code really needs to deal with all of these cases in
41 > some way. It seems fine to me to go ahead with the move even if the page
42 > was edited. If the page was deleted or moved, it seems reasonable to exit
43 > with an error.
44 >
45 > Another set of issues exists if a separate web user is trying to edit the
46 > page at the same time. We'll have to make sure that something sane
47 > happens there; will ikiwiki re-add the moved page under the old name if
48 > the user saves their edit after the move? Could be confusing.. I think it
49 > probably errors out instead, but I'm not sure. Of course, this is an
50 > issue that occurs if the page is moved using a regular svn commit too, so
51 > it's not really your concern in a way. :-)
52
53 Could you elaborate on [[commit-internals]]? Can I assume that ikiwiki's 
54 working copy W will always reflect a revision of the master copy M? 
55 (That is, nobody changes W and leaves it uncommitted.) I would guess 
56 probably not; a user probably expects that if he starts editing W it 
57 won't get randomly committed by web user actions. But then looking at
58 the svn backend, it looks like if I edit foo.mdwn, don't commit, and then
59 a web user makes different changes, my changes get wiped out. So does
60 W "belong" to ikiwiki? --Ethan
61
62 > The working copy used by ikiwiki belongs to ikiwiki; it should not be
63 > edited directly.
64
65     diff -urx .svn ikiwiki/IkiWiki/CGI.pm ikiwiki-new/IkiWiki/CGI.pm
66     --- ikiwiki/IkiWiki/CGI.pm  2007-01-04 03:52:47.000000000 -0800
67     +++ ikiwiki-new/IkiWiki/CGI.pm      2007-01-11 18:49:37.000000000 -0800
68     @@ -523,6 +523,97 @@
69         }
70      } #}}}
71      
72     +sub cgi_movepage($$) {
73     +   my $q = shift;
74     +   my $session = shift;
75     +   eval q{use CGI::FormBuilder};
76     +   error($@) if $@;
77     +   my @fields=qw(do from rcsinfo subpage page newname message); # subpage ignored so far
78     +   my @buttons=("Rename Page", "Cancel");
79     +
80     +   my $form = CGI::FormBuilder->new(
81     +           fields => \@fields,
82     +                header => 1,
83     +                charset => "utf-8",
84     +                method => 'POST',
85     +           action => $config{cgiurl},
86     +                template => (-e "$config{templatedir}/movepage.tmpl" ?
87     +                        {template_params("movepage.tpml")} : ""),
88     +   );
89     +   run_hooks(formbuilder_setup => sub {
90     +           shift->(form => $form, cgi => $q, session => $session);
91     +   });
92     +
93     +   decode_form_utf8($form);
94     +   
95     +   # This untaint is safe because if the page doesn't exist, bail.
96     +   my $page = $form->field('page');
97     +   $page = possibly_foolish_untaint($page);
98     +   if (! exists $pagesources{$page}) {
99     +           error("page does not exist");
100     +   }
101     +   my $file=$pagesources{$page};
102     +   my $type=pagetype($file);
103     +
104     +   my $from;
105     +   if (defined $form->field('from')) {
106     +           ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
107     +   }
108     +   
109     +   $form->field(name => "do", type => 'hidden');
110     +   $form->field(name => "from", type => 'hidden');
111     +   $form->field(name => "rcsinfo", type => 'hidden');
112     +   $form->field(name => "subpage", type => 'hidden');
113     +   $form->field(name => "page", value => $page, force => 1);
114     +   $form->field(name => "newname", type => "text", size => 80);
115     +   $form->field(name => "message", type => "text", size => 80);
116     +
117     +   if (! $form->submitted) {
118     +           $form->field(name => "rcsinfo", value => rcs_prepedit($file),
119     +                        force => 1);
120     +   }
121     +
122     +   if ($form->submitted eq "Cancel") {
123     +           redirect($q, "$config{url}/".htmlpage($from));
124     +           return;
125     +   }
126     +           
127     +   if (! $form->submitted || $form->submitted eq "Preview" || 
128     +       ! $form->validate) {
129     +           if ($form->field("do") eq "move"){
130     +                   page_locked($page, $session);
131     +                   $form->tmpl_param("page_select", 0);
132     +                   $form->field(name => "page", type => 'hidden');
133     +                   $form->field(name => "type", type => 'hidden');
134     +                   $form->title(sprintf(gettext("moving %s"), pagetitle($page)));
135     +                   if (! defined $form->field('newname') ||
136     +                       ! length $form->field('newname')) {
137     +                           $form->field(name => "newname", 
138     +                                        value => pagetitle($page), force => 1);
139     +                   }
140     +
141     +           }
142     +           print $form->render(submit => \@buttons);
143     +   }
144     +   else{
145     +           # This untaint is safe because titlepage removes any problematic
146     +           # characters.
147     +           my ($newname)=$form->field('newname');
148     +           $newname=titlepage(possibly_foolish_untaint($newname));
149     +           if (! defined $newname || ! length $newname || file_pruned($newname, $config{srcdir}) || $newname=~/^\//) {
150     +                   error("bad page name");
151     +           }
152     +           page_locked($page, $session);
153     +
154     +           my $newfile = $newname . ".$type";
155     +           my $message = $form->field('message');
156     +           unlockwiki();
157     +           rcs_move($file, $newfile, $message, $form->field("rcsinfo"), 
158     +                    $session->param("name"), $ENV{REMOTE_ADDR});
159     +           redirect($q, "$config{url}/".htmlpage($newname));
160     +   }
161     +}
162     +
163      sub cgi_getsession ($) { #{{{
164         my $q=shift;
165      
166     @@ -631,6 +722,9 @@
167         if ($do eq 'create' || $do eq 'edit') {
168                 cgi_editpage($q, $session);
169         }
170     +   elsif ($do eq 'move') {
171     +           cgi_movepage($q, $session);
172     +   }
173         elsif ($do eq 'prefs') {
174                 cgi_prefs($q, $session);
175         }
176     diff -urx .svn ikiwiki/IkiWiki/Rcs/svn.pm ikiwiki-new/IkiWiki/Rcs/svn.pm
177     --- ikiwiki/IkiWiki/Rcs/svn.pm      2006-12-28 17:50:46.000000000 -0800
178     +++ ikiwiki-new/IkiWiki/Rcs/svn.pm  2007-01-11 18:14:30.000000000 -0800
179     @@ -60,6 +60,34 @@
180         }
181      } #}}}
182      
183     +sub rcs_move ($$$$;$$) {
184     +   my $file=shift;
185     +   my $newname=shift;
186     +   my $message=shift;
187     +   my $rcstoken=shift;
188     +   my $user=shift;
189     +   my $ipaddr=shift;
190     +   if (defined $user) {
191     +           $message="web commit by $user".(length $message ? ": $message" : "");
192     +   }
193     +   elsif (defined $ipaddr) {
194     +           $message="web commit from $ipaddr".(length $message ? ": $message" : "");
195     +   }
196     +
197     +   chdir($config{srcdir}); # svn merge wants to be here
198     +
199     +   if (system("svn", "move", "--quiet", 
200     +              "$file", "$newname") != 0) {
201     +           return 1;
202     +   }
203     +   if (system("svn", "commit", "--quiet", 
204     +              "--encoding", "UTF-8", "-m",
205     +              possibly_foolish_untaint($message)) != 0) {
206     +           return 1;
207     +   }
208     +   return undef # success
209     +}
210     +
211      sub rcs_commit ($$$;$$) { #{{{
212         # Tries to commit the page; returns undef on _success_ and
213         # a version of the page with the rcs's conflict markers on failure.