X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/d8819689b1f7ffe80164f223b38f071c0783cd38..9d0902a7503feb775e6b7a032641f0a970cd5ad1:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 5bb8ea1c9..b6e160ab6 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -12,15 +12,17 @@ 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}; +my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE + sub defaultconfig () { #{{{ wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.x?html?$|\.rss$)}, wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]]+)\]\]/, - wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]*)\]\]/, wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/, verbose => 0, + syslog => 0, wikiname => "wiki", default_pageext => "mdwn", cgi => 0, @@ -44,8 +46,8 @@ sub defaultconfig () { #{{{ srcdir => undef, destdir => undef, pingurl => [], - templatedir => "/usr/share/ikiwiki/templates", - underlaydir => "/usr/share/ikiwiki/basewiki", + templatedir => "$installdir/share/ikiwiki/templates", + underlaydir => "$installdir/share/ikiwiki/basewiki", setup => undef, adminuser => undef, adminemail => undef, @@ -119,12 +121,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 +259,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 +268,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"; @@ -282,14 +305,14 @@ sub cgiurl (@) { #{{{ return $config{cgiurl}."?".join("&", map "$_=$params{$_}", keys %params); } #}}} -sub styleurl (;$) { #{{{ +sub baseurl (;$) { #{{{ my $page=shift; - return "$config{url}/style.css" if ! defined $page; + return "$config{url}/" if ! defined $page; $page=~s/[^\/]+$//; $page=~s/[^\/]+\//..\//g; - return $page."style.css"; + return $page; } #}}} sub abs2rel ($$) { #{{{ @@ -323,7 +346,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 +357,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 +419,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]; } @@ -432,7 +457,10 @@ sub template_params (@) { #{{{ my $text_ref = shift; $$text_ref=&Encode::decode_utf8($$text_ref); }, - filename => "$config{templatedir}/$filename", @_; + filename => "$config{templatedir}/$filename", + loop_context_vars => 1, + die_on_bad_params => 0, + @_; } #}}} sub template ($;@) { #{{{ @@ -449,8 +477,7 @@ sub misctemplate ($$) { #{{{ indexlink => indexlink(), wikiname => $config{wikiname}, pagebody => $pagebody, - styleurl => styleurl(), - baseurl => "$config{url}/", + baseurl => baseurl(), ); return $template->output; }#}}} @@ -519,6 +546,8 @@ sub pagespec_merge ($$) { #{{{ my $a=shift; my $b=shift; + return $a if $a eq $b; + # Support for old-style GlobLists. if (is_globlist($a)) { $a=globlist_to_pagespec($a); @@ -585,7 +614,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) {