]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Patch from Recai to allow selection of page type when creating a new page.
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Wed, 26 Jul 2006 21:23:06 +0000 (21:23 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Wed, 26 Jul 2006 21:23:06 +0000 (21:23 +0000)
  Default page type is inherited from the link clicked on to create the new
  page.

IkiWiki/CGI.pm
debian/changelog
doc/patchqueue/allow_to_select_a_page_type_on_new_file_creations.mdwn [deleted file]
templates/editpage.tmpl

index 21bb6ea38c9ff1844c2a857ac1672c8623725df5..759a49b7da6697df3b305930836acbf74914dd89 100644 (file)
@@ -325,7 +325,7 @@ sub cgi_editpage ($$) { #{{{
 
        eval q{use CGI::FormBuilder};
        my $form = CGI::FormBuilder->new(
 
        eval q{use CGI::FormBuilder};
        my $form = CGI::FormBuilder->new(
-               fields => [qw(do rcsinfo subpage from page editcontent comments)],
+               fields => [qw(do rcsinfo subpage from page type editcontent comments)],
                header => 1,
                charset => "utf-8",
                method => 'POST',
                header => 1,
                charset => "utf-8",
                method => 'POST',
@@ -353,13 +353,32 @@ sub cgi_editpage ($$) { #{{{
        }
        $page=lc($page);
        
        }
        $page=lc($page);
        
+       my $from;
+       if (defined $form->field('from')) {
+               ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
+       }
+       
        my $file;
        my $file;
-       if (exists $pagesources{lc($page)}) {
-               $file=$pagesources{lc($page)};
+       my $type;       
+       if (exists $pagesources{$page}) {
+               $file=$pagesources{$page};
+               $type=pagetype($file);
        }
        else {
        }
        else {
-               $file=$page.".".$config{default_pageext};
+               $type=$form->param('type');
+               if (defined $type && length $type && $hooks{htmlize}{$type}) {
+                       $type=possibly_foolish_untaint($type);
+               }
+               elsif (defined $from) {
+                       # favor the type of linking page
+                       $type=pagetype($pagesources{$from});
+               }
+               else {
+                       $type=$config{default_pageext};
+               }
+               $file=$page.".".$type;
        }
        }
+
        my $newfile=0;
        if (! -e "$config{srcdir}/$file") {
                $newfile=1;
        my $newfile=0;
        if (! -e "$config{srcdir}/$file") {
                $newfile=1;
@@ -369,7 +388,8 @@ sub cgi_editpage ($$) { #{{{
        $form->field(name => "from", type => 'hidden');
        $form->field(name => "rcsinfo", type => 'hidden');
        $form->field(name => "subpage", type => 'hidden');
        $form->field(name => "from", type => 'hidden');
        $form->field(name => "rcsinfo", type => 'hidden');
        $form->field(name => "subpage", type => 'hidden');
-       $form->field(name => "page", value => "$page", force => 1);
+       $form->field(name => "page", value => $page, force => 1);
+       $form->field(name => "type", value => $type, force => 1);
        $form->field(name => "comments", type => "text", size => 80);
        $form->field(name => "editcontent", type => "textarea", rows => 20,
                cols => 80);
        $form->field(name => "comments", type => "text", size => 80);
        $form->field(name => "editcontent", type => "textarea", rows => 20,
                cols => 80);
@@ -397,8 +417,7 @@ sub cgi_editpage ($$) { #{{{
                $form->field(name => "comments",
                                value => $comments, force => 1);
                $form->tmpl_param("page_preview",
                $form->field(name => "comments",
                                value => $comments, force => 1);
                $form->tmpl_param("page_preview",
-                       htmlize(pagetype($file),
-                               linkify($page, $page, $content)));
+                       htmlize($type, linkify($page, $page, $content)));
        }
        else {
                $form->tmpl_param("page_preview", "");
        }
        else {
                $form->tmpl_param("page_preview", "");
@@ -410,7 +429,6 @@ sub cgi_editpage ($$) { #{{{
                if ($form->field("do") eq "create") {
                        my @page_locs;
                        my $best_loc;
                if ($form->field("do") eq "create") {
                        my @page_locs;
                        my $best_loc;
-                       my ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
                        if (! defined $from || ! length $from ||
                            $from ne $form->field('from') ||
                            $from=~/$config{wiki_file_prune_regexp}/ ||
                        if (! defined $from || ! length $from ||
                            $from ne $form->field('from') ||
                            $from=~/$config{wiki_file_prune_regexp}/ ||
@@ -449,10 +467,17 @@ sub cgi_editpage ($$) { #{{{
                                redirect($q, "$config{url}/".htmlpage($page));
                                return;
                        }
                                redirect($q, "$config{url}/".htmlpage($page));
                                return;
                        }
-                               
+                       
+                       my @page_types;
+                       if (exists $hooks{htmlize}) {
+                               @page_types=keys %{$hooks{htmlize}};
+                       }
+                       
                        $form->tmpl_param("page_select", 1);
                        $form->field(name => "page", type => 'select',
                                options => \@page_locs, value => $best_loc);
                        $form->tmpl_param("page_select", 1);
                        $form->field(name => "page", type => 'select',
                                options => \@page_locs, value => $best_loc);
+                       $form->field(name => "type", type => 'select',
+                               options => \@page_types);
                        $form->title("creating ".pagetitle($page));
                }
                elsif ($form->field("do") eq "edit") {
                        $form->title("creating ".pagetitle($page));
                }
                elsif ($form->field("do") eq "edit") {
@@ -469,6 +494,7 @@ sub cgi_editpage ($$) { #{{{
                        }
                        $form->tmpl_param("page_select", 0);
                        $form->field(name => "page", type => 'hidden');
                        }
                        $form->tmpl_param("page_select", 0);
                        $form->field(name => "page", type => 'hidden');
+                       $form->field(name => "type", type => 'hidden');
                        $form->title("editing ".pagetitle($page));
                }
                
                        $form->title("editing ".pagetitle($page));
                }
                
@@ -517,6 +543,7 @@ sub cgi_editpage ($$) { #{{{
                                $form->field("do", "edit)");
                                $form->tmpl_param("page_select", 0);
                                $form->field(name => "page", type => 'hidden');
                                $form->field("do", "edit)");
                                $form->tmpl_param("page_select", 0);
                                $form->field(name => "page", type => 'hidden');
+                               $form->field(name => "type", type => 'hidden');
                                $form->title("editing $page");
                                print $form->render(submit => \@buttons);
                                return;
                                $form->title("editing $page");
                                print $form->render(submit => \@buttons);
                                return;
index 391569fad0f666301b56945ebc7ac3284206b191..50720bc0fb66707e2f6f424be92a7b9c48853972 100644 (file)
@@ -18,8 +18,11 @@ ikiwiki (1.9) UNRELEASED; urgency=low
     readable and avoid future mistakes. The patch seems to work and for the
     first time I have a UTF-8 username ;-) (Faidon)
   * Use form->field consistently, not form->param.
     readable and avoid future mistakes. The patch seems to work and for the
     first time I have a UTF-8 username ;-) (Faidon)
   * Use form->field consistently, not form->param.
+  * Patch from Recai to allow selection of page type when creating a new page.
+    Default page type is inherited from the link clicked on to create the new
+    page.
 
 
- -- Joey Hess <joeyh@debian.org>  Tue, 11 Jul 2006 17:18:39 -0400
+ -- Joey Hess <joeyh@debian.org>  Wed, 26 Jul 2006 16:48:43 -0400
 
 ikiwiki (1.8) unstable; urgency=low
 
 
 ikiwiki (1.8) unstable; urgency=low
 
diff --git a/doc/patchqueue/allow_to_select_a_page_type_on_new_file_creations.mdwn b/doc/patchqueue/allow_to_select_a_page_type_on_new_file_creations.mdwn
deleted file mode 100644 (file)
index d1c8655..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-From [[Recai]].
-       
-Note that this isn't safe since it needs to check file types from the CGI
-against the list of allowed file types. Also, renaming a page won't work so
-at least the first cut needs to be changed to only allow changing file type
-when crating a new page. -- [[Joey]]
-       
-       diff -rup ikiwiki.orig/IkiWiki/CGI.pm ikiwiki/IkiWiki/CGI.pm
-       --- ikiwiki.orig/IkiWiki/CGI.pm 2006-07-08 02:33:07.000000000 +0300
-       +++ ikiwiki/IkiWiki/CGI.pm      2006-07-08 18:27:24.000000000 +0300
-       @@ -310,7 +310,7 @@ sub cgi_editpage ($$) { #{{{
-        
-               eval q{use CGI::FormBuilder};
-               my $form = CGI::FormBuilder->new(
-       -               fields => [qw(do rcsinfo subpage from page editcontent comments)],
-       +               fields => [qw(do rcsinfo subpage from page type editcontent comments)],
-                       header => 1,
-                       charset => "utf-8",
-                       method => 'POST',
-       @@ -337,12 +337,21 @@ sub cgi_editpage ($$) { #{{{
-               $page=lc($page);
-               
-               my $file;
-       -       if (exists $pagesources{lc($page)}) {
-       -               $file=$pagesources{lc($page)};
-       +       my $type;       
-       +       if (exists $pagesources{$page}) {
-       +               $file=$pagesources{$page};
-       +               $type=pagetype($file);
-               }
-               else {
-       -               $file=$page.".".$config{default_pageext};
-       +               $type=$form->param('type');
-       +               if (defined $type && length $type) {
-       +                       $type=possibly_foolish_untaint($type);
-       +               } else {
-       +                       $type=$config{default_pageext};
-       +               }
-       +               $file=$page.".".$type;
-               }
-       +
-               my $newfile=0;
-               if (! -e "$config{srcdir}/$file") {
-                       $newfile=1;
-       @@ -353,6 +362,7 @@ sub cgi_editpage ($$) { #{{{
-               $form->field(name => "rcsinfo", type => 'hidden');
-               $form->field(name => "subpage", type => 'hidden');
-               $form->field(name => "page", value => "$page", force => 1);
-       +       $form->field(name => "type", value => "$type", force => 1, type => 'hidden');
-               $form->field(name => "comments", type => "text", size => 80);
-               $form->field(name => "editcontent", type => "textarea", rows => 20,
-                       cols => 80);
-       @@ -382,8 +392,7 @@ sub cgi_editpage ($$) { #{{{
-                       $form->field(name => "comments",
-                                       value => $comments, force => 1);
-                       $form->tmpl_param("page_preview",
-       -                       htmlize(pagetype($file),
-       -                               linkify($page, $page, $content)));
-       +                       htmlize($type, linkify($page, $page, $content)));
-               }
-               else {
-                       $form->tmpl_param("page_preview", "");
-       @@ -395,6 +404,8 @@ sub cgi_editpage ($$) { #{{{
-                       if ($form->field("do") eq "create") {
-                               my @page_locs;
-                               my $best_loc;
-       +                       my @page_types;
-       +                       my $best_type;
-                               my ($from)=$form->param('from')=~/$config{wiki_file_regexp}/;
-                               if (! defined $from || ! length $from ||
-                                   $from ne $form->param('from') ||
-       @@ -435,9 +446,24 @@ sub cgi_editpage ($$) { #{{{
-                                       return;
-                               }
-                                       
-       +                       if (exists $hooks{htmlize}) {
-       +                               @page_types=keys %{$hooks{htmlize}};
-       +                       }
-       +                       else {
-       +                               @page_types=($type);
-       +                       }
-       +
-       +                       # favor the type of originated page
-       +                       $best_type=pagetype($pagesources{$from});
-       +                       if (! defined $best_type || ! length $best_type) {
-       +                               $best_type=$type;
-       +                       }
-       +
-                               $form->tmpl_param("page_select", 1);
-                               $form->field(name => "page", type => 'select',
-                                       options => \@page_locs, value => $best_loc);
-       +                       $form->field(name => "type", type => 'select',
-       +                               options => \@page_types, value => $best_type);
-                               $form->title("creating ".pagetitle($page));
-                       }
-                       elsif ($form->field("do") eq "edit") {
-       @@ -454,6 +480,7 @@ sub cgi_editpage ($$) { #{{{
-                               }
-                               $form->tmpl_param("page_select", 0);
-                               $form->field(name => "page", type => 'hidden');
-       +                       $form->field(name => "type", type => 'hidden');
-                               $form->title("editing ".pagetitle($page));
-                       }
-                       
-       @@ -503,6 +530,7 @@ sub cgi_editpage ($$) { #{{{
-                                       $form->field("do", "edit)");
-                                       $form->tmpl_param("page_select", 0);
-                                       $form->field(name => "page", type => 'hidden');
-       +                               $form->field(name => "type", type => 'hidden');
-                                       $form->title("editing $page");
-                                       print $form->render(submit => \@buttons);
-                                       return;
-       diff -rup ikiwiki.orig/templates/editpage.tmpl ikiwiki/templates/editpage.tmpl
-       --- ikiwiki.orig/templates/editpage.tmpl        2006-07-03 03:13:46.000000000 +0300
-       +++ ikiwiki/templates/editpage.tmpl     2006-07-08 18:04:48.000000000 +0300
-       @@ -28,9 +28,11 @@ confict and commit again to save your ch
-        <TMPL_VAR FIELD-RCSINFO>
-        <TMPL_IF NAME="PAGE_SELECT">
-        Page location: <TMPL_VAR FIELD-PAGE>
-       +Page type: <TMPL_VAR FIELD-TYPE>
-        <TMPL_ELSE>
-        <br />
-        <TMPL_VAR FIELD-PAGE>
-       +<TMPL_VAR FIELD-TYPE>
-        </TMPL_IF>
-        <TMPL_VAR FIELD-EDITCONTENT><br />
-        <TMPL_IF NAME="CAN_COMMIT">
index cf4520575ba04776ddf3cf65ab9521f281473ca6..1ee4c49479c16017e7f93ff8654290983cb8fc44 100644 (file)
@@ -28,9 +28,11 @@ confict and commit again to save your changes.
 <TMPL_VAR FIELD-RCSINFO>
 <TMPL_IF NAME="PAGE_SELECT">
 Page location: <TMPL_VAR FIELD-PAGE>
 <TMPL_VAR FIELD-RCSINFO>
 <TMPL_IF NAME="PAGE_SELECT">
 Page location: <TMPL_VAR FIELD-PAGE>
+Page type: <TMPL_VAR FIELD-TYPE>
 <TMPL_ELSE>
 <br />
 <TMPL_VAR FIELD-PAGE>
 <TMPL_ELSE>
 <br />
 <TMPL_VAR FIELD-PAGE>
+<TMPL_VAR FIELD-TYPE>
 </TMPL_IF>
 <TMPL_VAR FIELD-EDITCONTENT><br />
 <TMPL_IF NAME="CAN_COMMIT">
 </TMPL_IF>
 <TMPL_VAR FIELD-EDITCONTENT><br />
 <TMPL_IF NAME="CAN_COMMIT">