X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/7b4600df3f8b8c2112a8df6c018d64f04db1ebe8..c4e0e8c36c89fa26e76bb21dbdb8263ee88d5143:/ikiwiki diff --git a/ikiwiki b/ikiwiki index 77c7744f9..f7ccaf743 100755 --- a/ikiwiki +++ b/ikiwiki @@ -18,10 +18,10 @@ 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_.\&;:\/+]+$)/, + wiki_file_regexp => qr/(^[-A-Za-z0-9_.:\/+]+$)/, verbose => 0, wikiname => "wiki", default_pageext => ".mdwn", @@ -34,11 +34,15 @@ sub getconfig () { #{{{ anonok => 0, rss => 0, 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, ); @@ -49,9 +53,12 @@ sub getconfig () { #{{{ "wikiname=s" => \$config{wikiname}, "verbose|v!" => \$config{verbose}, "rebuild!" => \$config{rebuild}, + "refresh!" => \$config{refresh}, + "getctime" => \$config{getctime}, "wrappermode=i" => \$config{wrappermode}, "svn!" => \$config{svn}, "anonok!" => \$config{anonok}, + "hyperestraier" => \$config{hyperestraier}, "rss!" => \$config{rss}, "cgi!" => \$config{cgi}, "url=s" => \$config{url}, @@ -67,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" }, @@ -94,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}; @@ -172,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; @@ -186,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)) { @@ -205,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; } #}}} @@ -238,7 +264,7 @@ sub bestlink ($$) { #{{{ sub isinlinableimage ($) { #{{{ my $file=shift; - $file=~/\.(png|gif|jpg|jpeg)$/; + $file=~/\.(png|gif|jpg|jpeg)$/i; } #}}} sub pagetitle ($) { #{{{ @@ -248,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) { @@ -262,7 +312,7 @@ sub htmllink ($$;$$) { #{{{ $bestlink="$page/".lc($link); } - my $linktext=pagetitle($link); + $linktext=pagetitle(basename($link)) unless defined $linktext; return $linktext if length $bestlink && $page eq $bestlink; @@ -274,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"; } #}}} @@ -375,6 +427,8 @@ sub misctemplate ($$) { #{{{ indexlink => indexlink(), wikiname => $config{wikiname}, pagebody => $pagebody, + styleurl => styleurl(), + baseurl => "$config{url}/", ); return $template->output; }#}}} @@ -466,7 +520,13 @@ sub globlist_match ($$) { #{{{ sub main () { #{{{ getconfig(); - if ($config{setup}) { + if ($config{cgi}) { + lockwiki(); + loadindex(); + require IkiWiki::CGI; + cgi(); + } + elsif ($config{setup}) { require IkiWiki::Setup; setup(); } @@ -475,17 +535,12 @@ sub main () { #{{{ require IkiWiki::Wrapper; gen_wrapper(); } - elsif ($config{cgi}) { - lockwiki(); - loadindex(); - require IkiWiki::CGI; - cgi(); - } else { lockwiki(); loadindex(); require IkiWiki::Render; rcs_update(); + rcs_getctime() if $config{getctime}; refresh(); saveindex(); }