X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/7a05087f475e897560c34a614108dae50ba05c62..ad07eebb0b4afe4af8170dedefb9b782f3ab2d98:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 0907df6a1..4e3011918 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -12,7 +12,7 @@ use Memoize; memoize("abs2rel"); memoize("pagespec_translate"); -use vars qw{%config %links %oldlinks %oldpagemtime %pagectime +use vars qw{%config %links %oldlinks %oldpagemtime %pagectime %pagecase %renderedfiles %pagesources %depends %hooks %forcerebuild}; sub defaultconfig () { #{{{ @@ -21,6 +21,7 @@ sub defaultconfig () { #{{{ wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]*)\]\]/, wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/, verbose => 0, + syslog => 0, wikiname => "wiki", default_pageext => "mdwn", cgi => 0, @@ -119,12 +120,31 @@ sub error ($) { #{{{ print "Content-type: text/html\n\n"; print misctemplate("Error", "

Error: @_

"); } - die @_; + log_message(error => @_); + exit(1); } #}}} sub debug ($) { #{{{ return unless $config{verbose}; - if (! $config{cgi}) { + log_message(debug => @_); +} #}}} + +my $log_open=0; +sub log_message ($$) { #{{{ + my $type=shift; + + if ($config{syslog}) { + require Sys::Syslog; + unless ($log_open) { + Sys::Syslog::setlogsock('unix'); + Sys::Syslog::openlog('ikiwiki', '', 'user'); + $log_open=1; + } + eval { + Sys::Syslog::syslog($type, join(" ", @_)); + } + } + elsif (! $config{cgi}) { print "@_\n"; } else { @@ -238,7 +258,7 @@ sub bestlink ($$) { #{{{ # goes down the directory tree to the base looking for matching # pages. my $page=shift; - my $link=lc(shift); + my $link=shift; my $cwd=$page; do { @@ -247,9 +267,11 @@ sub bestlink ($$) { #{{{ $l.=$link; if (exists $links{$l}) { - #debug("for $page, \"$link\", use $l"); return $l; } + elsif (exists $pagecase{lc $l}) { + return $pagecase{lc $l}; + } } while $cwd=~s!/?[^/]+$!!; #print STDERR "warning: page $page, broken link: $link\n"; @@ -323,7 +345,8 @@ sub htmllink ($$$;$$$) { #{{{ $linktext=pagetitle(basename($link)) unless defined $linktext; - return $linktext if length $bestlink && $page eq $bestlink; + return "$linktext" + if length $bestlink && $page eq $bestlink; # TODO BUG: %renderedfiles may not have it, if the linked to page # was also added and isn't yet rendered! Note that this bug is @@ -333,7 +356,7 @@ sub htmllink ($$$;$$$) { #{{{ } if (! grep { $_ eq $bestlink } values %renderedfiles) { return " "create", page => $link, from => $page). + cgiurl(do => "create", page => lc($link), from => $page). "\">?$linktext" } @@ -395,6 +418,7 @@ sub loadindex () { #{{{ $links{$page}=[@{$items{link}}]; $depends{$page}=$items{depends}[0] if exists $items{depends}; $renderedfiles{$page}=$items{dest}[0]; + $pagecase{lc $page}=$page; } $pagectime{$page}=$items{ctime}[0]; } @@ -434,6 +458,7 @@ sub template_params (@) { #{{{ }, filename => "$config{templatedir}/$filename", loop_context_vars => 1, + die_on_bad_params => 0, @_; } #}}} @@ -587,7 +612,7 @@ sub match_glob ($$) { #{{{ sub match_link ($$) { #{{{ my $page=shift; - my $link=shift; + my $link=lc(shift); my $links = $links{$page} or return undef; foreach my $p (@$links) {