-
- run_hooks(formbuilder_setup => sub {
- shift->(form => $form, cgi => $q, session => $session,
- buttons => \@buttons);
- });
-
- # This untaint is safe because titlepage removes any problematic
- # characters.
- my ($page)=$form->field('page');
- $page=titlepage(possibly_foolish_untaint($page));
- if (! defined $page || ! length $page ||
- file_pruned($page, $config{srcdir}) || $page=~/^\//) {
- error("bad page name");
- }
-
- my $from;
- if (defined $form->field('from')) {
- ($from)=$form->field('from')=~/$config{wiki_file_regexp}/;
- }
-
- my $file;
- my $type;
- if (exists $pagesources{$page} && $form->field("do") ne "create") {
- $file=$pagesources{$page};
- $type=pagetype($file);
- if (! defined $type || $type=~/^_/) {
- error(sprintf(gettext("%s is not an editable page"), $page));
- }
- if (! $form->submitted) {
- $form->field(name => "rcsinfo",
- value => rcs_prepedit($file), force => 1);
- }
- $form->field(name => "editcontent", validate => '/.*/');
- }
- else {
- $type=$form->param('type');
- if (defined $type && length $type && $hooks{htmlize}{$type}) {
- $type=possibly_foolish_untaint($type);
- }
- elsif (defined $from && exists $pagesources{$from}) {
- # favor the type of linking page
- $type=pagetype($pagesources{$from});
- }
- $type=$config{default_pageext} unless defined $type;
- $file=$page.".".$type;
- if (! $form->submitted) {
- $form->field(name => "rcsinfo", value => "", force => 1);
- }
- $form->field(name => "editcontent", validate => '/.+/');
- }
-
- $form->field(name => "do", 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 => pagetitle($page, 1), 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->tmpl_param("can_commit", $config{rcs});
- $form->tmpl_param("indexlink", indexlink());
- $form->tmpl_param("helponformattinglink",
- htmllink("", "", "ikiwiki/formatting",
- noimageinline => 1,
- linktext => "FormattingHelp"));
- $form->tmpl_param("baseurl", baseurl());
-
- if ($form->submitted eq "Cancel") {
- if ($form->field("do") eq "create" && defined $from) {
- redirect($q, "$config{url}/".htmlpage($from));
- }
- elsif ($form->field("do") eq "create") {
- redirect($q, $config{url});
- }
- else {
- redirect($q, "$config{url}/".htmlpage($page));
- }
- return;