X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/710a8b2d8f5e014699c8c06caa5e3fe5ffd1e112..7bbfbf82fb17c05cc70ec042c1fdd4e0fb370b12:/ikiwiki diff --git a/ikiwiki b/ikiwiki index 729f8628b..bda2d0401 100755 --- a/ikiwiki +++ b/ikiwiki @@ -3,19 +3,15 @@ $ENV{PATH}="/usr/local/bin:/usr/bin:/bin"; use warnings; use strict; -use File::Find; use Memoize; use File::Spec; use HTML::Template; use Getopt::Long; -BEGIN { - $blosxom::version="is a proper perl module too much to ask?"; - do "/usr/bin/markdown"; -} my (%links, %oldlinks, %oldpagemtime, %renderedfiles, %pagesources); -my %config=( #{{{ +# Holds global config settings, also used by some modules. +our %config=( #{{{ wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)}, wiki_link_regexp => qr/\[\[([^\s]+)\]\]/, wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/, @@ -23,23 +19,27 @@ my %config=( #{{{ wikiname => "wiki", default_pageext => ".mdwn", cgi => 0, - url => "", - cgiurl => "", - historyurl => "", svn => 1, + url => '', + cgiurl => '', + historyurl => '', anonok => 0, rebuild => 0, - wrapper => 0, + wrapper => undef, + wrappermode => undef, srcdir => undef, destdir => undef, templatedir => undef, + setup => undef, ); #}}} GetOptions( #{{{ + "setup=s" => \$config{setup}, "wikiname=s" => \$config{wikiname}, "verbose|v!" => \$config{verbose}, "rebuild!" => \$config{rebuild}, - "wrapper!" => \$config{wrapper}, + "wrapper=s" => sub { $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap" }, + "wrappermode=i" => \$config{wrappermode}, "svn!" => \$config{svn}, "anonok!" => \$config{anonok}, "cgi!" => \$config{cgi}, @@ -51,13 +51,16 @@ GetOptions( #{{{ }, ) || usage(); -usage() unless @ARGV == 3; -$config{srcdir} = possibly_foolish_untaint(shift); -$config{templatedir} = possibly_foolish_untaint(shift); -$config{destdir} = possibly_foolish_untaint(shift); -if ($config{cgi} && ! length $config{url}) { - error("Must specify url to wiki with --url when using --cgi"); -} #}}} +if (! $config{setup}) { + usage() unless @ARGV == 3; + $config{srcdir} = possibly_foolish_untaint(shift); + $config{templatedir} = possibly_foolish_untaint(shift); + $config{destdir} = possibly_foolish_untaint(shift); + if ($config{cgi} && ! length $config{url}) { + error("Must specify url to wiki with --url when using --cgi"); + } +} +#}}} sub usage { #{{{ die "usage: ikiwiki [options] source templates dest\n"; @@ -67,11 +70,8 @@ sub error { #{{{ if ($config{cgi}) { print "Content-type: text/html\n\n"; print misctemplate("Error", "
Error: @_
"); - exit 1; - } - else { - die @_; } + die @_; } #}}} sub debug ($) { #{{{ @@ -166,14 +166,17 @@ sub writefile ($$) { #{{{ close OUT; } #}}} -sub findlinks ($) { #{{{ +sub findlinks ($$) { #{{{ my $content=shift; + my $page=shift; my @links; - while ($content =~ /$config{wiki_link_regexp}/g) { + while ($content =~ /(??$link" - } - else { - return "?$link" - } + return "?$link" } $bestlink=File::Spec->abs2rel($bestlink, dirname($page)); @@ -245,7 +249,9 @@ sub linkify ($$) { #{{{ my $content=shift; my $file=shift; - $content =~ s/$config{wiki_link_regexp}/htmllink(pagename($file), $1)/eg; + $content =~ s{(\\?)$config{wiki_link_regexp}}{ + $1 ? "[[$2]]" : htmllink(pagename($file), $2) + }eg; return $content; } #}}} @@ -254,6 +260,13 @@ sub htmlize ($$) { #{{{ my $type=shift; my $content=shift; + if (! $INC{"/usr/bin/markdown"}) { + no warnings 'once'; + $blosxom::version="is a proper perl module too much to ask?"; + use warnings 'all'; + do "/usr/bin/markdown"; + } + if ($type eq '.mdwn') { return Markdown::Markdown($content); } @@ -296,14 +309,14 @@ sub parentlinks ($) { #{{{ my $skip=1; foreach my $dir (reverse split("/", $page)) { if (! $skip) { + $path.="../"; unshift @ret, { url => "$path$dir.html", page => $dir }; } else { $skip=0; } - $path.="../"; } - unshift @ret, { url => $path , page => $config{wikiname} }; + unshift @ret, { url => length $path ? $path : ".", page => $config{wikiname} }; return @ret; } #}}} @@ -353,10 +366,10 @@ sub check_overwrite ($$) { #{{{ my $src=shift; if (! exists $renderedfiles{$src} && -e $dest && ! $config{rebuild}) { - error("$dest exists and was rendered from ". + error("$dest already exists and was rendered from ". join(" ",(grep { $renderedfiles{$_} eq $dest } keys %renderedfiles)). - ", not from $src before not overwriting"); + ", before, so not rendering from $src"); } } #}}} @@ -368,7 +381,7 @@ sub render ($) { #{{{ if ($type ne 'unknown') { my $page=pagename($file); - $links{$page}=[findlinks($content)]; + $links{$page}=[findlinks($content, $page)]; $content=linkify($content, $file); $content=htmlize($type, $content); @@ -388,6 +401,25 @@ sub render ($) { #{{{ } } #}}} +sub lockwiki () { #{{{ + # Take an exclusive lock on the wiki to prevent multiple concurrent + # run issues. The lock will be dropped on program exit. + if (! -d "$config{srcdir}/.ikiwiki") { + mkdir("$config{srcdir}/.ikiwiki"); + } + open(WIKILOCK, ">$config{srcdir}/.ikiwiki/lockfile") || error ("cannot write to lockfile: $!"); + if (! flock(WIKILOCK, 2 | 4)) { + debug("wiki seems to be locked, waiting for lock"); + my $wait=600; # arbitrary, but don't hang forever to + # prevent process pileup + for (1..600) { + return if flock(WIKILOCK, 2 | 4); + sleep 1; + } + error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)"); + } +} #}}} + sub loadindex () { #{{{ open (IN, "$config{srcdir}/.ikiwiki/index") || return; while (