X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/0a95ac2144de8552eeebabd6467bf25969352240..98eb183cf78113e82b32f895a58008ed1c79a8fd:/ikiwiki diff --git a/ikiwiki b/ikiwiki index 44a7abaf4..f7ccaf743 100755 --- a/ikiwiki +++ b/ikiwiki @@ -18,7 +18,7 @@ sub usage () { #{{{ sub getconfig () { #{{{ if (! exists $ENV{WRAPPED_OPTIONS}) { %config=( - wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)}, + wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)}, wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/, wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]+)\]\]/, wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/, @@ -36,11 +36,13 @@ sub getconfig () { #{{{ rebuild => 0, refresh => 0, getctime => 0, + hyperestraier => 0, wrapper => undef, wrappermode => undef, srcdir => undef, destdir => undef, templatedir => "/usr/share/ikiwiki/templates", + underlaydir => "/usr/share/ikiwiki/basewiki", setup => undef, adminuser => undef, ); @@ -56,6 +58,7 @@ sub getconfig () { #{{{ "wrappermode=i" => \$config{wrappermode}, "svn!" => \$config{svn}, "anonok!" => \$config{anonok}, + "hyperestraier" => \$config{hyperestraier}, "rss!" => \$config{rss}, "cgi!" => \$config{cgi}, "url=s" => \$config{url}, @@ -71,6 +74,9 @@ sub getconfig () { #{{{ "templatedir=s" => sub { $config{templatedir}=possibly_foolish_untaint($_[1]) }, + "underlaydir=s" => sub { + $config{underlaydir}=possibly_foolish_untaint($_[1]) + }, "wrapper:s" => sub { $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap" }, @@ -98,6 +104,9 @@ sub checkconfig () { #{{{ if ($config{rss} && ! length $config{url}) { error("Must specify url to wiki with --url when using --rss\n"); } + if ($config{hyperestraier} && ! length $config{url}) { + error("Must specify --url when using --hyperestraier\n"); + } $config{wikistatedir}="$config{srcdir}/.ikiwiki" unless exists $config{wikistatedir}; @@ -176,6 +185,14 @@ sub htmlpage ($) { #{{{ return $page.".html"; } #}}} +sub srcfile ($) { #{{{ + my $file=shift; + + return "$config{srcdir}/$file" if -e "$config{srcdir}/$file"; + return "$config{underlaydir}/$file" if -e "$config{underlaydir}/$file"; + error("internal error: $file cannot be found"); +} #}}} + sub readfile ($) { #{{{ my $file=shift; @@ -190,15 +207,20 @@ sub readfile ($) { #{{{ return $ret; } #}}} -sub writefile ($$) { #{{{ - my $file=shift; +sub writefile ($$$) { #{{{ + my $file=shift; # can include subdirs + my $destdir=shift; # directory to put file in my $content=shift; - if (-l $file) { - error("cannot write to a symlink ($file)"); + my $test=$file; + while (length $test) { + if (-l "$destdir/$test") { + error("cannot write to a symlink ($test)"); + } + $test=dirname($test); } - my $dir=dirname($file); + my $dir=dirname("$destdir/$file"); if (! -d $dir) { my $d=""; foreach my $s (split(m!/+!, $dir)) { @@ -209,7 +231,7 @@ sub writefile ($$) { #{{{ } } - open (OUT, ">$file") || error("failed to write $file: $!"); + open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!"); print OUT $content; close OUT; } #}}} @@ -255,10 +277,26 @@ sub pagetitle ($) { #{{{ sub titlepage ($) { #{{{ my $title=shift; $title=~y/ /_/; - $title=~s/([^-A-Za-z0-9_:+\/])/"__".ord($1)."__"/eg; + $title=~s/([^-A-Za-z0-9_:+\/.])/"__".ord($1)."__"/eg; return $title; } #}}} +sub cgiurl (@) { #{{{ + my %params=@_; + + return $config{cgiurl}."?".join("&", map "$_=$params{$_}", keys %params); +} #}}} + +sub styleurl (;$) { #{{{ + my $page=shift; + + return "$config{url}/style.css" if ! defined $page; + + $page=~s/[^\/]+$//; + $page=~s/[^\/]+\//..\//g; + return $page."style.css"; +} #}}} + sub htmllink ($$;$$$) { #{{{ my $page=shift; my $link=shift; @@ -286,13 +324,15 @@ sub htmllink ($$;$$$) { #{{{ $bestlink=htmlpage($bestlink); } if (! grep { $_ eq $bestlink } values %renderedfiles) { - return "?$linktext" + return " "create", page => $link, from =>$page). + "\">?$linktext" } $bestlink=File::Spec->abs2rel($bestlink, dirname($page)); if (! $noimageinline && isinlinableimage($bestlink)) { - return ""; + return "\"$linktext\""; } return "$linktext"; } #}}} @@ -387,6 +427,8 @@ sub misctemplate ($$) { #{{{ indexlink => indexlink(), wikiname => $config{wikiname}, pagebody => $pagebody, + styleurl => styleurl(), + baseurl => "$config{url}/", ); return $template->output; }#}}}