X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/94eab28a86d518c39d8a71accee7b25818e38e63..66b92c6eb5fadc62c503a6925b86eff03632d640:/ikiwiki diff --git a/ikiwiki b/ikiwiki index 2815a8e1d..ce89112de 100755 --- a/ikiwiki +++ b/ikiwiki @@ -26,6 +26,7 @@ my $url=""; my $cgiurl=""; my $historyurl=""; my $svn=1; +my $anonok=0; sub usage { #{{{ die "usage: ikiwiki [options] source templates dest\n"; @@ -242,7 +243,7 @@ sub backlinks ($) { #{{{ return @links; } #}}} -sub parentlinks ($) { +sub parentlinks ($) { #{{{ my $page=shift; my @ret; @@ -259,7 +260,7 @@ sub parentlinks ($) { $path.="../"; } return @ret; -} +} #}}} sub indexlink () { #{{{ return "$wikiname/ "; @@ -406,7 +407,7 @@ sub rcs_recentchanges ($) { #{{{ my $div=qr/^--------------------+$/; my $infoline=qr/^r(\d+)\s+\|\s+([^\s]+)\s+\|\s+(\d+-\d+-\d+\s+\d+:\d+:\d+\s+[-+]?\d+).*/; my $state='start'; - my ($rev, $user, $when, @pages, $message); + my ($rev, $user, $when, @pages, @message); foreach (`LANG=C svn log -v '$svn_url'`) { chomp; if ($state eq 'start' && /$div/) { @@ -418,23 +419,24 @@ sub rcs_recentchanges ($) { #{{{ $when=concise(ago(time - str2time($3))); } elsif ($state eq 'header' && /^\s+[A-Z]\s+\Q$svn_base\E\/(.+)$/) { - push @pages, pagename($1) if length $1; + push @pages, { link => htmllink("", pagename($1), 1) } + if length $1; } elsif ($state eq 'header' && /^$/) { $state='body'; } elsif ($state eq 'body' && /$div/) { push @ret, { rev => $rev, user => $user, - when => $when, message => $message, + when => $when, message => [@message], pages => [@pages] } if @pages; return @ret if @ret >= $num; $state='header'; - $message=$rev=$user=$when=undef; - @pages=(); + $rev=$user=$when=undef; + @pages=@message=(); } elsif ($state eq 'body') { - $message.="$_
\n"; + push @message, {line => $_}, } } } @@ -588,7 +590,7 @@ sub gen_wrapper ($$) { #{{{ error("$this doesn't seem to be executable"); } - my @params=($srcdir, $destdir, "--wikiname=$wikiname"); + my @params=($srcdir, $templatedir, $destdir, "--wikiname=$wikiname"); push @params, "--verbose" if $verbose; push @params, "--rebuild" if $rebuild; push @params, "--nosvn" if !$svn; @@ -596,6 +598,7 @@ sub gen_wrapper ($$) { #{{{ push @params, "--url=$url" if $url; push @params, "--cgiurl=$cgiurl" if $cgiurl; push @params, "--historyurl=$historyurl" if $historyurl; + push @params, "--anonok" if $anonok; my $params=join(" ", @params); my $call=''; foreach my $p ($this, $this, @params) { @@ -658,26 +661,15 @@ EOF sub cgi_recentchanges ($) { #{{{ my $q=shift; - - - my $list="\n"; - - print $q->header, - $q->start_html("RecentChanges"), - $q->h1(indexlink()." RecentChanges"), - $list, - $q->end_form, - $q->end_html; + my $template=HTML::Template->new( + filename => "$templatedir/recentchanges.tmpl"); + $template->param( + title => "RecentChanges", + indexlink => $url, + wikiname => $wikiname, + changelog => [rcs_recentchanges(100)], + ); + print $q->header, $template->output; } #}}} sub cgi_signin ($$) { #{{{ @@ -701,6 +693,7 @@ sub cgi_signin ($$) { #{{{ javascript => 0, params => $q, action => $q->request_uri, + template => (-e "$templatedir/signin.tmpl" ? "$templatedir/signin.tmpl" : "") ); $form->sessionid($session->id); @@ -753,13 +746,14 @@ sub cgi_signin ($$) { #{{{ if ($form->submitted && $form->validate) { if ($form->submitted eq 'Login') { $session->param("name", $form->field("name")); - if (defined $form->field("do")) { - $q->redirect( + if (defined $form->field("do") && + $form->field("do") ne 'signin') { + print $q->redirect( "$cgiurl?do=".$form->field("do"). "&page=".$form->field("page")); } else { - $q->redirect($url); + print $q->redirect($url); } } elsif ($form->submitted eq 'Register') { @@ -785,24 +779,27 @@ sub cgi () { #{{{ eval q{use CGI::Session}; my $q=CGI->new; - # session id has to be _sessionid for CGI::FormBuilder to work. - # TODO: stop having the formbuilder emit cookies and change session - # id to something else. - CGI::Session->name("_sessionid"); - my $session = CGI::Session->new(undef, $q, - { Directory=> "$srcdir/.ikiwiki/sessions" }); my $do=$q->param('do'); if (! defined $do || ! length $do) { error("\"do\" parameter missing"); } + # This does not need a session. if ($do eq 'recentchanges') { cgi_recentchanges($q); return; } - if (! defined $session->param("name") || $do eq 'signin') { + # session id has to be _sessionid for CGI::FormBuilder to work. + # TODO: stop having the formbuilder emit cookies and change session + # id to something else. + CGI::Session->name("_sessionid"); + my $session = CGI::Session->new(undef, $q, + { Directory=> "$srcdir/.ikiwiki/sessions" }); + + # Everything below this point needs the user to be signed in. + if ((! $anonok && ! defined $session->param("name")) || $do eq 'signin') { cgi_signin($q, $session); return; } @@ -936,6 +933,7 @@ if (grep /^-/, @ARGV) { "rebuild" => \$rebuild, "wrapper" => \$wrapper, "svn!" => \$svn, + "anonok!" => \$anonok, "cgi" => \$cgi, "url=s" => \$url, "cgiurl=s" => \$cgiurl,