]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/Can__39__t_create_root_page.mdwn
web commit by intrigeri: added opinion + patch
[ikiwiki.git] / doc / bugs / Can__39__t_create_root_page.mdwn
1 This is a link to a non-existent page in the root directory: [[/root_page_test]] (\[[/root\_page\_test]])
2
3 When you click on the question mark to create the page, you get *Error: bad page name*.  It's a valid [[wikilink]], shouldn't it create the page? --[[sabr]]
4
5 > Is it a valid wikilink?  Should Iki prevent the page from being created? --[[sabr]], 2 months later
6
7 This type of page name (with leading slash) also gets created by the aggregate plugin: /cgi-bin/ikiwiki.cgi?page=%2FCalculated_Risk&from=news%2FAll_Stories&do=create  I'm now pretty convinced that Iki should handle this without error.  I'll investigate if I can find the time.
8
9 > As documented on [[ikiwiki/subpage/linkingrules]], such an absolute
10 > link works perfectly when the linked page already exists.
11 >
12 > The CGI behaviour is thus not consistent with the general linking
13 > rules, which is annoying for me : I'm using templates to generate
14 > links to pages that may not exist yet, and I would like the "right"
15 > path to be selected by default, instead of the usual
16 > <current>/subdir/subpage, when a user clicks the "?" link to create
17 > the missing page ; that's why I'm using absolute paths.
18 >
19 > Anyway, having the CGI consider invalid an otherwise valid wikilink
20 > seems a bit weird to me, so I had a look to the code, and here is a
21 > patch that should fix this issue ; I proceeded the only way I could
22 > find to prevent side-effects : the only place where I use `$origpage`
23 > is a match, so no function at all is fed with a `$page` with 
24 > leading slash :
25 >
26 > -- intrigeri
27
28
29         diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
30         index 99cead6..23d9616 100644
31         --- a/IkiWiki/CGI.pm
32         +++ b/IkiWiki/CGI.pm
33         @@ -305,9 +305,11 @@ sub cgi_editpage ($$) { #{{{
34                 my $page=$form->field('page');
35                 $page=possibly_foolish_untaint($page);
36                 if (! defined $page || ! length $page ||
37         -           file_pruned($page, $config{srcdir}) || $page=~/^\//) {
38         +           file_pruned($page, $config{srcdir})) {
39                         error("bad page name");
40                 }
41         +       my $origpage=$page;
42         +       $page =~ s#^/##;
43          
44                 my $baseurl=$config{url}."/".htmlpage($page);
45                 
46         @@ -425,6 +427,7 @@ sub cgi_editpage ($$) { #{{{
47                                     $from ne $form->field('from') ||
48                                     file_pruned($from, $config{srcdir}) ||
49                                     $from=~/^\// ||
50         +                           $origpage=~/^\// ||
51                                     $form->submitted eq "Preview") {
52                                         @page_locs=$best_loc=$page;
53                                 }
54
55 [[tag patch]]