2 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
12 my (%links, %oldlinks, %oldpagemtime, %renderedfiles, %pagesources);
15 wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
16 wiki_link_regexp => qr/\[\[([^\s]+)\]\]/,
17 wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
20 default_pageext => ".mdwn",
35 "wikiname=s" => \$config{wikiname},
36 "verbose|v!" => \$config{verbose},
37 "rebuild!" => \$config{rebuild},
38 "wrapper!" => \$config{wrapper},
39 "svn!" => \$config{svn},
40 "anonok!" => \$config{anonok},
41 "cgi!" => \$config{cgi},
42 "url=s" => \$config{url},
43 "cgiurl=s" => \$config{cgiurl},
44 "historyurl=s" => \$config{historyurl},
46 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
50 usage() unless @ARGV == 3;
51 $config{srcdir} = possibly_foolish_untaint(shift);
52 $config{templatedir} = possibly_foolish_untaint(shift);
53 $config{destdir} = possibly_foolish_untaint(shift);
54 if ($config{cgi} && ! length $config{url}) {
55 error("Must specify url to wiki with --url when using --cgi");
59 die "usage: ikiwiki [options] source templates dest\n";
64 print "Content-type: text/html\n\n";
65 print misctemplate("Error", "<p>Error: @_</p>");
74 return unless $config{verbose};
86 return (stat($page))[9];
89 sub possibly_foolish_untaint { #{{{
91 my ($untainted)=$tainted=~/(.*)/;
95 sub basename ($) { #{{{
102 sub dirname ($) { #{{{
109 sub pagetype ($) { #{{{
112 if ($page =~ /\.mdwn$/) {
120 sub pagename ($) { #{{{
123 my $type=pagetype($file);
125 $page=~s/\Q$type\E*$// unless $type eq 'unknown';
129 sub htmlpage ($) { #{{{
132 return $page.".html";
135 sub readfile ($) { #{{{
139 open (IN, "$file") || error("failed to read $file: $!");
145 sub writefile ($$) { #{{{
149 my $dir=dirname($file);
152 foreach my $s (split(m!/+!, $dir)) {
155 mkdir($d) || error("failed to create directory $d: $!");
160 open (OUT, ">$file") || error("failed to write $file: $!");
165 sub findlinks ($) { #{{{
169 while ($content =~ /$config{wiki_link_regexp}/g) {
175 sub bestlink ($$) { #{{{
176 # Given a page and the text of a link on the page, determine which
177 # existing page that link best points to. Prefers pages under a
178 # subdirectory with the same name as the source page, failing that
179 # goes down the directory tree to the base looking for matching
187 $l.="/" if length $l;
190 if (exists $links{$l}) {
191 #debug("for $page, \"$link\", use $l");
194 } while $cwd=~s!/?[^/]+$!!;
196 #print STDERR "warning: page $page, broken link: $link\n";
200 sub isinlinableimage ($) { #{{{
203 $file=~/\.(png|gif|jpg|jpeg)$/;
209 my $noimageinline=shift; # don't turn links into inline html images
210 my $createsubpage=shift; # force creation of a subpage if page DNE
212 my $bestlink=bestlink($page, $link);
214 return $link if length $bestlink && $page eq $bestlink;
216 # TODO BUG: %renderedfiles may not have it, if the linked to page
217 # was also added and isn't yet rendered! Note that this bug is
218 # masked by the bug mentioned below that makes all new files
220 if (! grep { $_ eq $bestlink } values %renderedfiles) {
221 $bestlink=htmlpage($bestlink);
223 if (! grep { $_ eq $bestlink } values %renderedfiles) {
224 if (! $createsubpage) {
225 return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$link"
228 return "<a href=\"$config{cgiurl}?do=create&page=$page/$link\">?</a>$link"
232 $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
234 if (! $noimageinline && isinlinableimage($bestlink)) {
235 return "<img src=\"$bestlink\">";
237 return "<a href=\"$bestlink\">$link</a>";
240 sub linkify ($$) { #{{{
244 $content =~ s/$config{wiki_link_regexp}/htmllink(pagename($file), $1)/eg;
249 sub htmlize ($$) { #{{{
253 if (! $INC{"/usr/bin/markdown"}) {
254 $blosxom::version="is a proper perl module too much to ask?";
255 do "/usr/bin/markdown";
258 if ($type eq '.mdwn') {
259 return Markdown::Markdown($content);
262 error("htmlization of $type not supported");
266 sub backlinks ($) { #{{{
270 foreach my $p (keys %links) {
271 next if bestlink($page, $p) eq $page;
272 if (grep { length $_ && bestlink($p, $_) eq $page } @{$links{$p}}) {
273 my $href=File::Spec->abs2rel(htmlpage($p), dirname($page));
275 # Trim common dir prefixes from both pages.
277 my $page_trimmed=$page;
279 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
281 $p_trimmed=~s/^\Q$dir\E// &&
282 $page_trimmed=~s/^\Q$dir\E//;
284 push @links, { url => $href, page => $p_trimmed };
288 return sort { $a->{page} cmp $b->{page} } @links;
291 sub parentlinks ($) { #{{{
298 foreach my $dir (reverse split("/", $page)) {
300 unshift @ret, { url => "$path$dir.html", page => $dir };
307 unshift @ret, { url => $path , page => $config{wikiname} };
311 sub indexlink () { #{{{
312 return "<a href=\"$config{url}\">$config{wikiname}</a>";
315 sub finalize ($$) { #{{{
319 my $title=basename($page);
322 my $template=HTML::Template->new(blind_cache => 1,
323 filename => "$config{templatedir}/page.tmpl");
325 if (length $config{cgiurl}) {
326 $template->param(editurl => "$config{cgiurl}?do=edit&page=$page");
328 $template->param(recentchangesurl => "$config{cgiurl}?do=recentchanges");
332 if (length $config{historyurl}) {
333 my $u=$config{historyurl};
334 $u=~s/\[\[\]\]/$pagesources{$page}/g;
335 $template->param(historyurl => $u);
340 wikiname => $config{wikiname},
341 parentlinks => [parentlinks($page)],
343 backlinks => [backlinks($page)],
344 discussionlink => htmllink($page, "Discussion", 1, 1),
347 return $template->output;
350 sub check_overwrite ($$) { #{{{
351 # Important security check. Make sure to call this before saving
352 # any files to the source directory.
356 if (! exists $renderedfiles{$src} && -e $dest && ! $config{rebuild}) {
357 error("$dest exists and was rendered from ".
358 join(" ",(grep { $renderedfiles{$_} eq $dest } keys
360 ", not from $src before not overwriting");
364 sub render ($) { #{{{
367 my $type=pagetype($file);
368 my $content=readfile("$config{srcdir}/$file");
369 if ($type ne 'unknown') {
370 my $page=pagename($file);
372 $links{$page}=[findlinks($content)];
374 $content=linkify($content, $file);
375 $content=htmlize($type, $content);
376 $content=finalize($content, $page);
378 check_overwrite("$config{destdir}/".htmlpage($page), $page);
379 writefile("$config{destdir}/".htmlpage($page), $content);
380 $oldpagemtime{$page}=time;
381 $renderedfiles{$page}=htmlpage($page);
385 check_overwrite("$config{destdir}/$file", $file);
386 writefile("$config{destdir}/$file", $content);
387 $oldpagemtime{$file}=time;
388 $renderedfiles{$file}=$file;
392 sub loadindex () { #{{{
393 open (IN, "$config{srcdir}/.ikiwiki/index") || return;
395 $_=possibly_foolish_untaint($_);
397 my ($mtime, $file, $rendered, @links)=split(' ', $_);
398 my $page=pagename($file);
399 $pagesources{$page}=$file;
400 $oldpagemtime{$page}=$mtime;
401 $oldlinks{$page}=[@links];
402 $links{$page}=[@links];
403 $renderedfiles{$page}=$rendered;
408 sub saveindex () { #{{{
409 if (! -d "$config{srcdir}/.ikiwiki") {
410 mkdir("$config{srcdir}/.ikiwiki");
412 open (OUT, ">$config{srcdir}/.ikiwiki/index") || error("cannot write to index: $!");
413 foreach my $page (keys %oldpagemtime) {
414 print OUT "$oldpagemtime{$page} $pagesources{$page} $renderedfiles{$page} ".
415 join(" ", @{$links{$page}})."\n"
416 if $oldpagemtime{$page};
421 sub rcs_update () { #{{{
422 if (-d "$config{srcdir}/.svn") {
423 if (system("svn", "update", "--quiet", $config{srcdir}) != 0) {
424 warn("svn update failed\n");
429 sub rcs_commit ($) { #{{{
432 if (-d "$config{srcdir}/.svn") {
433 if (system("svn", "commit", "--quiet", "-m",
434 possibly_foolish_untaint($message),
435 $config{srcdir}) != 0) {
436 warn("svn commit failed\n");
441 sub rcs_add ($) { #{{{
444 if (-d "$config{srcdir}/.svn") {
445 my $parent=dirname($file);
446 while (! -d "$config{srcdir}/$parent/.svn") {
448 $parent=dirname($file);
451 if (system("svn", "add", "--quiet", "$config{srcdir}/$file") != 0) {
452 warn("svn add failed\n");
457 sub rcs_recentchanges ($) { #{{{
461 eval q{use Date::Parse};
462 eval q{use Time::Duration};
464 if (-d "$config{srcdir}/.svn") {
465 my $info=`LANG=C svn info $config{srcdir}`;
466 my ($svn_url)=$info=~/^URL: (.*)$/m;
468 # FIXME: currently assumes that the wiki is somewhere
469 # under trunk in svn, doesn't support other layouts.
470 my ($svn_base)=$svn_url=~m!(/trunk(?:/.*)?)$!;
472 my $div=qr/^--------------------+$/;
473 my $infoline=qr/^r(\d+)\s+\|\s+([^\s]+)\s+\|\s+(\d+-\d+-\d+\s+\d+:\d+:\d+\s+[-+]?\d+).*/;
475 my ($rev, $user, $when, @pages, @message);
476 foreach (`LANG=C svn log -v '$svn_url'`) {
478 if ($state eq 'start' && /$div/) {
481 elsif ($state eq 'header' && /$infoline/) {
484 $when=concise(ago(time - str2time($3)));
486 elsif ($state eq 'header' && /^\s+[A-Z]\s+\Q$svn_base\E\/(.+)$/) {
487 push @pages, { link => htmllink("", pagename($1), 1) }
490 elsif ($state eq 'header' && /^$/) {
493 elsif ($state eq 'body' && /$div/) {
494 my $committype="web";
495 if (defined $message[0] &&
496 $message[0]->{line}=~/^web commit by (\w+):?(.*)/) {
498 $message[0]->{line}=$2;
504 push @ret, { rev => $rev,
505 user => htmllink("", $user, 1),
506 committype => $committype,
507 when => $when, message => [@message],
508 pages => [@pages] } if @pages;
509 return @ret if @ret >= $num;
512 $rev=$user=$when=undef;
515 elsif ($state eq 'body') {
516 push @message, {line => $_},
528 my $dir=dirname($file);
529 while (rmdir($dir)) {
534 sub refresh () { #{{{
535 # Find existing pages.
541 if (/$config{wiki_file_prune_regexp}/) {
542 $File::Find::prune=1;
545 my ($f)=/$config{wiki_file_regexp}/; # untaint
547 warn("skipping bad filename $_\n");
550 $f=~s/^\Q$config{srcdir}\E\/?//;
552 $exists{pagename($f)}=1;
560 # check for added or removed pages
562 foreach my $file (@files) {
563 my $page=pagename($file);
564 if (! $oldpagemtime{$page}) {
565 debug("new page $page");
568 $pagesources{$page}=$file;
572 foreach my $page (keys %oldpagemtime) {
573 if (! $exists{$page}) {
574 debug("removing old page $page");
575 push @del, $renderedfiles{$page};
576 prune($config{destdir}."/".$renderedfiles{$page});
577 delete $renderedfiles{$page};
578 $oldpagemtime{$page}=0;
579 delete $pagesources{$page};
583 # render any updated files
584 foreach my $file (@files) {
585 my $page=pagename($file);
587 if (! exists $oldpagemtime{$page} ||
588 mtime("$config{srcdir}/$file") > $oldpagemtime{$page}) {
589 debug("rendering changed file $file");
595 # if any files were added or removed, check to see if each page
596 # needs an update due to linking to them
597 # TODO: inefficient; pages may get rendered above and again here;
598 # problem is the bestlink may have changed and we won't know until
601 FILE: foreach my $file (@files) {
602 my $page=pagename($file);
603 foreach my $f (@add, @del) {
605 foreach my $link (@{$links{$page}}) {
606 if (bestlink($page, $link) eq $p) {
607 debug("rendering $file, which links to $p");
617 # handle backlinks; if a page has added/removed links, update the
619 # TODO: inefficient; pages may get rendered above and again here;
620 # problem is the backlinks could be wrong in the first pass render
624 foreach my $file (keys %rendered, @del) {
625 my $page=pagename($file);
626 if (exists $links{$page}) {
627 foreach my $link (@{$links{$page}}) {
628 $link=bestlink($page, $link);
630 ! exists $oldlinks{$page} ||
631 ! grep { $_ eq $link } @{$oldlinks{$page}}) {
632 $linkchanged{$link}=1;
636 if (exists $oldlinks{$page}) {
637 foreach my $link (@{$oldlinks{$page}}) {
638 $link=bestlink($page, $link);
640 ! exists $links{$page} ||
641 ! grep { $_ eq $link } @{$links{$page}}) {
642 $linkchanged{$link}=1;
647 foreach my $link (keys %linkchanged) {
648 my $linkfile=$pagesources{$link};
649 if (defined $linkfile) {
650 debug("rendering $linkfile, to update its backlinks");
657 sub gen_wrapper () { #{{{
658 eval q{use Cwd 'abs_path'};
659 $config{srcdir}=abs_path($config{srcdir});
660 $config{destdir}=abs_path($config{destdir});
661 my $this=abs_path($0);
663 error("$this doesn't seem to be executable");
666 my @params=($config{srcdir}, $config{templatedir}, $config{destdir},
667 "--wikiname=$config{wikiname}");
668 push @params, "--verbose" if $config{verbose};
669 push @params, "--rebuild" if $config{rebuild};
670 push @params, "--nosvn" if !$config{svn};
671 push @params, "--cgi" if $config{cgi};
672 push @params, "--url=$config{url}" if length $config{url};
673 push @params, "--cgiurl=$config{cgiurl}" if length $config{cgiurl};
674 push @params, "--historyurl=$config{historyurl}" if length $config{historyurl};
675 push @params, "--anonok" if $config{anonok};
676 my $params=join(" ", map { "\'$_\'" } @params);
678 foreach my $p ($this, $this, @params) {
684 push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
685 CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE
686 HTTP_COOKIE} if $config{cgi};
688 foreach my $var (@envsave) {
690 if ((s=getenv("$var")))
691 asprintf(&newenviron[i++], "%s=%s", "$var", s);
695 open(OUT, ">ikiwiki-wrap.c") || error("failed to write ikiwiki-wrap.c: $!");;
697 /* A wrapper for ikiwiki, can be safely made suid. */
704 extern char **environ;
706 int main (int argc, char **argv) {
707 /* Sanitize environment. */
709 char *newenviron[$#envsave+3];
712 newenviron[i++]="HOME=$ENV{HOME}";
716 if (argc == 2 && strcmp(argv[1], "--params") == 0) {
717 printf("$params\\n");
722 perror("failed to run $this");
727 if (system("gcc", "ikiwiki-wrap.c", "-o", "ikiwiki-wrap") != 0) {
728 error("failed to compile ikiwiki-wrap.c");
730 unlink("ikiwiki-wrap.c");
731 print "successfully generated ikiwiki-wrap\n";
735 sub misctemplate ($$) { #{{{
739 my $template=HTML::Template->new(
740 filename => "$config{templatedir}/misc.tmpl"
744 indexlink => indexlink(),
745 wikiname => $config{wikiname},
746 pagebody => $pagebody,
748 return $template->output;
751 sub cgi_recentchanges ($) { #{{{
754 my $template=HTML::Template->new(
755 filename => "$config{templatedir}/recentchanges.tmpl"
758 title => "RecentChanges",
759 indexlink => indexlink(),
760 wikiname => $config{wikiname},
761 changelog => [rcs_recentchanges(100)],
763 print $q->header, $template->output;
766 sub userinfo_get ($$) { #{{{
770 eval q{use Storable};
771 my $userdata=eval{ Storable::lock_retrieve("$config{srcdir}/.ikiwiki/userdb") };
772 if (! defined $userdata || ! ref $userdata ||
773 ! exists $userdata->{$user} || ! ref $userdata->{$user}) {
776 return $userdata->{$user}->{$field};
779 sub userinfo_set ($$) { #{{{
783 eval q{use Storable};
784 my $userdata=eval{ Storable::lock_retrieve("$config{srcdir}/.ikiwiki/userdb") };
785 if (! defined $userdata || ! ref $userdata) {
788 $userdata->{$user}=$info;
789 my $oldmask=umask(077);
790 my $ret=Storable::lock_store($userdata, "$config{srcdir}/.ikiwiki/userdb");
795 sub cgi_signin ($$) { #{{{
799 eval q{use CGI::FormBuilder};
800 my $form = CGI::FormBuilder->new(
801 title => "$config{wikiname} signin",
802 fields => [qw(do page from name password confirm_password email)],
806 confirm_password => {
807 perl => q{eq $form->field("password")},
814 action => $q->request_uri,
816 template => (-e "$config{templatedir}/signin.tmpl" ?
817 "$config{templatedir}/signin.tmpl" : "")
820 $form->field(name => "name", required => 0);
821 $form->field(name => "do", type => "hidden");
822 $form->field(name => "page", type => "hidden");
823 $form->field(name => "from", type => "hidden");
824 $form->field(name => "password", type => "password", required => 0);
825 $form->field(name => "confirm_password", type => "password", required => 0);
826 $form->field(name => "email", required => 0);
827 if ($q->param("do") ne "signin") {
828 $form->text("You need to log in before you can edit pages.");
831 if ($form->submitted) {
832 # Set required fields based on how form was submitted.
834 "Login" => [qw(name password)],
835 "Register" => [qw(name password confirm_password email)],
836 "Mail Password" => [qw(name)],
838 foreach my $opt (@{$required{$form->submitted}}) {
839 $form->field(name => $opt, required => 1);
842 # Validate password differently depending on how
843 # form was submitted.
844 if ($form->submitted eq 'Login') {
848 length $form->field("name") &&
849 shift eq userinfo_get($form->field("name"), 'password');
852 $form->field(name => "name", validate => '/^\w+$/');
855 $form->field(name => "password", validate => 'VALUE');
857 # And make sure the entered name exists when logging
858 # in or sending email, and does not when registering.
859 if ($form->submitted eq 'Register') {
865 ! userinfo_get($name, "regdate");
875 userinfo_get($name, "regdate");
881 # First time settings.
882 $form->field(name => "name", comment => "use FirstnameLastName");
883 $form->field(name => "confirm_password", comment => "(only needed");
884 $form->field(name => "email", comment => "for registration)");
885 if ($session->param("name")) {
886 $form->field(name => "name", value => $session->param("name"));
890 if ($form->submitted && $form->validate) {
891 if ($form->submitted eq 'Login') {
892 $session->param("name", $form->field("name"));
893 if (defined $form->field("do") &&
894 $form->field("do") ne 'signin') {
896 "$config{cgiurl}?do=".$form->field("do").
897 "&page=".$form->field("page").
898 "&from=".$form->field("from"));;
901 print $q->redirect($config{url});
904 elsif ($form->submitted eq 'Register') {
905 my $user_name=$form->field('name');
906 if (userinfo_set($user_name, {
907 'email' => $form->field('email'),
908 'password' => $form->field('password'),
911 $form->field(name => "confirm_password", type => "hidden");
912 $form->field(name => "email", type => "hidden");
913 $form->text("Registration successful. Now you can Login.");
914 print $session->header();
915 print misctemplate($form->title, $form->render(submit => ["Login"]));
918 error("Error saving registration.");
921 elsif ($form->submitted eq 'Mail Password') {
922 my $user_name=$form->field("name");
923 my $template=HTML::Template->new(
924 filename => "$config{templatedir}/passwordmail.tmpl"
927 user_name => $user_name,
928 user_password => userinfo_get($user_name, "password"),
929 wikiurl => $config{url},
930 wikiname => $config{wikiname},
931 REMOTE_ADDR => $ENV{REMOTE_ADDR},
934 eval q{use Mail::Sendmail};
935 my ($fromhost) = $config{cgiurl} =~ m!/([^/]+)!;
937 To => userinfo_get($user_name, "email"),
938 From => "$config{wikiname} admin <".(getpwuid($>))[0]."@".$fromhost.">",
939 Subject => "$config{wikiname} information",
940 Message => $template->output,
941 ) or error("Failed to send mail");
943 $form->text("Your password has been emailed to you.");
944 $form->field(name => "name", required => 0);
945 print $session->header();
946 print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"]));
950 print $session->header();
951 print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"]));
955 sub cgi_editpage ($$) { #{{{
959 eval q{use CGI::FormBuilder};
960 my $form = CGI::FormBuilder->new(
961 fields => [qw(do from page content comments)],
967 required => [qw{content}],
970 action => $q->request_uri,
972 template => "$config{templatedir}/editpage.tmpl"
975 my ($page)=$form->param('page')=~/$config{wiki_file_regexp}/;
976 if (! defined $page || ! length $page || $page ne $q->param('page') ||
977 $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
978 error("bad page name");
982 $form->field(name => "do", type => 'hidden');
983 $form->field(name => "from", type => 'hidden');
984 $form->field(name => "page", value => "$page", force => 1);
985 $form->field(name => "comments", type => "text", size => 80);
986 $form->field(name => "content", type => "textarea", rows => 20,
989 if ($form->submitted eq "Cancel") {
990 print $q->redirect("$config{url}/".htmlpage($page));
993 if (! $form->submitted || ! $form->validate) {
994 if ($form->field("do") eq "create") {
995 if (exists $pagesources{lc($page)}) {
996 # hmm, someone else made the page in the
998 print $q->redirect("$config{url}/".htmlpage($page));
1003 my ($from)=$form->param('from')=~/$config{wiki_file_regexp}/;
1004 if (! defined $from || ! length $from ||
1005 $from ne $form->param('from') ||
1006 $from=~/$config{wiki_file_prune_regexp}/ || $from=~/^\//) {
1012 push @page_locs, $dir.$page;
1013 push @page_locs, "$from/$page";
1014 while (length $dir) {
1016 push @page_locs, $dir.$page;
1020 $form->tmpl_param("page_select", 1);
1021 $form->field(name => "page", type => 'select',
1022 options => \@page_locs);
1023 $form->title("creating $page");
1025 elsif ($form->field("do") eq "edit") {
1027 if (exists $pagesources{lc($page)}) {
1028 $content=readfile("$config{srcdir}/$pagesources{lc($page)}");
1029 $content=~s/\n/\r\n/g;
1031 $form->tmpl_param("page_select", 0);
1032 $form->field(name => "content", value => $content,
1034 $form->field(name => "page", type => 'hidden');
1035 $form->title("editing $page");
1038 $form->tmpl_param("can_commit", $config{svn});
1039 $form->tmpl_param("indexlink", indexlink());
1040 print $form->render(submit => ["Save Page", "Cancel"]);
1044 my $file=$page.$config{default_pageext};
1046 if (exists $pagesources{lc($page)}) {
1047 $file=$pagesources{lc($page)};
1051 my $content=$form->field('content');
1052 $content=~s/\r\n/\n/g;
1053 $content=~s/\r/\n/g;
1054 writefile("$config{srcdir}/$file", $content);
1056 my $message="web commit ";
1057 if ($session->param("name")) {
1058 $message.="by ".$session->param("name");
1061 $message.="from $ENV{REMOTE_ADDR}";
1063 if (defined $form->field('comments') &&
1064 length $form->field('comments')) {
1065 $message.=": ".$form->field('comments');
1072 # presumably the commit will trigger an update
1074 rcs_commit($message);
1080 # The trailing question mark tries to avoid broken
1081 # caches and get the most recent version of the page.
1082 print $q->redirect("$config{url}/".htmlpage($page)."?updated");
1088 eval q{use CGI::Session};
1092 my $do=$q->param('do');
1093 if (! defined $do || ! length $do) {
1094 error("\"do\" parameter missing");
1097 # This does not need a session.
1098 if ($do eq 'recentchanges') {
1099 cgi_recentchanges($q);
1103 CGI::Session->name("ikiwiki_session");
1105 my $oldmask=umask(077);
1106 my $session = CGI::Session->new("driver:db_file", $q,
1107 { FileName => "$config{srcdir}/.ikiwiki/sessions.db" });
1110 # Everything below this point needs the user to be signed in.
1111 if ((! $config{anonok} && ! defined $session->param("name") ||
1112 ! userinfo_get($session->param("name"), "regdate")) || $do eq 'signin') {
1113 cgi_signin($q, $session);
1115 # Force session flush with safe umask.
1116 my $oldmask=umask(077);
1123 if ($do eq 'create' || $do eq 'edit') {
1124 cgi_editpage($q, $session);
1127 error("unknown do parameter");
1132 gen_wrapper() if $config{wrapper};
1133 memoize('pagename');
1134 memoize('bestlink');
1135 loadindex() unless $config{rebuild};
1140 rcs_update() if $config{svn};