]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/move_page.mdwn
3c96fde3e6db86c65b2d8897f47367d30971cd97
[ikiwiki.git] / doc / patchqueue / move_page.mdwn
1 This is my second cut at a feature like that requested in [[todo/Moving_Pages]].
2 It can also be found [here](http://ikidev.betacantrips.com/patches/move.patch).
3
4 A few shortcomings exist: 
5
6 * No precautions whatsoever are made to protect against race conditions or failures
7   in the rcs\_move function. I didn't even do the `cgi_editpage` thing where I hold
8   the lock and render afterwards (mostly because the copy I was editing was not
9   up-to-date enough to have that code). Although FAILED_SAVE is in movepage.tmpl,
10   no code activates it yet.
11 * Some code is duplicated between cgi\_movepage and cgi\_editpage, as well
12   as rcs\_commit and rcs\_move.
13 * The user interface is pretty lame. I couldn't figure out a good way to let
14   the user specify which directory to move things to without implementing a
15   FileChooser thing.
16 * No redirect pages like those mentioned on [[todo/Moving_Pages]] exist yet, 
17   so none are created.
18 * I added a Move link to page.tmpl but it may belong better someplace else --
19   maybe editpage.tmpl? Not sure.
20 * from is redundant with page so far -- but since the Move links could someday
21   come from someplace other than the page itself I kept it around.
22 * If I move foo.mdwn to bar.mdwn, foo/* should move too, probably.
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 >> I wrote a seperate patch to address this -- it's in [[disappearing_pages]]. --Ethan
54
55     diff -urNX ignorepats ikiwiki/IkiWiki/CGI.pm ikidev/IkiWiki/CGI.pm
56     --- ikiwiki/IkiWiki/CGI.pm  2007-02-14 18:17:12.000000000 -0800
57     +++ ikidev/IkiWiki/CGI.pm   2007-02-22 18:54:23.194982000 -0800
58     @@ -561,6 +561,106 @@
59         }
60      } #}}}
61
62     +sub cgi_movepage($$) {
63     +   my $q = shift;
64     +   my $session = shift;
65     +   eval q{use CGI::FormBuilder};
66     +   error($@) if $@;
67     +   my @fields=qw(do from rcsinfo page newdir newname comments);
68     +   my @buttons=("Rename Page", "Cancel");
69     +
70     +   my $form = CGI::FormBuilder->new(
71     +           fields => \@fields,
72     +                header => 1,
73     +                charset => "utf-8",
74     +                method => 'POST',
75     +           action => $config{cgiurl},
76     +                template => (-e "$config{templatedir}/movepage.tmpl" ?
77     +                        {template_params("movepage.tmpl")} : ""),
78     +   );
79     +   run_hooks(formbuilder_setup => sub {
80     +           shift->(form => $form, cgi => $q, session => $session);
81     +   });
82     +
83     +   decode_form_utf8($form);
84     +
85     +   # This untaint is safe because if the page doesn't exist, bail.
86     +   my $page = $form->field('page');
87     +   $page = possibly_foolish_untaint($page);
88     +   if (! exists $pagesources{$page}) {
89     +           error("page does not exist");
90     +   }
91     +   my $file=$pagesources{$page};
92     +   my $type=pagetype($file);
93     +
94     +   my $from;
95     +   if (defined $form->field('from')) {
96     +           ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
97     +   }
98     +
99     +   $form->field(name => "do", type => 'hidden');
100     +   $form->field(name => "from", type => 'hidden');
101     +   $form->field(name => "rcsinfo", type => 'hidden');
102     +   $form->field(name => "newdir", type => 'text', size => 80);
103     +   $form->field(name => "page", value => $page, force => 1);
104     +   $form->field(name => "newname", type => "text", size => 80);
105     +   $form->field(name => "comments", type => "text", size => 80);
106     +   $form->tmpl_param("can_commit", $config{rcs});
107     +   $form->tmpl_param("indexlink", indexlink());
108     +   $form->tmpl_param("baseurl", baseurl());
109     +
110     +   if (! $form->submitted) {
111     +           $form->field(name => "rcsinfo", value => rcs_prepedit($file),
112     +                        force => 1);
113     +   }
114     +
115     +   if ($form->submitted eq "Cancel") {
116     +           redirect($q, "$config{url}/".htmlpage($page));
117     +           return;
118     +   }
119     +
120     +   if (! $form->submitted || ! $form->validate) {
121     +           check_canedit($page, $q, $session);
122     +           $form->tmpl_param("page_select", 0);
123     +           $form->field(name => "page", type => 'hidden');
124     +           $form->field(name => "type", type => 'hidden');
125     +           $form->title(sprintf(gettext("moving %s"), pagetitle($page)));
126     +           my $pname = basename($page);
127     +           my $dname = dirname($page);
128     +           if (! defined $form->field('newname') ||
129     +               ! length $form->field('newname')) {
130     +                   $form->field(name => "newname",
131     +                                value => pagetitle($pname, 1), force => 1);
132     +           }
133     +           if (! defined $form->field('newdir') ||
134     +               ! length $form->field('newdir')) {
135     +                   $form->field(name => "newdir",
136     +                                value => pagetitle($dname, 1), force => 1);
137     +           }
138     +           print $form->render(submit => \@buttons);
139     +   }
140     +   else{
141     +           # This untaint is safe because titlepage removes any problematic
142     +           # characters.
143     +           my ($newname)=$form->field('newname');
144     +           $newname=titlepage(possibly_foolish_untaint($newname));
145     +           my ($newdir)=$form->field('newdir');
146     +           $newdir=titlepage(possibly_foolish_untaint($newdir));
147     +           if (! defined $newname || ! length $newname || file_pruned($newname, $config{srcdir}) || $newname=~/^\//) {
148     +                   error("bad page name");
149     +           }
150     +           check_canedit($page, $q, $session);
151     +
152     +           my $newpage = ($newdir?"$newdir/":"") . $newname;
153     +           my $newfile = $newpage . ".$type";
154     +           my $message = $form->field('comments');
155     +           unlockwiki();
156     +           rcs_move($file, $newfile, $message, $form->field("rcsinfo"),
157     +                    $session->param("name"), $ENV{REMOTE_ADDR});
158     +           redirect($q, "$config{url}/".htmlpage($newpage));
159     +   }
160     +}
161     +
162      sub cgi_getsession ($) { #{{{
163         my $q=shift;
164
165     @@ -656,6 +756,9 @@
166         elsif (defined $session->param("postsignin")) {
167                 cgi_postsignin($q, $session);
168         }
169     +   elsif ($do eq 'move') {
170     +           cgi_movepage($q, $session);
171     +   }
172         elsif ($do eq 'prefs') {
173                 cgi_prefs($q, $session);
174         }
175     diff -urNX ignorepats ikiwiki/IkiWiki/Rcs/svn.pm ikidev/IkiWiki/Rcs/svn.pm
176     --- ikiwiki/IkiWiki/Rcs/svn.pm      2007-01-27 16:04:48.000000000 -0800
177     +++ ikidev/IkiWiki/Rcs/svn.pm       2007-02-22 01:51:29.923626000 -0800
178     @@ -60,6 +60,34 @@
179         }
180      } #}}}
181
182     +sub rcs_move ($$$$;$$) {
183     +   my $file=shift;
184     +   my $newname=shift;
185     +   my $message=shift;
186     +   my $rcstoken=shift;
187     +   my $user=shift;
188     +   my $ipaddr=shift;
189     +   if (defined $user) {
190     +           $message="web commit by $user".(length $message ? ": $message" : "");
191     +   }
192     +   elsif (defined $ipaddr) {
193     +           $message="web commit from $ipaddr".(length $message ? ": $message" : "");
194     +   }
195     +
196     +   chdir($config{srcdir}); # svn merge wants to be here
197     +
198     +   if (system("svn", "move", "--quiet",
199     +              "$file", "$newname") != 0) {
200     +           return 1;
201     +   }
202     +   if (system("svn", "commit", "--quiet",
203     +              "--encoding", "UTF-8", "-m",
204     +              possibly_foolish_untaint($message)) != 0) {
205     +           return 1;
206     +   }
207     +   return undef # success
208     +}
209     +
210      sub rcs_commit ($$$;$$) { #{{{
211         # Tries to commit the page; returns undef on _success_ and
212         # a version of the page with the rcs's conflict markers on failure.
213     diff -urNX ignorepats ikiwiki/IkiWiki/Render.pm ikidev/IkiWiki/Render.pm
214     --- ikiwiki/IkiWiki/Render.pm       2007-02-14 17:00:05.000000000 -0800
215     +++ ikidev/IkiWiki/Render.pm        2007-02-22 18:30:00.451755000 -0800
216     @@ -80,6 +80,7 @@
217
218         if (length $config{cgiurl}) {
219                 $template->param(editurl => cgiurl(do => "edit", page => $page));
220     +           $template->param(moveurl => cgiurl(do => "move", page => $page));
221                 $template->param(prefsurl => cgiurl(do => "prefs"));
222                 if ($config{rcs}) {
223                         $template->param(recentchangesurl => cgiurl(do => "recentchanges"));
224     diff -urNX ignorepats ikiwiki/templates/movepage.tmpl ikidev/templates/movepage.tmpl
225     --- ikiwiki/templates/movepage.tmpl 1969-12-31 16:00:00.000000000 -0800
226     +++ ikidev/templates/movepage.tmpl  2007-02-22 18:40:39.751763000 -0800
227     @@ -0,0 +1,44 @@
228     +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
229     + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
230     +<html>
231     +<head>
232     +<base href="<TMPL_VAR BASEURL>" />
233     +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
234     +<title><TMPL_VAR FORM-TITLE></title>
235     +<link rel="stylesheet" href="<TMPL_VAR BASEURL>style.css" type="text/css" />
236     +<link rel="stylesheet" href="<TMPL_VAR BASEURL>local.css" type="text/css" />
237     +<TMPL_IF NAME="FAVICON">
238     +<link rel="icon" href="<TMPL_VAR BASEURL><TMPL_VAR FAVICON>" type="image/x-icon" />
239     +</TMPL_IF>
240     +</head>
241     +<body>
242     +<TMPL_IF NAME="FAILED_SAVE">
243     +<p>
244     +<b>Failed to save your changes.</b>
245     +</p>
246     +<p>
247     +Your changes were not able to be saved to disk. The system gave the error:
248     +<blockquote>
249     +<TMPL_VAR ERROR_MESSAGE>
250     +</blockquote>
251     +Your changes are preserved below, and you can try again to save them.
252     +</p>
253     +</TMPL_IF>
254     +<TMPL_VAR FORM-START>
255     +<div class="header">
256     +<span><TMPL_VAR INDEXLINK>/ <TMPL_VAR FORM-TITLE></span>
257     +</div>
258     +<TMPL_VAR FIELD-DO>
259     +<TMPL_VAR FIELD-FROM>
260     +<TMPL_VAR FIELD-RCSINFO>
261     +<TMPL_VAR FIELD-PAGE>
262     +New location: <TMPL_VAR FIELD-NEWDIR>/ <TMPL_VAR FIELD-NEWNAME>
263     +<br />
264     +<TMPL_IF NAME="CAN_COMMIT">
265     +Optional comment about this change:<br />
266     +<TMPL_VAR FIELD-COMMENTS><br />
267     +</TMPL_IF>
268     +<input id="_submit" name="_submit" type="submit" value="Rename Page" /><input id="_submit_2" name="_submit" type="submit" value="Cancel" />
269     +<TMPL_VAR FORM-END>
270     +</body>
271     +</html>
272     diff -urNX ignorepats ikiwiki/templates/page.tmpl ikidev/templates/page.tmpl
273     --- ikiwiki/templates/page.tmpl     2006-12-28 12:27:01.000000000 -0800
274     +++ ikidev/templates/page.tmpl      2007-02-22 01:52:33.078464000 -0800
275     @@ -32,6 +32,9 @@
276      <TMPL_IF NAME="EDITURL">
277      <li><a href="<TMPL_VAR EDITURL>">Edit</a></li>
278      </TMPL_IF>
279     +<TMPL_IF NAME="MOVEURL">
280     +<li><a href="<TMPL_VAR MOVEURL>">Move</a></li>
281     +</TMPL_IF>
282      <TMPL_IF NAME="RECENTCHANGESURL">
283      <li><a href="<TMPL_VAR RECENTCHANGESURL>">RecentChanges</a></li>
284      </TMPL_IF>