X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/ffc0be87d7eca4de4dbc91d740d36b7b40bfa911..2ac1e80db3dbfa1e651bfeac4c13d0db1c3e12bc:/ikiwiki diff --git a/ikiwiki b/ikiwiki index c5ac7c0b8..f7ccaf743 100755 --- a/ikiwiki +++ b/ikiwiki @@ -18,8 +18,8 @@ sub usage () { #{{{ sub getconfig () { #{{{ if (! exists $ENV{WRAPPED_OPTIONS}) { %config=( - wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$)}, - wiki_link_regexp => qr/\[\[([^\s\]]+)\]\]/, + 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_.:\/+]+$)/, verbose => 0, @@ -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; } #}}} @@ -242,7 +264,7 @@ sub bestlink ($$) { #{{{ sub isinlinableimage ($) { #{{{ my $file=shift; - $file=~/\.(png|gif|jpg|jpeg)$/; + $file=~/\.(png|gif|jpg|jpeg)$/i; } #}}} sub pagetitle ($) { #{{{ @@ -252,11 +274,35 @@ sub pagetitle ($) { #{{{ return $page; } #}}} -sub htmllink ($$;$$) { #{{{ +sub titlepage ($) { #{{{ + my $title=shift; + $title=~y/ /_/; + $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; my $noimageinline=shift; # don't turn links into inline html images my $forcesubpage=shift; # force a link to a subpage + my $linktext=shift; # set to force the link text to something my $bestlink; if (! $forcesubpage) { @@ -266,7 +312,7 @@ sub htmllink ($$;$$) { #{{{ $bestlink="$page/".lc($link); } - my $linktext=pagetitle(basename($link)); + $linktext=pagetitle(basename($link)) unless defined $linktext; return $linktext if length $bestlink && $page eq $bestlink; @@ -278,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"; } #}}} @@ -379,6 +427,8 @@ sub misctemplate ($$) { #{{{ indexlink => indexlink(), wikiname => $config{wikiname}, pagebody => $pagebody, + styleurl => styleurl(), + baseurl => "$config{url}/", ); return $template->output; }#}}}