]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/patchqueue/allow_to_select_a_page_type_on_new_file_creations.mdwn
web commit by joey
[git.ikiwiki.info.git] / doc / patchqueue / allow_to_select_a_page_type_on_new_file_creations.mdwn
1 From [[Recai]].
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 ($$) { #{{{
12  
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)],
17                 header => 1,
18                 charset => "utf-8",
19                 method => 'POST',
20 @@ -337,12 +337,21 @@ sub cgi_editpage ($$) { #{{{
21         $page=lc($page);
22         
23         my $file;
24 -       if (exists $pagesources{lc($page)}) {
25 -               $file=$pagesources{lc($page)};
26 +       my $type;       
27 +       if (exists $pagesources{$page}) {
28 +               $file=$pagesources{$page};
29 +               $type=pagetype($file);
30         }
31         else {
32 -               $file=$page.".".$config{default_pageext};
33 +               $type=$form->param('type');
34 +               if (defined $type && length $type) {
35 +                       $type=possibly_foolish_untaint($type);
36 +               } else {
37 +                       $type=$config{default_pageext};
38 +               }
39 +               $file=$page.".".$type;
40         }
41 +
42         my $newfile=0;
43         if (! -e "$config{srcdir}/$file") {
44                 $newfile=1;
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,
52                 cols => 80);
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)));
60         }
61         else {
62                 $form->tmpl_param("page_preview", "");
63 @@ -395,6 +404,8 @@ sub cgi_editpage ($$) { #{{{
64                 if ($form->field("do") eq "create") {
65                         my @page_locs;
66                         my $best_loc;
67 +                       my @page_types;
68 +                       my $best_type;
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 ($$) { #{{{
73                                 return;
74                         }
75                                 
76 +                       if (exists $hooks{htmlize}) {
77 +                               @page_types=keys %{$hooks{htmlize}};
78 +                       }
79 +                       else {
80 +                               @page_types=($type);
81 +                       }
82 +
83 +                       # favor the type of originated page
84 +                       $best_type=pagetype($pagesources{$from});
85 +                       if (! defined $best_type || ! length $best_type) {
86 +                               $best_type=$type;
87 +                       }
88 +
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));
95                 }
96                 elsif ($form->field("do") eq "edit") {
97 @@ -454,6 +480,7 @@ sub cgi_editpage ($$) { #{{{
98                         }
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));
103                 }
104                 
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);
112                                 return;
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>
121  <TMPL_ELSE>
122  <br />
123  <TMPL_VAR FIELD-PAGE>
124 +<TMPL_VAR FIELD-TYPE>
125  </TMPL_IF>
126  <TMPL_VAR FIELD-EDITCONTENT><br />
127  <TMPL_IF NAME="CAN_COMMIT">