X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/99fce0af0d4e99bc81ef7847bfbe77662763e805..53b188ed35d24933b6440e4c3032ede829eba0ee:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 684713821..8af0d7889 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -87,6 +87,7 @@ sub defaultconfig () { #{{{ numbacklinks => 10, account_creation_password => "", prefix_directives => 0, + hardlink => 0, } #}}} sub checkconfig () { #{{{ @@ -102,6 +103,12 @@ sub checkconfig () { #{{{ } } + if (ref $config{ENV} eq 'HASH') { + foreach my $val (keys %{$config{ENV}}) { + $ENV{$val}=$config{ENV}{$val}; + } + } + if ($config{w3mmode}) { eval q{use Cwd q{abs_path}}; error($@) if $@; @@ -281,17 +288,22 @@ sub htmlpage ($) { #{{{ return targetpage($page, $config{htmlext}); } #}}} -sub srcfile ($) { #{{{ +sub srcfile_stat { #{{{ my $file=shift; + my $nothrow=shift; - return "$config{srcdir}/$file" if -e "$config{srcdir}/$file"; + return "$config{srcdir}/$file", stat(_) if -e "$config{srcdir}/$file"; foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) { - return "$dir/$file" if -e "$dir/$file"; + return "$dir/$file", stat(_) if -e "$dir/$file"; } - error("internal error: $file cannot be found in $config{srcdir} or underlay"); + error("internal error: $file cannot be found in $config{srcdir} or underlay") unless $nothrow; return; } #}}} +sub srcfile ($;$) { #{{{ + return (srcfile_stat(@_))[0]; +} #}}} + sub add_underlay ($) { #{{{ my $dir=shift; @@ -323,12 +335,9 @@ sub readfile ($;$$) { #{{{ return $ret; } #}}} -sub writefile ($$$;$$) { #{{{ - my $file=shift; # can include subdirs - my $destdir=shift; # directory to put file in - my $content=shift; - my $binary=shift; - my $writer=shift; +sub prep_writefile ($$) { + my $file=shift; + my $destdir=shift; my $test=$file; while (length $test) { @@ -337,12 +346,8 @@ sub writefile ($$$;$$) { #{{{ } $test=dirname($test); } - my $newfile="$destdir/$file.ikiwiki-new"; - if (-l $newfile) { - error("cannot write to a symlink ($newfile)"); - } - my $dir=dirname($newfile); + my $dir=dirname("$destdir/$file"); if (! -d $dir) { my $d=""; foreach my $s (split(m!/+!, $dir)) { @@ -353,6 +358,23 @@ sub writefile ($$$;$$) { #{{{ } } + return 1; +} + +sub writefile ($$$;$$) { #{{{ + my $file=shift; # can include subdirs + my $destdir=shift; # directory to put file in + my $content=shift; + my $binary=shift; + my $writer=shift; + + prep_writefile($file, $destdir); + + my $newfile="$destdir/$file.ikiwiki-new"; + if (-l $newfile) { + error("cannot write to a symlink ($newfile)"); + } + my $cleanup = sub { unlink($newfile) }; open (my $out, '>', $newfile) || error("failed to write $newfile: $!", $cleanup); binmode($out) if ($binary); @@ -576,7 +598,7 @@ sub htmllink ($$$;@) { #{{{ page => pagetitle(lc($link), 1), from => $lpage ). - "\">?$linktext" + "\" rel=\"nofollow\">?$linktext" } } @@ -610,6 +632,9 @@ sub userlink ($) { #{{{ return "$oiduser"; } else { + eval q{use CGI 'escapeHTML'}; + error($@) if $@; + return htmllink("", "", escapeHTML( length $config{userdir} ? $config{userdir}."/".$user : $user ), noimageinline => 1); @@ -1233,6 +1258,11 @@ sub pagespec_translate ($) { #{{{ } } + if (! length $code) { + $code=0; + } + + no warnings; return eval 'sub { my $page=shift; '.$code.' }'; } #}}} @@ -1247,7 +1277,7 @@ sub pagespec_match ($$;@) { #{{{ } my $sub=pagespec_translate($spec); - return IkiWiki::FailReason->new('syntax error') if $@; + return IkiWiki::FailReason->new("syntax error in pagespec \"$spec\"") if $@; return $sub->($page, @params); } #}}} @@ -1268,7 +1298,9 @@ use overload ( #{{{ ); #}}} sub new { #{{{ - return bless \$_[1], $_[0]; + my $class = shift; + my $value = shift; + return bless \$value, $class; } #}}} package IkiWiki::SuccessReason; @@ -1281,7 +1313,9 @@ use overload ( #{{{ ); #}}} sub new { #{{{ - return bless \$_[1], $_[0]; + my $class = shift; + my $value = shift; + return bless \$value, $class; }; #}}} package IkiWiki::PageSpec;