- @page_locs = grep {
- ! exists $pagecase{lc $_} &&
- ! page_locked($_, $session, 1)
- } @page_locs;
-
- if (! @page_locs) {
- # hmm, someone else made the page in the
- # meantime?
- 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->field(name => "type", type => 'select',
- options => \@page_types);
- $form->title("creating ".pagetitle($page));
- }
- elsif ($form->field("do") eq "edit") {
- page_locked($page, $session);
- if (! defined $form->field('editcontent') ||
- ! length $form->field('editcontent')) {
- my $content="";
- if (exists $pagesources{$page}) {
- $content=readfile(srcfile($pagesources{$page}));
- $content=~s/\n/\r\n/g;
- }
- $form->field(name => "editcontent", value => $content,
- force => 1);
- }
- $form->tmpl_param("page_select", 0);
- $form->field(name => "page", type => 'hidden');
- $form->field(name => "type", type => 'hidden');
- $form->title("editing ".pagetitle($page));
- }
-
- print $form->render(submit => \@buttons);
- }
- else {
- # save page
- page_locked($page, $session);
-
- my $content=$form->field('editcontent');
-
- $content=~s/\r\n/\n/g;
- $content=~s/\r/\n/g;
- writefile($file, $config{srcdir}, $content);
-
- if ($config{rcs}) {
- my $message="";
- if (defined $form->field('comments') &&
- length $form->field('comments')) {
- $message=$form->field('comments');
- }
-
- if ($newfile) {
- rcs_add($file);
- }
- # prevent deadlock with post-commit hook
- unlockwiki();
- # presumably the commit will trigger an update
- # of the wiki
- my $conflict=rcs_commit($file, $message,
- $form->field("rcsinfo"),
- $session->param("name"), $ENV{REMOTE_ADDR});
-
- if (defined $conflict) {
- $form->field(name => "rcsinfo", value => rcs_prepedit($file),
- force => 1);
- $form->tmpl_param("page_conflict", 1);
- $form->field("editcontent", value => $conflict, force => 1);
- $form->field(name => "comments", value => $form->field('comments'), force => 1);
- $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;
- }
- }
- else {
- require IkiWiki::Render;
- refresh();
- saveindex();
- }
-
- # The trailing question mark tries to avoid broken
- # caches and get the most recent version of the page.
- redirect($q, "$config{url}/".htmlpage($page)."?updated");
- }