3 Note that this isn't safe since it needs to check file types from the CGI
4 against the list of allowed file types. Also, renaming a page won't work so
5 at least the first cut needs to be changed to only allow changing file type
6 when crating a new page. -- [[Joey]]
8 diff -rup ikiwiki.orig/IkiWiki/CGI.pm ikiwiki/IkiWiki/CGI.pm
9 --- ikiwiki.orig/IkiWiki/CGI.pm 2006-07-08 02:33:07.000000000 +0300
10 +++ ikiwiki/IkiWiki/CGI.pm 2006-07-08 18:27:24.000000000 +0300
11 @@ -310,7 +310,7 @@ sub cgi_editpage ($$) { #{{{
13 eval q{use CGI::FormBuilder};
14 my $form = CGI::FormBuilder->new(
15 - fields => [qw(do rcsinfo subpage from page editcontent comments)],
16 + fields => [qw(do rcsinfo subpage from page type editcontent comments)],
20 @@ -337,12 +337,21 @@ sub cgi_editpage ($$) { #{{{
24 - if (exists $pagesources{lc($page)}) {
25 - $file=$pagesources{lc($page)};
27 + if (exists $pagesources{$page}) {
28 + $file=$pagesources{$page};
29 + $type=pagetype($file);
32 - $file=$page.".".$config{default_pageext};
33 + $type=$form->param('type');
34 + if (defined $type && length $type) {
35 + $type=possibly_foolish_untaint($type);
37 + $type=$config{default_pageext};
39 + $file=$page.".".$type;
43 if (! -e "$config{srcdir}/$file") {
45 @@ -353,6 +362,7 @@ sub cgi_editpage ($$) { #{{{
46 $form->field(name => "rcsinfo", type => 'hidden');
47 $form->field(name => "subpage", type => 'hidden');
48 $form->field(name => "page", value => "$page", force => 1);
49 + $form->field(name => "type", value => "$type", force => 1, type => 'hidden');
50 $form->field(name => "comments", type => "text", size => 80);
51 $form->field(name => "editcontent", type => "textarea", rows => 20,
53 @@ -382,8 +392,7 @@ sub cgi_editpage ($$) { #{{{
54 $form->field(name => "comments",
55 value => $comments, force => 1);
56 $form->tmpl_param("page_preview",
57 - htmlize(pagetype($file),
58 - linkify($page, $page, $content)));
59 + htmlize($type, linkify($page, $page, $content)));
62 $form->tmpl_param("page_preview", "");
63 @@ -395,6 +404,8 @@ sub cgi_editpage ($$) { #{{{
64 if ($form->field("do") eq "create") {
69 my ($from)=$form->param('from')=~/$config{wiki_file_regexp}/;
70 if (! defined $from || ! length $from ||
71 $from ne $form->param('from') ||
72 @@ -435,9 +446,24 @@ sub cgi_editpage ($$) { #{{{
76 + if (exists $hooks{htmlize}) {
77 + @page_types=keys %{$hooks{htmlize}};
80 + @page_types=($type);
83 + # favor the type of originated page
84 + $best_type=pagetype($pagesources{$from});
85 + if (! defined $best_type || ! length $best_type) {
89 $form->tmpl_param("page_select", 1);
90 $form->field(name => "page", type => 'select',
91 options => \@page_locs, value => $best_loc);
92 + $form->field(name => "type", type => 'select',
93 + options => \@page_types, value => $best_type);
94 $form->title("creating ".pagetitle($page));
96 elsif ($form->field("do") eq "edit") {
97 @@ -454,6 +480,7 @@ sub cgi_editpage ($$) { #{{{
99 $form->tmpl_param("page_select", 0);
100 $form->field(name => "page", type => 'hidden');
101 + $form->field(name => "type", type => 'hidden');
102 $form->title("editing ".pagetitle($page));
105 @@ -503,6 +530,7 @@ sub cgi_editpage ($$) { #{{{
106 $form->field("do", "edit)");
107 $form->tmpl_param("page_select", 0);
108 $form->field(name => "page", type => 'hidden');
109 + $form->field(name => "type", type => 'hidden');
110 $form->title("editing $page");
111 print $form->render(submit => \@buttons);
113 diff -rup ikiwiki.orig/templates/editpage.tmpl ikiwiki/templates/editpage.tmpl
114 --- ikiwiki.orig/templates/editpage.tmpl 2006-07-03 03:13:46.000000000 +0300
115 +++ ikiwiki/templates/editpage.tmpl 2006-07-08 18:04:48.000000000 +0300
116 @@ -28,9 +28,11 @@ confict and commit again to save your ch
117 <TMPL_VAR FIELD-RCSINFO>
118 <TMPL_IF NAME="PAGE_SELECT">
119 Page location: <TMPL_VAR FIELD-PAGE>
120 +Page type: <TMPL_VAR FIELD-TYPE>
123 <TMPL_VAR FIELD-PAGE>
124 +<TMPL_VAR FIELD-TYPE>
126 <TMPL_VAR FIELD-EDITCONTENT><br />
127 <TMPL_IF NAME="CAN_COMMIT">