1 I thought I'd draw attention to a desire of mine for **ikiwiki**. I'm no power-user, and mostly I do fairly simple stuff with my [wiki](http://kitenet.net/~kyle/family/wiki).
3 However, I would like the ability (now) to **rename/move/delete** pages. As part of having a genealogy wiki, I've put name and dates of birth/death as part of the title of each article (so to avoid cases where people have the same name, but are children/cousins/etc of others with that name). However, some of this information changes. For instance, I didn't know a date of death and now I do, or I had it wrong originally, or it turns out someone is still alive I didn't know about. All of these cases leave me with bad article titles.
5 So, I can go ahead and move the file to a new page with the correct info, orphan that page, provide a link for the new page if desired, and otherwise ignore that page. But then, it clutters up the wiki and serves no useful purpose.
7 Anyway to consider implementing **rename/move/delete** ? I certainly lack the skills to appreciate what this would entail, but feel free to comment if it appears impossible, and then I'll go back to the aforementioned workaround. I would prefer simple rename, however.
9 Thanks again to [Joey](http://kitenet.net/~joey) for putting ikiwiki together. I love the program.
11 *[Kyle](http://kitenet.net/~kyle/)=*
15 The MediaWiki moving/renaming mechanism is pretty nice. It's easy to get a list of pages that point to the current page. When renaming a page it sticks a forwarding page in the original place. The larger the size of the wiki the more important organization tools become.
19 * a new type of file to represent a forwarding page
20 * a rename tool that can
21 * move the existing page to the new name
22 * optionally drop a forwarding page
23 * optionally rewrite incoming links to the new location
27 > This could be implemented through the use of an HTTP redirect to the
28 > new page, but this has the downside that people may not know they're being
31 > This could also be implemented using a combination of raw inline and meta
32 > to change the title (add a "redirected from etc." page. This could be done
33 > with a plugin. A redirect page would be [[redirect page="newpage"]].
34 > But then if you click "edit" on this redirect page, you won't be able
35 > to edit the new page, only the call to redirect.
42 This is my second cut at a feature like that requested here.
43 It can also be found [here](http://ikidev.betacantrips.com/patches/move.patch).
45 A few shortcomings exist:
47 * No precautions whatsoever are made to protect against race conditions or failures
48 in the rcs\_move function. I didn't even do the `cgi_editpage` thing where I hold
49 the lock and render afterwards (mostly because the copy I was editing was not
50 up-to-date enough to have that code). Although FAILED_SAVE is in movepage.tmpl,
51 no code activates it yet.
52 * Some code is duplicated between cgi\_movepage and cgi\_editpage, as well
53 as rcs\_commit and rcs\_move.
54 * The user interface is pretty lame. I couldn't figure out a good way to let
55 the user specify which directory to move things to without implementing a
57 * No redirect pages like those mentioned on [[todo/Moving_Pages]] exist yet,
59 * I added a Move link to page.tmpl but it may belong better someplace else --
60 maybe editpage.tmpl? Not sure.
61 * from is redundant with page so far -- but since the Move links could someday
62 come from someplace other than the page itself I kept it around.
63 * If I move foo.mdwn to bar.mdwn, foo/* should move too, probably.
65 > Looks like a good start, although I agree about many of the points above,
66 > and also feel that something needs to be done about rcses that don't
67 > implement a move operation -- falling back to an add and delete.
70 Hmm. Shouldn't that be done on a by-RCS basis, though? (i.e. implemented
71 by backends in the `rcs_move` function)
73 > Probably, yes, but maybe there's a way to avoid duplicating code for that
76 Also, how should ikiwiki react if a page is edited (say, by another user)
77 before it is moved? Bail, or shrug and proceed?
79 > The important thing is to keep in mind that the page could be edited,
80 > moved, deleted, etc in between the user starting the move and the move
81 > happening. So, the code really needs to deal with all of these cases in
82 > some way. It seems fine to me to go ahead with the move even if the page
83 > was edited. If the page was deleted or moved, it seems reasonable to exit
86 diff -urNX ignorepats ikiwiki/IkiWiki/CGI.pm ikidev/IkiWiki/CGI.pm
87 --- ikiwiki/IkiWiki/CGI.pm 2007-02-14 18:17:12.000000000 -0800
88 +++ ikidev/IkiWiki/CGI.pm 2007-02-22 18:54:23.194982000 -0800
93 +sub cgi_movepage($$) {
95 + my $session = shift;
96 + eval q{use CGI::FormBuilder};
98 + my @fields=qw(do from rcsinfo page newdir newname comments);
99 + my @buttons=("Rename Page", "Cancel");
101 + my $form = CGI::FormBuilder->new(
102 + fields => \@fields,
104 + charset => "utf-8",
106 + action => $config{cgiurl},
107 + template => (-e "$config{templatedir}/movepage.tmpl" ?
108 + {template_params("movepage.tmpl")} : ""),
110 + run_hooks(formbuilder_setup => sub {
111 + shift->(form => $form, cgi => $q, session => $session);
114 + decode_form_utf8($form);
116 + # This untaint is safe because if the page doesn't exist, bail.
117 + my $page = $form->field('page');
118 + $page = possibly_foolish_untaint($page);
119 + if (! exists $pagesources{$page}) {
120 + error("page does not exist");
122 + my $file=$pagesources{$page};
123 + my $type=pagetype($file);
126 + if (defined $form->field('from')) {
127 + ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
130 + $form->field(name => "do", type => 'hidden');
131 + $form->field(name => "from", type => 'hidden');
132 + $form->field(name => "rcsinfo", type => 'hidden');
133 + $form->field(name => "newdir", type => 'text', size => 80);
134 + $form->field(name => "page", value => $page, force => 1);
135 + $form->field(name => "newname", type => "text", size => 80);
136 + $form->field(name => "comments", type => "text", size => 80);
137 + $form->tmpl_param("can_commit", $config{rcs});
138 + $form->tmpl_param("indexlink", indexlink());
139 + $form->tmpl_param("baseurl", baseurl());
141 + if (! $form->submitted) {
142 + $form->field(name => "rcsinfo", value => rcs_prepedit($file),
146 + if ($form->submitted eq "Cancel") {
147 + redirect($q, "$config{url}/".htmlpage($page));
151 + if (! $form->submitted || ! $form->validate) {
152 + check_canedit($page, $q, $session);
153 + $form->tmpl_param("page_select", 0);
154 + $form->field(name => "page", type => 'hidden');
155 + $form->field(name => "type", type => 'hidden');
156 + $form->title(sprintf(gettext("moving %s"), pagetitle($page)));
157 + my $pname = basename($page);
158 + my $dname = dirname($page);
159 + if (! defined $form->field('newname') ||
160 + ! length $form->field('newname')) {
161 + $form->field(name => "newname",
162 + value => pagetitle($pname, 1), force => 1);
164 + if (! defined $form->field('newdir') ||
165 + ! length $form->field('newdir')) {
166 + $form->field(name => "newdir",
167 + value => pagetitle($dname, 1), force => 1);
169 + print $form->render(submit => \@buttons);
172 + # This untaint is safe because titlepage removes any problematic
174 + my ($newname)=$form->field('newname');
175 + $newname=titlepage(possibly_foolish_untaint($newname));
176 + my ($newdir)=$form->field('newdir');
177 + $newdir=titlepage(possibly_foolish_untaint($newdir));
178 + if (! defined $newname || ! length $newname || file_pruned($newname, $config{srcdir}) || $newname=~/^\//) {
179 + error("bad page name");
181 + check_canedit($page, $q, $session);
183 + my $newpage = ($newdir?"$newdir/":"") . $newname;
184 + my $newfile = $newpage . ".$type";
185 + my $message = $form->field('comments');
187 + rcs_move($file, $newfile, $message, $form->field("rcsinfo"),
188 + $session->param("name"), $ENV{REMOTE_ADDR});
189 + redirect($q, "$config{url}/".htmlpage($newpage));
193 sub cgi_getsession ($) { #{{{
197 elsif (defined $session->param("postsignin")) {
198 cgi_postsignin($q, $session);
200 + elsif ($do eq 'move') {
201 + cgi_movepage($q, $session);
203 elsif ($do eq 'prefs') {
204 cgi_prefs($q, $session);
206 diff -urNX ignorepats ikiwiki/IkiWiki/Rcs/svn.pm ikidev/IkiWiki/Rcs/svn.pm
207 --- ikiwiki/IkiWiki/Rcs/svn.pm 2007-01-27 16:04:48.000000000 -0800
208 +++ ikidev/IkiWiki/Rcs/svn.pm 2007-02-22 01:51:29.923626000 -0800
213 +sub rcs_move ($$$$;$$) {
217 + my $rcstoken=shift;
220 + if (defined $user) {
221 + $message="web commit by $user".(length $message ? ": $message" : "");
223 + elsif (defined $ipaddr) {
224 + $message="web commit from $ipaddr".(length $message ? ": $message" : "");
227 + chdir($config{srcdir}); # svn merge wants to be here
229 + if (system("svn", "move", "--quiet",
230 + "$file", "$newname") != 0) {
233 + if (system("svn", "commit", "--quiet",
234 + "--encoding", "UTF-8", "-m",
235 + possibly_foolish_untaint($message)) != 0) {
238 + return undef # success
241 sub rcs_commit ($$$;$$) { #{{{
242 # Tries to commit the page; returns undef on _success_ and
243 # a version of the page with the rcs's conflict markers on failure.
244 diff -urNX ignorepats ikiwiki/IkiWiki/Render.pm ikidev/IkiWiki/Render.pm
245 --- ikiwiki/IkiWiki/Render.pm 2007-02-14 17:00:05.000000000 -0800
246 +++ ikidev/IkiWiki/Render.pm 2007-02-22 18:30:00.451755000 -0800
249 if (length $config{cgiurl}) {
250 $template->param(editurl => cgiurl(do => "edit", page => $page));
251 + $template->param(moveurl => cgiurl(do => "move", page => $page));
252 $template->param(prefsurl => cgiurl(do => "prefs"));
254 $template->param(recentchangesurl => cgiurl(do => "recentchanges"));
255 diff -urNX ignorepats ikiwiki/templates/movepage.tmpl ikidev/templates/movepage.tmpl
256 --- ikiwiki/templates/movepage.tmpl 1969-12-31 16:00:00.000000000 -0800
257 +++ ikidev/templates/movepage.tmpl 2007-02-22 18:40:39.751763000 -0800
259 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
260 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
263 +<base href="<TMPL_VAR BASEURL>" />
264 +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
265 +<title><TMPL_VAR FORM-TITLE></title>
266 +<link rel="stylesheet" href="<TMPL_VAR BASEURL>style.css" type="text/css" />
267 +<link rel="stylesheet" href="<TMPL_VAR BASEURL>local.css" type="text/css" />
268 +<TMPL_IF NAME="FAVICON">
269 +<link rel="icon" href="<TMPL_VAR BASEURL><TMPL_VAR FAVICON>" type="image/x-icon" />
273 +<TMPL_IF NAME="FAILED_SAVE">
275 +<b>Failed to save your changes.</b>
278 +Your changes were not able to be saved to disk. The system gave the error:
280 +<TMPL_VAR ERROR_MESSAGE>
282 +Your changes are preserved below, and you can try again to save them.
285 +<TMPL_VAR FORM-START>
286 +<div class="header">
287 +<span><TMPL_VAR INDEXLINK>/ <TMPL_VAR FORM-TITLE></span>
290 +<TMPL_VAR FIELD-FROM>
291 +<TMPL_VAR FIELD-RCSINFO>
292 +<TMPL_VAR FIELD-PAGE>
293 +New location: <TMPL_VAR FIELD-NEWDIR>/ <TMPL_VAR FIELD-NEWNAME>
295 +<TMPL_IF NAME="CAN_COMMIT">
296 +Optional comment about this change:<br />
297 +<TMPL_VAR FIELD-COMMENTS><br />
299 +<input id="_submit" name="_submit" type="submit" value="Rename Page" /><input id="_submit_2" name="_submit" type="submit" value="Cancel" />
303 diff -urNX ignorepats ikiwiki/templates/page.tmpl ikidev/templates/page.tmpl
304 --- ikiwiki/templates/page.tmpl 2006-12-28 12:27:01.000000000 -0800
305 +++ ikidev/templates/page.tmpl 2007-02-22 01:52:33.078464000 -0800
307 <TMPL_IF NAME="EDITURL">
308 <li><a href="<TMPL_VAR EDITURL>">Edit</a></li>
310 +<TMPL_IF NAME="MOVEURL">
311 +<li><a href="<TMPL_VAR MOVEURL>">Move</a></li>
313 <TMPL_IF NAME="RECENTCHANGESURL">
314 <li><a href="<TMPL_VAR RECENTCHANGESURL>">RecentChanges</a></li>