2 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
11 my (%links, %oldlinks, %oldpagemtime, %renderedfiles, %pagesources);
14 wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)},
15 wiki_link_regexp => qr/\[\[([^\s]+)\]\]/,
16 wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/,
19 default_pageext => ".mdwn",
34 "wikiname=s" => \$config{wikiname},
35 "verbose|v!" => \$config{verbose},
36 "rebuild!" => \$config{rebuild},
37 "wrapper!" => \$config{wrapper},
38 "svn!" => \$config{svn},
39 "anonok!" => \$config{anonok},
40 "cgi!" => \$config{cgi},
41 "url=s" => \$config{url},
42 "cgiurl=s" => \$config{cgiurl},
43 "historyurl=s" => \$config{historyurl},
45 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
49 usage() unless @ARGV == 3;
50 $config{srcdir} = possibly_foolish_untaint(shift);
51 $config{templatedir} = possibly_foolish_untaint(shift);
52 $config{destdir} = possibly_foolish_untaint(shift);
53 if ($config{cgi} && ! length $config{url}) {
54 error("Must specify url to wiki with --url when using --cgi");
58 die "usage: ikiwiki [options] source templates dest\n";
63 print "Content-type: text/html\n\n";
64 print misctemplate("Error", "<p>Error: @_</p>");
73 return unless $config{verbose};
85 return (stat($page))[9];
88 sub possibly_foolish_untaint { #{{{
90 my ($untainted)=$tainted=~/(.*)/;
94 sub basename ($) { #{{{
101 sub dirname ($) { #{{{
108 sub pagetype ($) { #{{{
111 if ($page =~ /\.mdwn$/) {
119 sub pagename ($) { #{{{
122 my $type=pagetype($file);
124 $page=~s/\Q$type\E*$// unless $type eq 'unknown';
128 sub htmlpage ($) { #{{{
131 return $page.".html";
134 sub readfile ($) { #{{{
138 open (IN, "$file") || error("failed to read $file: $!");
144 sub writefile ($$) { #{{{
148 my $dir=dirname($file);
151 foreach my $s (split(m!/+!, $dir)) {
154 mkdir($d) || error("failed to create directory $d: $!");
159 open (OUT, ">$file") || error("failed to write $file: $!");
164 sub findlinks ($) { #{{{
168 while ($content =~ /$config{wiki_link_regexp}/g) {
174 sub bestlink ($$) { #{{{
175 # Given a page and the text of a link on the page, determine which
176 # existing page that link best points to. Prefers pages under a
177 # subdirectory with the same name as the source page, failing that
178 # goes down the directory tree to the base looking for matching
186 $l.="/" if length $l;
189 if (exists $links{$l}) {
190 #debug("for $page, \"$link\", use $l");
193 } while $cwd=~s!/?[^/]+$!!;
195 #print STDERR "warning: page $page, broken link: $link\n";
199 sub isinlinableimage ($) { #{{{
202 $file=~/\.(png|gif|jpg|jpeg)$/;
208 my $noimageinline=shift; # don't turn links into inline html images
209 my $createsubpage=shift; # force creation of a subpage if page DNE
211 my $bestlink=bestlink($page, $link);
213 return $link if length $bestlink && $page eq $bestlink;
215 # TODO BUG: %renderedfiles may not have it, if the linked to page
216 # was also added and isn't yet rendered! Note that this bug is
217 # masked by the bug mentioned below that makes all new files
219 if (! grep { $_ eq $bestlink } values %renderedfiles) {
220 $bestlink=htmlpage($bestlink);
222 if (! grep { $_ eq $bestlink } values %renderedfiles) {
223 if (! $createsubpage) {
224 return "<a href=\"$config{cgiurl}?do=create&page=$link&from=$page\">?</a>$link"
227 return "<a href=\"$config{cgiurl}?do=create&page=$page/$link\">?</a>$link"
231 $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
233 if (! $noimageinline && isinlinableimage($bestlink)) {
234 return "<img src=\"$bestlink\">";
236 return "<a href=\"$bestlink\">$link</a>";
239 sub linkify ($$) { #{{{
243 $content =~ s/$config{wiki_link_regexp}/htmllink(pagename($file), $1)/eg;
248 sub htmlize ($$) { #{{{
252 if (! $INC{"/usr/bin/markdown"}) {
254 $blosxom::version="is a proper perl module too much to ask?";
256 do "/usr/bin/markdown";
259 if ($type eq '.mdwn') {
260 return Markdown::Markdown($content);
263 error("htmlization of $type not supported");
267 sub backlinks ($) { #{{{
271 foreach my $p (keys %links) {
272 next if bestlink($page, $p) eq $page;
273 if (grep { length $_ && bestlink($p, $_) eq $page } @{$links{$p}}) {
274 my $href=File::Spec->abs2rel(htmlpage($p), dirname($page));
276 # Trim common dir prefixes from both pages.
278 my $page_trimmed=$page;
280 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
282 $p_trimmed=~s/^\Q$dir\E// &&
283 $page_trimmed=~s/^\Q$dir\E//;
285 push @links, { url => $href, page => $p_trimmed };
289 return sort { $a->{page} cmp $b->{page} } @links;
292 sub parentlinks ($) { #{{{
299 foreach my $dir (reverse split("/", $page)) {
301 unshift @ret, { url => "$path$dir.html", page => $dir };
308 unshift @ret, { url => $path , page => $config{wikiname} };
312 sub indexlink () { #{{{
313 return "<a href=\"$config{url}\">$config{wikiname}</a>";
316 sub finalize ($$) { #{{{
320 my $title=basename($page);
323 my $template=HTML::Template->new(blind_cache => 1,
324 filename => "$config{templatedir}/page.tmpl");
326 if (length $config{cgiurl}) {
327 $template->param(editurl => "$config{cgiurl}?do=edit&page=$page");
329 $template->param(recentchangesurl => "$config{cgiurl}?do=recentchanges");
333 if (length $config{historyurl}) {
334 my $u=$config{historyurl};
335 $u=~s/\[\[\]\]/$pagesources{$page}/g;
336 $template->param(historyurl => $u);
341 wikiname => $config{wikiname},
342 parentlinks => [parentlinks($page)],
344 backlinks => [backlinks($page)],
345 discussionlink => htmllink($page, "Discussion", 1, 1),
348 return $template->output;
351 sub check_overwrite ($$) { #{{{
352 # Important security check. Make sure to call this before saving
353 # any files to the source directory.
357 if (! exists $renderedfiles{$src} && -e $dest && ! $config{rebuild}) {
358 error("$dest exists and was rendered from ".
359 join(" ",(grep { $renderedfiles{$_} eq $dest } keys
361 ", not from $src before not overwriting");
365 sub render ($) { #{{{
368 my $type=pagetype($file);
369 my $content=readfile("$config{srcdir}/$file");
370 if ($type ne 'unknown') {
371 my $page=pagename($file);
373 $links{$page}=[findlinks($content)];
375 $content=linkify($content, $file);
376 $content=htmlize($type, $content);
377 $content=finalize($content, $page);
379 check_overwrite("$config{destdir}/".htmlpage($page), $page);
380 writefile("$config{destdir}/".htmlpage($page), $content);
381 $oldpagemtime{$page}=time;
382 $renderedfiles{$page}=htmlpage($page);
386 check_overwrite("$config{destdir}/$file", $file);
387 writefile("$config{destdir}/$file", $content);
388 $oldpagemtime{$file}=time;
389 $renderedfiles{$file}=$file;
393 sub loadindex () { #{{{
394 open (IN, "$config{srcdir}/.ikiwiki/index") || return;
396 $_=possibly_foolish_untaint($_);
398 my ($mtime, $file, $rendered, @links)=split(' ', $_);
399 my $page=pagename($file);
400 $pagesources{$page}=$file;
401 $oldpagemtime{$page}=$mtime;
402 $oldlinks{$page}=[@links];
403 $links{$page}=[@links];
404 $renderedfiles{$page}=$rendered;
409 sub saveindex () { #{{{
410 if (! -d "$config{srcdir}/.ikiwiki") {
411 mkdir("$config{srcdir}/.ikiwiki");
413 open (OUT, ">$config{srcdir}/.ikiwiki/index") || error("cannot write to index: $!");
414 foreach my $page (keys %oldpagemtime) {
415 print OUT "$oldpagemtime{$page} $pagesources{$page} $renderedfiles{$page} ".
416 join(" ", @{$links{$page}})."\n"
417 if $oldpagemtime{$page};
422 sub rcs_update () { #{{{
423 if (-d "$config{srcdir}/.svn") {
424 if (system("svn", "update", "--quiet", $config{srcdir}) != 0) {
425 warn("svn update failed\n");
430 sub rcs_commit ($) { #{{{
433 if (-d "$config{srcdir}/.svn") {
434 if (system("svn", "commit", "--quiet", "-m",
435 possibly_foolish_untaint($message),
436 $config{srcdir}) != 0) {
437 warn("svn commit failed\n");
442 sub rcs_add ($) { #{{{
445 if (-d "$config{srcdir}/.svn") {
446 my $parent=dirname($file);
447 while (! -d "$config{srcdir}/$parent/.svn") {
449 $parent=dirname($file);
452 if (system("svn", "add", "--quiet", "$config{srcdir}/$file") != 0) {
453 warn("svn add failed\n");
458 sub rcs_recentchanges ($) { #{{{
462 eval q{use Date::Parse};
463 eval q{use Time::Duration};
465 if (-d "$config{srcdir}/.svn") {
466 my $info=`LANG=C svn info $config{srcdir}`;
467 my ($svn_url)=$info=~/^URL: (.*)$/m;
469 # FIXME: currently assumes that the wiki is somewhere
470 # under trunk in svn, doesn't support other layouts.
471 my ($svn_base)=$svn_url=~m!(/trunk(?:/.*)?)$!;
473 my $div=qr/^--------------------+$/;
474 my $infoline=qr/^r(\d+)\s+\|\s+([^\s]+)\s+\|\s+(\d+-\d+-\d+\s+\d+:\d+:\d+\s+[-+]?\d+).*/;
476 my ($rev, $user, $when, @pages, @message);
477 foreach (`LANG=C svn log -v '$svn_url'`) {
479 if ($state eq 'start' && /$div/) {
482 elsif ($state eq 'header' && /$infoline/) {
485 $when=concise(ago(time - str2time($3)));
487 elsif ($state eq 'header' && /^\s+[A-Z]\s+\Q$svn_base\E\/(.+)$/) {
488 push @pages, { link => htmllink("", pagename($1), 1) }
491 elsif ($state eq 'header' && /^$/) {
494 elsif ($state eq 'body' && /$div/) {
495 my $committype="web";
496 if (defined $message[0] &&
497 $message[0]->{line}=~/^web commit by (\w+):?(.*)/) {
499 $message[0]->{line}=$2;
505 push @ret, { rev => $rev,
506 user => htmllink("", $user, 1),
507 committype => $committype,
508 when => $when, message => [@message],
509 pages => [@pages] } if @pages;
510 return @ret if @ret >= $num;
513 $rev=$user=$when=undef;
516 elsif ($state eq 'body') {
517 push @message, {line => $_},
529 my $dir=dirname($file);
530 while (rmdir($dir)) {
535 sub refresh () { #{{{
536 # Find existing pages.
540 eval q{use File::Find};
544 if (/$config{wiki_file_prune_regexp}/) {
546 $File::Find::prune=1;
550 my ($f)=/$config{wiki_file_regexp}/; # untaint
552 warn("skipping bad filename $_\n");
555 $f=~s/^\Q$config{srcdir}\E\/?//;
557 $exists{pagename($f)}=1;
565 # check for added or removed pages
567 foreach my $file (@files) {
568 my $page=pagename($file);
569 if (! $oldpagemtime{$page}) {
570 debug("new page $page");
573 $pagesources{$page}=$file;
577 foreach my $page (keys %oldpagemtime) {
578 if (! $exists{$page}) {
579 debug("removing old page $page");
580 push @del, $renderedfiles{$page};
581 prune($config{destdir}."/".$renderedfiles{$page});
582 delete $renderedfiles{$page};
583 $oldpagemtime{$page}=0;
584 delete $pagesources{$page};
588 # render any updated files
589 foreach my $file (@files) {
590 my $page=pagename($file);
592 if (! exists $oldpagemtime{$page} ||
593 mtime("$config{srcdir}/$file") > $oldpagemtime{$page}) {
594 debug("rendering changed file $file");
600 # if any files were added or removed, check to see if each page
601 # needs an update due to linking to them
602 # TODO: inefficient; pages may get rendered above and again here;
603 # problem is the bestlink may have changed and we won't know until
606 FILE: foreach my $file (@files) {
607 my $page=pagename($file);
608 foreach my $f (@add, @del) {
610 foreach my $link (@{$links{$page}}) {
611 if (bestlink($page, $link) eq $p) {
612 debug("rendering $file, which links to $p");
622 # handle backlinks; if a page has added/removed links, update the
624 # TODO: inefficient; pages may get rendered above and again here;
625 # problem is the backlinks could be wrong in the first pass render
629 foreach my $file (keys %rendered, @del) {
630 my $page=pagename($file);
631 if (exists $links{$page}) {
632 foreach my $link (@{$links{$page}}) {
633 $link=bestlink($page, $link);
635 ! exists $oldlinks{$page} ||
636 ! grep { $_ eq $link } @{$oldlinks{$page}}) {
637 $linkchanged{$link}=1;
641 if (exists $oldlinks{$page}) {
642 foreach my $link (@{$oldlinks{$page}}) {
643 $link=bestlink($page, $link);
645 ! exists $links{$page} ||
646 ! grep { $_ eq $link } @{$links{$page}}) {
647 $linkchanged{$link}=1;
652 foreach my $link (keys %linkchanged) {
653 my $linkfile=$pagesources{$link};
654 if (defined $linkfile) {
655 debug("rendering $linkfile, to update its backlinks");
662 sub gen_wrapper () { #{{{
663 eval q{use Cwd 'abs_path'};
664 $config{srcdir}=abs_path($config{srcdir});
665 $config{destdir}=abs_path($config{destdir});
666 my $this=abs_path($0);
668 error("$this doesn't seem to be executable");
671 my @params=($config{srcdir}, $config{templatedir}, $config{destdir},
672 "--wikiname=$config{wikiname}");
673 push @params, "--verbose" if $config{verbose};
674 push @params, "--rebuild" if $config{rebuild};
675 push @params, "--nosvn" if !$config{svn};
676 push @params, "--cgi" if $config{cgi};
677 push @params, "--url=$config{url}" if length $config{url};
678 push @params, "--cgiurl=$config{cgiurl}" if length $config{cgiurl};
679 push @params, "--historyurl=$config{historyurl}" if length $config{historyurl};
680 push @params, "--anonok" if $config{anonok};
681 my $params=join(" ", map { "\'$_\'" } @params);
683 foreach my $p ($this, $this, @params) {
689 push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
690 CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE
691 HTTP_COOKIE} if $config{cgi};
693 foreach my $var (@envsave) {
695 if ((s=getenv("$var")))
696 asprintf(&newenviron[i++], "%s=%s", "$var", s);
700 open(OUT, ">ikiwiki-wrap.c") || error("failed to write ikiwiki-wrap.c: $!");;
702 /* A wrapper for ikiwiki, can be safely made suid. */
709 extern char **environ;
711 int main (int argc, char **argv) {
712 /* Sanitize environment. */
714 char *newenviron[$#envsave+3];
717 newenviron[i++]="HOME=$ENV{HOME}";
721 if (argc == 2 && strcmp(argv[1], "--params") == 0) {
722 printf("$params\\n");
727 perror("failed to run $this");
732 if (system("gcc", "ikiwiki-wrap.c", "-o", "ikiwiki-wrap") != 0) {
733 error("failed to compile ikiwiki-wrap.c");
735 unlink("ikiwiki-wrap.c");
736 print "successfully generated ikiwiki-wrap\n";
740 sub misctemplate ($$) { #{{{
744 my $template=HTML::Template->new(
745 filename => "$config{templatedir}/misc.tmpl"
749 indexlink => indexlink(),
750 wikiname => $config{wikiname},
751 pagebody => $pagebody,
753 return $template->output;
756 sub cgi_recentchanges ($) { #{{{
759 my $template=HTML::Template->new(
760 filename => "$config{templatedir}/recentchanges.tmpl"
763 title => "RecentChanges",
764 indexlink => indexlink(),
765 wikiname => $config{wikiname},
766 changelog => [rcs_recentchanges(100)],
768 print $q->header, $template->output;
771 sub userinfo_get ($$) { #{{{
775 eval q{use Storable};
776 my $userdata=eval{ Storable::lock_retrieve("$config{srcdir}/.ikiwiki/userdb") };
777 if (! defined $userdata || ! ref $userdata ||
778 ! exists $userdata->{$user} || ! ref $userdata->{$user}) {
781 return $userdata->{$user}->{$field};
784 sub userinfo_set ($$) { #{{{
788 eval q{use Storable};
789 my $userdata=eval{ Storable::lock_retrieve("$config{srcdir}/.ikiwiki/userdb") };
790 if (! defined $userdata || ! ref $userdata) {
793 $userdata->{$user}=$info;
794 my $oldmask=umask(077);
795 my $ret=Storable::lock_store($userdata, "$config{srcdir}/.ikiwiki/userdb");
800 sub cgi_signin ($$) { #{{{
804 eval q{use CGI::FormBuilder};
805 my $form = CGI::FormBuilder->new(
806 title => "$config{wikiname} signin",
807 fields => [qw(do page from name password confirm_password email)],
811 confirm_password => {
812 perl => q{eq $form->field("password")},
819 action => $q->request_uri,
821 template => (-e "$config{templatedir}/signin.tmpl" ?
822 "$config{templatedir}/signin.tmpl" : "")
825 $form->field(name => "name", required => 0);
826 $form->field(name => "do", type => "hidden");
827 $form->field(name => "page", type => "hidden");
828 $form->field(name => "from", type => "hidden");
829 $form->field(name => "password", type => "password", required => 0);
830 $form->field(name => "confirm_password", type => "password", required => 0);
831 $form->field(name => "email", required => 0);
832 if ($q->param("do") ne "signin") {
833 $form->text("You need to log in before you can edit pages.");
836 if ($form->submitted) {
837 # Set required fields based on how form was submitted.
839 "Login" => [qw(name password)],
840 "Register" => [qw(name password confirm_password email)],
841 "Mail Password" => [qw(name)],
843 foreach my $opt (@{$required{$form->submitted}}) {
844 $form->field(name => $opt, required => 1);
847 # Validate password differently depending on how
848 # form was submitted.
849 if ($form->submitted eq 'Login') {
853 length $form->field("name") &&
854 shift eq userinfo_get($form->field("name"), 'password');
857 $form->field(name => "name", validate => '/^\w+$/');
860 $form->field(name => "password", validate => 'VALUE');
862 # And make sure the entered name exists when logging
863 # in or sending email, and does not when registering.
864 if ($form->submitted eq 'Register') {
870 ! userinfo_get($name, "regdate");
880 userinfo_get($name, "regdate");
886 # First time settings.
887 $form->field(name => "name", comment => "use FirstnameLastName");
888 $form->field(name => "confirm_password", comment => "(only needed");
889 $form->field(name => "email", comment => "for registration)");
890 if ($session->param("name")) {
891 $form->field(name => "name", value => $session->param("name"));
895 if ($form->submitted && $form->validate) {
896 if ($form->submitted eq 'Login') {
897 $session->param("name", $form->field("name"));
898 if (defined $form->field("do") &&
899 $form->field("do") ne 'signin') {
901 "$config{cgiurl}?do=".$form->field("do").
902 "&page=".$form->field("page").
903 "&from=".$form->field("from"));;
906 print $q->redirect($config{url});
909 elsif ($form->submitted eq 'Register') {
910 my $user_name=$form->field('name');
911 if (userinfo_set($user_name, {
912 'email' => $form->field('email'),
913 'password' => $form->field('password'),
916 $form->field(name => "confirm_password", type => "hidden");
917 $form->field(name => "email", type => "hidden");
918 $form->text("Registration successful. Now you can Login.");
919 print $session->header();
920 print misctemplate($form->title, $form->render(submit => ["Login"]));
923 error("Error saving registration.");
926 elsif ($form->submitted eq 'Mail Password') {
927 my $user_name=$form->field("name");
928 my $template=HTML::Template->new(
929 filename => "$config{templatedir}/passwordmail.tmpl"
932 user_name => $user_name,
933 user_password => userinfo_get($user_name, "password"),
934 wikiurl => $config{url},
935 wikiname => $config{wikiname},
936 REMOTE_ADDR => $ENV{REMOTE_ADDR},
939 eval q{use Mail::Sendmail};
940 my ($fromhost) = $config{cgiurl} =~ m!/([^/]+)!;
942 To => userinfo_get($user_name, "email"),
943 From => "$config{wikiname} admin <".(getpwuid($>))[0]."@".$fromhost.">",
944 Subject => "$config{wikiname} information",
945 Message => $template->output,
946 ) or error("Failed to send mail");
948 $form->text("Your password has been emailed to you.");
949 $form->field(name => "name", required => 0);
950 print $session->header();
951 print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"]));
955 print $session->header();
956 print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"]));
960 sub cgi_editpage ($$) { #{{{
964 eval q{use CGI::FormBuilder};
965 my $form = CGI::FormBuilder->new(
966 fields => [qw(do from page content comments)],
972 required => [qw{content}],
975 action => $q->request_uri,
977 template => "$config{templatedir}/editpage.tmpl"
980 my ($page)=$form->param('page')=~/$config{wiki_file_regexp}/;
981 if (! defined $page || ! length $page || $page ne $q->param('page') ||
982 $page=~/$config{wiki_file_prune_regexp}/ || $page=~/^\//) {
983 error("bad page name");
987 $form->field(name => "do", type => 'hidden');
988 $form->field(name => "from", type => 'hidden');
989 $form->field(name => "page", value => "$page", force => 1);
990 $form->field(name => "comments", type => "text", size => 80);
991 $form->field(name => "content", type => "textarea", rows => 20,
994 if ($form->submitted eq "Cancel") {
995 print $q->redirect("$config{url}/".htmlpage($page));
998 if (! $form->submitted || ! $form->validate) {
999 if ($form->field("do") eq "create") {
1000 if (exists $pagesources{lc($page)}) {
1001 # hmm, someone else made the page in the
1003 print $q->redirect("$config{url}/".htmlpage($page));
1008 my ($from)=$form->param('from')=~/$config{wiki_file_regexp}/;
1009 if (! defined $from || ! length $from ||
1010 $from ne $form->param('from') ||
1011 $from=~/$config{wiki_file_prune_regexp}/ || $from=~/^\//) {
1017 push @page_locs, $dir.$page;
1018 push @page_locs, "$from/$page";
1019 while (length $dir) {
1021 push @page_locs, $dir.$page;
1025 $form->tmpl_param("page_select", 1);
1026 $form->field(name => "page", type => 'select',
1027 options => \@page_locs);
1028 $form->title("creating $page");
1030 elsif ($form->field("do") eq "edit") {
1032 if (exists $pagesources{lc($page)}) {
1033 $content=readfile("$config{srcdir}/$pagesources{lc($page)}");
1034 $content=~s/\n/\r\n/g;
1036 $form->tmpl_param("page_select", 0);
1037 $form->field(name => "content", value => $content,
1039 $form->field(name => "page", type => 'hidden');
1040 $form->title("editing $page");
1043 $form->tmpl_param("can_commit", $config{svn});
1044 $form->tmpl_param("indexlink", indexlink());
1045 print $form->render(submit => ["Save Page", "Cancel"]);
1049 my $file=$page.$config{default_pageext};
1051 if (exists $pagesources{lc($page)}) {
1052 $file=$pagesources{lc($page)};
1056 my $content=$form->field('content');
1057 $content=~s/\r\n/\n/g;
1058 $content=~s/\r/\n/g;
1059 writefile("$config{srcdir}/$file", $content);
1061 my $message="web commit ";
1062 if ($session->param("name")) {
1063 $message.="by ".$session->param("name");
1066 $message.="from $ENV{REMOTE_ADDR}";
1068 if (defined $form->field('comments') &&
1069 length $form->field('comments')) {
1070 $message.=": ".$form->field('comments');
1077 # presumably the commit will trigger an update
1079 rcs_commit($message);
1085 # The trailing question mark tries to avoid broken
1086 # caches and get the most recent version of the page.
1087 print $q->redirect("$config{url}/".htmlpage($page)."?updated");
1093 eval q{use CGI::Session};
1097 my $do=$q->param('do');
1098 if (! defined $do || ! length $do) {
1099 error("\"do\" parameter missing");
1102 # This does not need a session.
1103 if ($do eq 'recentchanges') {
1104 cgi_recentchanges($q);
1108 CGI::Session->name("ikiwiki_session");
1110 my $oldmask=umask(077);
1111 my $session = CGI::Session->new("driver:db_file", $q,
1112 { FileName => "$config{srcdir}/.ikiwiki/sessions.db" });
1115 # Everything below this point needs the user to be signed in.
1116 if ((! $config{anonok} && ! defined $session->param("name") ||
1117 ! userinfo_get($session->param("name"), "regdate")) || $do eq 'signin') {
1118 cgi_signin($q, $session);
1120 # Force session flush with safe umask.
1121 my $oldmask=umask(077);
1128 if ($do eq 'create' || $do eq 'edit') {
1129 cgi_editpage($q, $session);
1132 error("unknown do parameter");
1137 gen_wrapper() if $config{wrapper};
1138 memoize('pagename');
1139 memoize('bestlink');
1140 loadindex() unless $config{rebuild};
1145 rcs_update() if $config{svn};