]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/index.html_allowed.mdwn
PERL5LIB won't work when using the taint flag, and use lib "." is removed
[ikiwiki.git] / doc / patchqueue / index.html_allowed.mdwn
1 Instead of having files foo.html "in front of" foo/, I prefer to have 
2 foo/index.html. This patch allows that. Specifically, foo/index.type 
3 is translated to $links{'foo/'}, and bestlink looks for either "foo" or 
4 "foo/" when linking to pages. There are other miscellaneous changes that 
5 go with that:
6
7 1. change the `cgi_editpage` `@page_locs` code so that creating foo from 
8    a/b/c prefers a/b/foo and then a/b/c/foo, but if creating foo from a/b/c/,
9    then prefer a/b/c/foo. I'm not really sure why the original was doing what
10    it did (why trim terminal `/` if no pages end in `/`?), so this part might
11    break something.
12 2. tweak things so that index.rss and index.atom are generated if inlining 
13    from 'foo/'
14 2. backlinks from "foo/bar" to "foo/" trim common prefixes as long as there 
15    would be something left when the trimming is done (i.e. don't trim "foo/")
16 3. parentlinks for "foo/" are the same as for "foo", except one directory 
17    higher
18 4. rewrite parentlinks so that bestlink is called at each level
19 5. basename("foo/") => basename("foo")
20 6. links to "foo/" are translated to "foo/index.html" rather than "foo/.html".
21   (Links to "foo/" might be preferred, but that causes an infinite loop in 
22   writefile, because apparently dirname("foo/") == "foo/" on my system for 
23   reasons that aren't clear to me.)
24 7. pagetitle("foo/") => pagetitle("foo")
25 8. clip the final slash when matching a relative pagespec, even if there are
26    no characters after it (otherwise inlining "./a" from "foo/" gets 
27    translated to "foo//a")
28
29 In case whitespace gets garbled, I'm also leaving a copy of the patch on 
30 [my site](http://ikidev.betacantrips.com/patches/index.patch). It should apply 
31 cleanly to a freshly unpacked ikiwiki-1.42. You can also see it in action 
32 [here](http://ikidev.betacantrips.com/one/). --Ethan
33
34     diff -urX ignorepats ikiclean/IkiWiki/CGI.pm ikidev/IkiWiki/CGI.pm
35     --- ikiclean/IkiWiki/CGI.pm 2007-02-11 21:40:32.419641000 -0800
36     +++ ikidev/IkiWiki/CGI.pm   2007-02-11 21:54:36.252357000 -0800
37     @@ -408,8 +408,8 @@
38                                 @page_locs=$best_loc=$page;
39                         }
40                         else {
41     -                           my $dir=$from."/";
42     -                           $dir=~s![^/]+/+$!!;
43     +                           my $dir=$from;
44     +                           $dir=~s![^/]+$!!;
45                                 
46                                 if ((defined $form->field('subpage') && length $form->field('subpage')) ||
47                                     $page eq gettext('discussion')) {
48     @@ -420,7 +420,9 @@
49                                 }
50                                 
51                                 push @page_locs, $dir.$page;
52     -                           push @page_locs, "$from/$page";
53     +                           if ($dir ne $from){ # i.e. $from not a directory
54     +                                   push @page_locs, "$from/$page";
55     +                           }
56                                 while (length $dir) {
57                                         $dir=~s![^/]+/+$!!;
58                                         push @page_locs, $dir.$page;
59     diff -urX ignorepats ikiclean/IkiWiki/Plugin/inline.pm ikidev/IkiWiki/Plugin/inline.pm
60     --- ikiclean/IkiWiki/Plugin/inline.pm       2007-02-11 21:40:31.996007000 -0800
61     +++ ikidev/IkiWiki/Plugin/inline.pm 2007-02-11 21:54:36.008358000 -0800
62     @@ -110,8 +110,8 @@
63      
64         add_depends($params{page}, $params{pages});
65      
66     -   my $rssurl=rsspage(basename($params{page}));
67     -   my $atomurl=atompage(basename($params{page}));
68     +   my $rssurl=basename(rsspage($params{page}));
69     +   my $atomurl=basename(atompage($params{page}));
70         my $ret="";
71      
72         if (exists $params{rootpage} && $config{cgiurl}) {
73     @@ -285,14 +285,18 @@
74      
75      sub rsspage ($) { #{{{
76         my $page=shift;
77     +   $page = htmlpage($page);
78     +   $page =~s/\.html$/.rss/;
79      
80     -   return $page.".rss";
81     +   return $page;
82      } #}}}
83      
84      sub atompage ($) { #{{{
85         my $page=shift;
86     +   $page = htmlpage($page);
87     +   $page =~s/\.html$/.atom/;
88      
89     -   return $page.".atom";
90     +   return $page;
91      } #}}}
92      
93      sub genfeed ($$$$@) { #{{{
94     diff -urX ignorepats ikiclean/IkiWiki/Render.pm ikidev/IkiWiki/Render.pm
95     --- ikiclean/IkiWiki/Render.pm      2007-02-11 21:40:32.413641000 -0800
96     +++ ikidev/IkiWiki/Render.pm        2007-02-11 21:54:36.246356000 -0800
97     @@ -40,6 +40,7 @@
98                 my $dir;
99                 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
100                         defined $dir &&
101     +                   $p_trimmed=~m/^\Q$dir\E(?:.)/ &&
102                         $p_trimmed=~s/^\Q$dir\E// &&
103                         $page_trimmed=~s/^\Q$dir\E//;
104                                
105     @@ -57,10 +58,18 @@
106         my $path="";
107         my $skip=1;
108         return if $page eq 'index'; # toplevel
109     -   foreach my $dir (reverse split("/", $page)) {
110     +   if ($page =~ m{/$}){
111     +           $page =~ s{/$}{};
112     +           $path="../";
113     +   }
114     +
115     +   while ($page =~ m!([^/]+)$!) {
116     +           my $last = $1;
117     +           $page =~ s!/?[^/]+$!!;
118                 if (! $skip) {
119                         $path.="../";
120     -                   unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
121     +                   my $target = abs2rel(htmlpage(bestlink($page, $last)), $page);
122     +                   unshift @ret, { url => $path.$target, page => pagetitle($last) };
123                 }
124                 else {
125                         $skip=0;
126     diff -urX ignorepats ikiclean/IkiWiki.pm ikidev/IkiWiki.pm
127     --- ikiclean/IkiWiki.pm     2007-02-11 21:40:35.118406000 -0800
128     +++ ikidev/IkiWiki.pm       2007-02-11 22:22:49.146071000 -0800
129     @@ -188,6 +188,7 @@
130      sub basename ($) { #{{{
131         my $file=shift;
132      
133     +   $file=~s!/$!!;
134         $file=~s!.*/+!!;
135         return $file;
136      } #}}}
137     @@ -214,12 +215,14 @@
138         my $type=pagetype($file);
139         my $page=$file;
140         $page=~s/\Q.$type\E*$// if defined $type;
141     +   $page=~s#index$## if $page=~m{/index$};
142         return $page;
143      } #}}}
144      
145      sub htmlpage ($) { #{{{
146         my $page=shift;
147      
148     +   return $page."index.html" if $page=~m{/$};
149         return $page.".html";
150      } #}}}
151      
152     @@ -307,6 +310,7 @@
153         my $page=shift;
154         my $link=shift;
155         
156     +   $page =~ s!/$!!;
157         my $cwd=$page;
158         if ($link=~s/^\/+//) {
159                 # absolute links
160     @@ -321,6 +325,9 @@
161                 if (exists $links{$l}) {
162                         return $l;
163                 }
164     +           if (exists $links{$l.'/'}){
165     +                   return $l.'/';
166     +           }
167                 elsif (exists $pagecase{lc $l}) {
168                         return $pagecase{lc $l};
169                 }
170     @@ -351,6 +358,7 @@
171                 $page=~s/__(\d+)__/&#$1;/g;
172         }
173         $page=~y/_/ /;
174     +   $page=~s!/$!!;
175      
176         return $page;
177      } #}}}
178     @@ -879,7 +887,7 @@
179      
180         # relative matching
181         if ($glob =~ m!^\./!) {
182     -           $from=~s!/?[^/]+$!!;
183     +           $from=~s!/?[^/]*$!!;
184                 $glob=~s!^\./!!;
185                 $glob="$from/$glob" if length $from;
186         }
187
188 I independently implemented a similar, but smaller patch.
189 (It's smaller because I only care about rendering; not CGI, for example.)
190 The key to this patch is that "A/B/C" is treated as equivalent
191 to "A/B/C/index".
192 Here it is:  --Per Bothner
193
194     --- IkiWiki/Render.pm~  2007-01-11 15:01:51.000000000 -0800
195     +++ IkiWiki/Render.pm   2007-02-02 22:24:12.000000000 -0800
196     @@ -60,9 +60,9 @@
197             foreach my $dir (reverse split("/", $page)) {
198                     if (! $skip) {
199                             $path.="../";
200     -                       unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
201     +                       unshift @ret, { url => abs2rel(htmlpage(bestlink($page, $dir)), dirname($page)), page => pagetitle($dir) };
202                     }
203     -               else {
204     +               elsif ($dir ne "index") {
205                             $skip=0;
206                     }
207             }
208
209     --- IkiWiki.pm~ 2007-01-12 12:47:09.000000000 -0800
210     +++ IkiWiki.pm  2007-02-02 18:02:16.000000000 -0800
211     @@ -315,6 +315,12 @@
212                     elsif (exists $pagecase{lc $l}) {
213                             return $pagecase{lc $l};
214                      }
215     +               else {
216     +                   my $lindex = $l . "/index";
217     +                   if (exists $links{$lindex}) {
218     +                       return $lindex;
219     +               }
220     +               }
221              } while $cwd=~s!/?[^/]+$!!;
222      
223             if (length $config{userdir} && exists $links{"$config{userdir}/".lc($link)}) {
224
225 Note I handle setting the url; slightly differently.
226 Also note that an initial "index" is ignored.  I.e. a
227 page "A/B/index.html" is treated as "A/B".
228
229 > This is actually a pretty cool hack. I'll have to think about
230 > whether I like it better than my way though :) --Ethan
231
232 ---
233
234 How about doing the index stuff only on the output side? (Or does the latter patch do it? I haven't tried them.) That is, render every `foo.type` for the rendered types (mdwn etc.) as `foo/index.html`, generating links to `foo/` instead of `foo.html`, but not earlier than the point where the .html as presently appended to the page name. Then you just flip a build time option on an existing wiki without any changes to that, and the pages appear elsewhere. The `index.type` files might be left out of this scheme, though (and the top-level one, of course, has to). --[[tuomov]]
235
236 > Well, get around to wasting time on it after all, and [here's the patch](http://iki.fi/tuomov/use_dirs.diff). The `-use_dirs` option will cause everything to be rendered inside directories. There may still be some problems with it, that need looking into (it doesn't e.g. check for conflicts between foo/index.mdwn and foo.mdwn), but seems to work well enough for me... The patch also improves, I think, the parentlinks code a little, as it uses generic routines to actually find the target location now. The only places where the `use_dirs` option is used is `htmlpage`, in fact, although other specific kludges needed to be removed from other points in the code.
237
238 >> FWIW, [use_dirs.diff](http://iki.fi/tuomov/use_dirs.diff) applies cleanly, and works well for me. Given that it makes this behaviour optional, how about merging it? I have some follow-up patches which I'm sitting on for now. ;-) -- Ben
239
240 >>> How do you apply a patch created by svn diff? I've been curious about this for a long time. The use_dirs patch looks OK but I'd like to play with it. --Ethan
241
242 >>>> Just do `svn co svn://ikiwiki.kitenet.net/ikiwiki/trunk ikiwiki` then `cd ikiwiki && patch -p0 <use_dirs.diff`. :-) Same would work with a tarball as well.   
243
244 >>>>> Sorry, I'm dumb. I'm so used to doing -p1 that doing -p0 never occurred to me; I thought the patch format generated by svn diff was just "wrong". --Ethan
245
246 ----
247
248 First pass over Tumov's patch -- which doesn't cleanly apply anymore, so
249 I'll attach an updated and slightly modified version below.
250
251 * `urlto()` is O(N) to the number of pages in the wiki, which leads to
252   O(N^2) behavior, which could be a scalability problem. This happens because
253   of the lookup for `$to` in `%renderedfiles`, which shouldn't be necessary
254   most of the time. Couldn't it just be required that `$to` be a html page
255   name on input? Or require it be a non-html page name and always run
256   htmlpage on it.
257
258       > Perhaps it would be possible to require that, but it seems like a
259       > very artificial restriction.  The renderedfiles search is just a
260       > copy-paste from htmllink, and I'm no perl (or ikiwiki internals)
261       > expert... maybe there would be a faster way to do the check whether
262       > name translation is needed? No more than O(log n) steps should be
263       > needed for a simple search, after all, and maybe there would be shortcuts
264       > for even constant-time (in n) checks. --[[tuomov]]
265
266       >> Ah, so much easier to critque other people's code than your own.
267       >> You're right, this is a general problem, and I can get it to log n
268       >> if I really want to. --[[Joey]]
269
270 * As we discussed in email, this will break handling of `foo/index.mdwn`
271   pages. Needs to be changed to generate `foo/index/index.html` for such
272   pages (though not for the toplevel `index`).
273
274   >> Can someone elaborate on this? What's broken about it? Will pages
275   >> foo/index/index.html include foo/index in their parentlinks? --Ethan
276
277   >>> Presently the patch does not move `foo/index.type` as `foo/index/index.html`, but renders
278   >>> it as `foo/index.html`, not because I particularly want that (except for the top-level one, of
279   >>> course), but because it could be done :). This, however, conflicts with a `foo.mdwn`
280   >>> rendered as `foo/index.html`. The easiest and cleanest way to fix this, is to simply
281   >>> not handle `index` in such a special manner -- except for the top-level one. --[[tuomov]]
282
283   >>>> Oh, I see, this patch doesn't address wanting to use foo/index.mdwn as 
284   >>>> an input page. Hmm. --Ethan
285
286   >>>>> No, it doesn't. I originally also was after that, but after discussing the
287   >>>>> complexities of supporting that with Joey, came up with this simpler scheme
288   >>>>> without many of those issues. It is the output that I primarily care about, anyway,
289   >>>>> and I do, in fact, find the present input file organisation quite nice. The output
290   >>>>> locations just aren't very good for conversion of an existing site to ikiwiki, and do
291   >>>>> make for rather ugly URLs with the .html extensions. (I do often type some URLs
292   >>>>> out of memory, when they're gone from the browser's completion history, and the
293   >>>>> .html makes that more laboursome.)
294
295   >>>>>> I support your decision, but now this wiki page serves two different patches :).
296   >>>>>> Can we split them somehow?
297   >>>>>> What are the complexities involved?
298   >>>>>> I think I overcomplicated it a little with my patch, and Per Bothner's gets 
299   >>>>>> much closer to the heart of it. --Ethan
300
301 * This does make the resulting wikis much less browsable directly on the
302   filesystem, since `dir` to `dir/index.html` conversion is only handled by web
303   servers and so you end up browsing to a directory index all the time.
304   Wouldn't it be better to make the links themselves include the index.html?
305   (Although that would mean that [[bugs/broken_parentlinks]] would not be
306   fixed en passant by this patch..)
307
308      > Yes, the sites are not that browsable on the FS (I blame the browsers
309      > for being stupid!), but linking to the directory produces so much
310      > cleaner URLs for the Web, that I specifically want it. This is,
311      > after all, an optional arrangement. 
312
313      >> It's optional for *now* ... I suppose that I could make adding the
314      >> index.html yet another option. I'm not _that_ fond of optioons
315      >> however. --[[Joey]]
316
317      >>> It is worth noting, that with this patch, you _can_ render the local
318      >>> copy in the present manner, while rendering the Web copy under
319      >>> directories. So no extra options are really needed for local browsing, 
320      >>> unless you also want to serve the same copy over the Web, which I
321      >>> doubt. --[[tuomov]]
322
323 * Some of the generated links are missing the trailing / , which is
324   innefficient since it leads to a http redirect when clicking on that
325   link. Seems to be limited to ".." links, and possibly only to
326   parentlinks. (Already fixed it for "." links.)
327
328       > The solution seems to be to add to `urlto` the following snippet,
329       > which might also help with the next point. (Sorry, no updated patch
330       > yet. Should be on my way out in the cold anyway...)
331
332         if ( !length $to ) {
333                 return baseurl($from);
334         }
335       
336
337 * It calles abs2rel about 16% more often with the patch, which makes it
338   a bit slower, since abs2rel is not very efficient. (This omits abs2rel
339   calls that might be memoized away already.) This seems to be due to one
340   extra abs2rel for the toplevel wiki page due to the nicely cleaned up code
341   in `parentlinks` -- so I'm not really complaining.. Especially since the
342   patch adds a new nice memoizable `urlto`.
343 * The rss page name generation code seems unnecesarily roundabout, I'm sure
344   that can be cleaned up somehow, perhaps by making `htmlpage` more
345   generic.
346
347      > Something like `targetpage(basename, extension)`?
348
349      >> Yes exactly. It might also be possible to remove htmlpage from the
350      >> plugin interface entirely (in favour of urlto), which would be a
351      >> good time to make such a changes. Not required to accept this patch
352      >> though.
353
354 * `aggregate.pm` uses htmlpage in a way that breaks with its new behavior.
355   It will need to be changed as follows:
356
357 <pre>
358 Index: aggregate.pm
359 ===================================================================
360 --- aggregate.pm        (revision 2700)
361 +++ aggregate.pm        (working copy)
362 @@ -320,7 +320,7 @@
363                 # NB: This doesn't check for path length limits.
364                 eval q{use POSIX};
365                 my $max=POSIX::pathconf($config{srcdir}, &POSIX::_PC_NAME_MAX);
366 -               if (defined $max && length(htmlpage($page)) >= $max) {
367 +               if (defined $max && length(htmlfn($page)) >= $max) {
368                         $c="";
369                         $page=$feed->{dir}."/item";
370                         while (exists $IkiWiki::pagecase{lc $page.$c} ||
371 @@ -356,7 +356,7 @@
372         if (ref $feed->{tags}) {
373                 $template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
374         }
375 -       writefile(htmlpage($guid->{page}), $config{srcdir},
376 +       writefile(htmlfn($guid->{page}), $config{srcdir},
377                 $template->output);
378  
379         # Set the mtime, this lets the build process get the right creation
380 @@ -434,4 +434,8 @@
381         return "$config{srcdir}/".htmlpage($page);
382  } #}}}
383  
384 +sub htmlfn ($) { #{{{
385 +       return shift().".html";
386 +} #}}}
387 +
388  1
389 </pre>
390
391 * `linkmap.pm` uses `htmlpage` to construct a link and should probably be
392   changed like this (untested):
393
394 <pre>
395 Index: linkmap.pm
396 ===================================================================
397 --- linkmap.pm  (revision 2700)
398 +++ linkmap.pm  (working copy)
399 @@ -50,8 +50,7 @@
400         foreach my $item (keys %links) {
401                 if (pagespec_match($item, $params{pages}, $params{page})) {
402                         my $link=htmlpage($item);
403 -                       $link=IkiWiki::abs2rel($link, IkiWiki::dirname($params{page}));
404 -                       $mapitems{$item}=$link;
405 +                       $mapitems{$item}=urlto($link, $params{destpage});
406                 }
407         }
408 </pre>
409
410 > This is probably supposed to be `$mapitems{$item}=urlto($item, $params{destpage});`,
411 > which does indeed remove one more `htmlpage` call from the plugins. I can't actually
412 > try it: "failed writing to dst/ts.png.ikiwiki-new: Inappropriate ioctl for device".
413
414 >> Crazy perl bug that ioctl thing. Worked around now in svn. --[[Joey]]
415
416 > After this probable fix, in fact, all uses of htmlpage in the plugins are used to
417 > construct an absolute address: the absolute url in most cases, so an `absurl`
418 > call could be added to be used instead of htmlpage, and something else in the
419 > aggregate plugin (above), that I also think isn't what's wanted:
420 > aren't `foo.html` pages also "rendered", so that they get moved as `foo/index.html`?
421 > --[[tuomov]]
422
423 * `inline.pm` uses htmlpage and `abs2rel` to generate a link, and probably
424   needs to be changed to either use `urlto` or to call `beautify_url` like
425   htmllink does. This might work:
426
427 <pre>
428 Index: inline.pm
429 ===================================================================
430 --- inline.pm   (revision 2700)
431 +++ inline.pm   (working copy)
432 @@ -150,10 +150,7 @@
433                         # Don't use htmllink because this way the
434                         # title is separate and can be overridden by
435                         # other plugins.
436 -                       my $link=bestlink($params{page}, $page);
437 -                       $link=htmlpage($link) if defined $type;
438 -                       $link=abs2rel($link, dirname($params{destpage}));
439 -                       $template->param(pageurl => $link);
440 +                       $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
441                         $template->param(title => pagetitle(basename($page)));
442                         $template->param(ctime => displaytime($pagectime{$page}));
443 </pre>
444
445 * `img.pm` makes some assumptions about name of the page that will be
446   linking to the image, which are probably broken.
447
448 * The changes to htmlpage's behavior probably call for the plugin
449   interface version number to be changed.
450
451 --[[Joey]]
452
453 Updated version of Tumov's patch follows:
454
455 <pre>
456 Index: IkiWiki/Render.pm
457 ===================================================================
458 --- IkiWiki/Render.pm   (revision 2700)
459 +++ IkiWiki/Render.pm   (working copy)
460 @@ -32,8 +32,8 @@
461         my @links;
462         return unless $backlinks{$page};
463         foreach my $p (keys %{$backlinks{$page}}) {
464 -               my $href=abs2rel(htmlpage($p), dirname($page));
465 -                       
466 +               my $href=urlto($p, $page);
467 +                
468                 # Trim common dir prefixes from both pages.
469                 my $p_trimmed=$p;
470                 my $page_trimmed=$page;
471 @@ -55,18 +55,14 @@
472         my @ret;
473         my $pagelink="";
474         my $path="";
475 -       my $skip=1;
476 +       my $title=$config{wikiname};
477 +       
478         return if $page eq 'index'; # toplevel
479 -       foreach my $dir (reverse split("/", $page)) {
480 -               if (! $skip) {
481 -                       $path.="../";
482 -                       unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
483 -               }
484 -               else {
485 -                       $skip=0;
486 -               }
487 +       foreach my $dir (split("/", $page)) {
488 +               push @ret, { url => urlto($path, $page), page => $title };
489 +               $path.="/".$dir;
490 +               $title=pagetitle($dir);
491         }
492 -       unshift @ret, { url => length $path ? $path : ".", page => $config{wikiname} };
493         return @ret;
494  } #}}}
495  
496 Index: IkiWiki/Plugin/inline.pm
497 ===================================================================
498 --- IkiWiki/Plugin/inline.pm    (revision 2700)
499 +++ IkiWiki/Plugin/inline.pm    (working copy)
500 @@ -110,8 +110,8 @@
501  
502         add_depends($params{page}, $params{pages});
503  
504 -       my $rssurl=rsspage(basename($params{page}));
505 -       my $atomurl=atompage(basename($params{page}));
506 +       my $rssurl=basename(rsspage($params{page}));
507 +       my $atomurl=basename(atompage($params{page}));
508         my $ret="";
509  
510         if (exists $params{rootpage} && $config{cgiurl}) {
511 @@ -151,8 +151,7 @@
512                         # title is separate and can be overridden by
513                         # other plugins.
514                         my $link=bestlink($params{page}, $page);
515 -                       $link=htmlpage($link) if defined $type;
516 -                       $link=abs2rel($link, dirname($params{destpage}));
517 +                       $link=urlto($link, $params{destpage});
518                         $template->param(pageurl => $link);
519                         $template->param(title => pagetitle(basename($page)));
520                         $template->param(ctime => displaytime($pagectime{$page}));
521 @@ -205,15 +204,17 @@
522                 }
523         
524                 if ($rss) {
525 -                       will_render($params{page}, rsspage($params{page}));
526 -                       writefile(rsspage($params{page}), $config{destdir},
527 +                       my $rssp=rsspage($params{page});
528 +                       will_render($params{page}, $rssp);
529 +                       writefile($rssp, $config{destdir},
530                                 genfeed("rss", $rssurl, $desc, $params{page}, @list));
531                         $toping{$params{page}}=1 unless $config{rebuild};
532                         $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
533                 }
534                 if ($atom) {
535 -                       will_render($params{page}, atompage($params{page}));
536 -                       writefile(atompage($params{page}), $config{destdir},
537 +                       my $atomp=atompage($params{page});
538 +                       will_render($params{page}, $atomp);
539 +                       writefile($atomp, $config{destdir},
540                                 genfeed("atom", $atomurl, $desc, $params{page}, @list));
541                         $toping{$params{page}}=1 unless $config{rebuild};
542                         $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
543 @@ -288,16 +289,25 @@
544         return $content;
545  } #}}}
546  
547 +sub basepage ($) { #{{{
548 +       my $page=shift;
549 +       
550 +       $page=htmlpage($page);
551 +       $page =~ s/\.html$//;
552 +       
553 +       return $page;
554 +} #}}}
555 +
556  sub rsspage ($) { #{{{
557         my $page=shift;
558  
559 -       return $page.".rss";
560 +       return basepage($page).".rss";
561  } #}}}
562  
563  sub atompage ($) { #{{{
564         my $page=shift;
565  
566 -       return $page.".atom";
567 +       return basepage($page).".atom";
568  } #}}}
569  
570  sub genfeed ($$$$@) { #{{{
571 Index: ikiwiki.in
572 ===================================================================
573 --- ikiwiki.in  (revision 2700)
574 +++ ikiwiki.in  (working copy)
575 @@ -46,6 +46,7 @@
576                         "sslcookie!" => \$config{sslcookie},
577                         "httpauth!" => \$config{httpauth},
578                         "userdir=s" => \$config{userdir},
579 +                       "usedirs!" => \$config{usedirs},
580                         "exclude=s@" => sub {
581                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
582                         },
583 Index: doc/usage.mdwn
584 ===================================================================
585 --- doc/usage.mdwn      (revision 2700)
586 +++ doc/usage.mdwn      (working copy)
587 @@ -244,6 +244,10 @@
588  
589    Log to syslog(3).
590  
591 +* --usedirs
592 +
593 +  Create output files named page/index.html instead of page.html.
594 +
595  * --w3mmode, --no-w3mmode
596  
597    Enable [[w3mmode]], which allows w3m to use ikiwiki as a local CGI script,
598 Index: doc/plugins/write.mdwn
599 ===================================================================
600 --- doc/plugins/write.mdwn      (revision 2700)
601 +++ doc/plugins/write.mdwn      (working copy)
602 @@ -412,6 +412,10 @@
603  
604  This is the standard gettext function, although slightly optimised.
605  
606 +#### `urlto($$)`
607 +
608 +Construct a relative url to the first parameter from the second.
609 +
610  ## RCS plugins
611  
612  ikiwiki's support for revision control systems also uses pluggable perl
613 Index: doc/ikiwiki.setup
614 ===================================================================
615 --- doc/ikiwiki.setup   (revision 2700)
616 +++ doc/ikiwiki.setup   (working copy)
617 @@ -94,6 +94,8 @@
618         syslog => 0,
619         # To link to user pages in a subdirectory of the wiki.
620         #userdir => "users",
621 +       # To enable alternate output filenames.
622 +       #usedirs => 1,
623  
624         # To add plugins, list them here.
625         #add_plugins => [qw{goodstuff openid search wikitext camelcase
626 Index: IkiWiki.pm
627 ===================================================================
628 --- IkiWiki.pm  (revision 2700)
629 +++ IkiWiki.pm  (working copy)
630 @@ -14,7 +14,7 @@
631  use Exporter q{import};
632  our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
633                   bestlink htmllink readfile writefile pagetype srcfile pagename
634 -                 displaytime will_render gettext
635 +                 displaytime will_render gettext urlto
636                   %config %links %renderedfiles %pagesources);
637  our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
638  our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
639 @@ -72,6 +72,7 @@
640         sslcookie => 0,
641         httpauth => 0,
642         userdir => "",
643 +       usedirs => 0
644  } #}}}
645     
646  sub checkconfig () { #{{{
647 @@ -226,7 +227,11 @@
648  sub htmlpage ($) { #{{{
649         my $page=shift;
650  
651 -       return $page.".html";
652 +       if (! $config{usedirs} || $page =~ /^index$/ || $page =~ /\/index$/) {
653 +               return $page.".html";
654 +       } else {
655 +               return $page."/index.html"; 
656 +       }
657  } #}}}
658  
659  sub srcfile ($) { #{{{
660 @@ -390,6 +395,7 @@
661  
662         return "$config{url}/" if ! defined $page;
663         
664 +       $page=htmlpage($page);
665         $page=~s/[^\/]+$//;
666         $page=~s/[^\/]+\//..\//g;
667         return $page;
668 @@ -419,6 +425,29 @@
669                         $config{timeformat}, localtime($time)));
670  } #}}}
671  
672 +sub beautify_url ($) { #{{{
673 +       my $url=shift;
674 +
675 +       $url =~ s!/index.html$!/!;
676 +       $url =~ s!^$!./!; # Browsers don't like empty links...
677 +
678 +       return $url;
679 +} #}}}
680 +
681 +sub urlto ($$) { #{{{
682 +       my $to=shift;
683 +       my $from=shift;
684 +
685 +       if (length $to &&
686 +           ! grep { $_ eq $to } map { @{$_} } values %renderedfiles) {
687 +               $to=htmlpage($to);
688 +       }
689 +
690 +       my $link = abs2rel($to, dirname(htmlpage($from)));
691 +
692 +       return beautify_url($link);
693 +} #}}}
694 +
695  sub htmllink ($$$;@) { #{{{
696         my $lpage=shift; # the page doing the linking
697         my $page=shift; # the page that will contain the link (different for inline)
698 @@ -454,7 +483,8 @@
699                         "\">?</a>$linktext</span>"
700         }
701         
702 -       $bestlink=abs2rel($bestlink, dirname($page));
703 +       $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
704 +       $bestlink=beautify_url($bestlink);
705         
706         if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
707                 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
708 </pre>