X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/c861b8cae9f0b2a74b9f7b6f4344d1c9ed18496c..400bd79e8a6d6ae6c391b0e5ff0866e6c419aaec:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 61725ab84..b6a2a3649 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -22,12 +22,14 @@ our $VERSION = 1.01; # plugin interface version use Memoize; memoize("abs2rel"); memoize("pagespec_translate"); +memoize("file_pruned"); my $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE sub defaultconfig () { #{{{ - wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.x?html?$|\.rss$|\.atom$|.arch-ids/|{arch}/)}, + wiki_file_prune_regexps => [qr/\.\./, qr/^\./, qr/\/\./, qr/\.x?html?$/, + qr/(^|\/).svn\//, qr/.arch-ids\//, qr/{arch}\//], wiki_link_regexp => qr/\[\[(?:([^\]\|]+)\|)?([^\s\]]+)\]\]/, wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/, web_commit_regexp => qr/^web commit (by (.*?(?=: |$))|from (\d+\.\d+\.\d+\.\d+)):?(.*)/, @@ -36,7 +38,7 @@ sub defaultconfig () { #{{{ wikiname => "wiki", default_pageext => "mdwn", cgi => 0, - rcs => 'svn', + rcs => '', notify => 0, url => '', cgiurl => '', @@ -67,6 +69,7 @@ sub defaultconfig () { #{{{ locale => undef, sslcookie => 0, httpauth => 0, + userdir => "", } #}}} sub checkconfig () { #{{{ @@ -95,9 +98,6 @@ sub checkconfig () { #{{{ if ($config{cgi} && ! length $config{url}) { error("Must specify url to wiki with --url when using --cgi\n"); } - if (($config{rss} || $config{atom}) && ! length $config{url}) { - error("Must specify url to wiki with --url when using --rss or --atom\n"); - } $config{wikistatedir}="$config{srcdir}/.ikiwiki" unless exists $config{wikistatedir}; @@ -298,6 +298,11 @@ sub bestlink ($$) { #{{{ my $link=shift; my $cwd=$page; + if ($link=~s/^\/+//) { + # absolute links + $cwd=""; + } + do { my $l=$cwd; $l.="/" if length $l; @@ -321,10 +326,18 @@ sub isinlinableimage ($) { #{{{ $file=~/\.(png|gif|jpg|jpeg)$/i; } #}}} -sub pagetitle ($) { #{{{ +sub pagetitle ($;$) { #{{{ my $page=shift; - $page=~s/__(\d+)__/&#$1;/g; + my $unescaped=shift; + + if ($unescaped) { + $page=~s/__(\d+)__/chr($1)/eg; + } + else { + $page=~s/__(\d+)__/&#$1;/g; + } $page=~y/_/ /; + return $page; } #}}} @@ -354,7 +367,7 @@ sub baseurl (;$) { #{{{ sub abs2rel ($$) { #{{{ # Work around very innefficient behavior in File::Spec if abs2rel # is passed two relative paths. It's much faster if paths are - # absolute! (Debian bug #376658) + # absolute! (Debian bug #376658; fixed in debian unstable now) my $path="/".shift; my $base="/".shift; @@ -400,6 +413,7 @@ sub htmllink ($$$;$$$) { #{{{ $bestlink=htmlpage($bestlink); } if (! grep { $_ eq $bestlink } map { @{$_} } values %renderedfiles) { + return $linktext unless length $config{cgiurl}; return " "create", page => lc($link), from => $page). "\">?$linktext" @@ -779,6 +793,16 @@ sub add_depends ($$) { #{{{ } } # }}} +sub file_pruned ($$) { #{{{ + require File::Spec; + my $file=File::Spec->canonpath(shift); + my $base=File::Spec->canonpath(shift); + $file=~s#^\Q$base\E/*##; + + my $regexp='('.join('|', @{$config{wiki_file_prune_regexps}}).')'; + $file =~ m/$regexp/; +} #}}} + sub pagespec_match ($$) { #{{{ my $page=shift; my $spec=shift;