X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/f6bd81db15340bd1bfa69e98f377099036308b7b..e0577bc944bed4ae8ed8cb7df664a87ea4401d6b:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index d1b65cd51..5a05a0f73 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -88,6 +88,7 @@ sub defaultconfig () { #{{{ account_creation_password => "", prefix_directives => 0, hardlink => 0, + cgi_disable_uploads => 1, } #}}} sub checkconfig () { #{{{ @@ -103,6 +104,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 $@; @@ -282,17 +289,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; @@ -526,7 +538,12 @@ sub beautify_url ($) { #{{{ if ($config{usedirs}) { $url =~ s!/index.$config{htmlext}$!/!; } - $url =~ s!^$!./!; # Browsers don't like empty links... + + # Ensure url is not an empty link, and + # if it's relative, make that explicit to avoid colon confusion. + if ($url !~ /\//) { + $url="./$url"; + } return $url; } #}}} @@ -536,7 +553,7 @@ sub urlto ($$) { #{{{ my $from=shift; if (! length $to) { - return beautify_url(baseurl($from)); + return beautify_url(baseurl($from)."index.$config{htmlext}"); } if (! $destsources{$to}) { @@ -584,10 +601,10 @@ sub htmllink ($$$;@) { #{{{ return " "create", - page => pagetitle(lc($link), 1), + page => lc($link), from => $lpage ). - "\">?$linktext" + "\" rel=\"nofollow\">?$linktext" } } @@ -621,14 +638,18 @@ sub userlink ($) { #{{{ return "$oiduser"; } else { + eval q{use CGI 'escapeHTML'}; + error($@) if $@; + return htmllink("", "", escapeHTML( length $config{userdir} ? $config{userdir}."/".$user : $user ), noimageinline => 1); } } #}}} -sub htmlize ($$$) { #{{{ +sub htmlize ($$$$) { #{{{ my $page=shift; + my $destpage=shift; my $type=shift; my $content=shift; @@ -647,6 +668,7 @@ sub htmlize ($$$) { #{{{ run_hooks(sanitize => sub { $content=shift->( page => $page, + destpage => $destpage, content => $content, ); }); @@ -678,7 +700,7 @@ sub linkify ($$$) { #{{{ return $content; } #}}} -my %preprocessing; +our %preprocessing; our $preprocess_preview=0; sub preprocess ($$$;$$) { #{{{ my $page=shift; # the page the data comes from @@ -1244,6 +1266,11 @@ sub pagespec_translate ($) { #{{{ } } + if (! length $code) { + $code=0; + } + + no warnings; return eval 'sub { my $page=shift; '.$code.' }'; } #}}} @@ -1258,7 +1285,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,6 +1295,13 @@ sub pagespec_valid ($) { #{{{ my $sub=pagespec_translate($spec); return ! $@; } #}}} + +sub glob2re ($) { #{{{ + my $re=quotemeta(shift); + $re=~s/\\\*/.*/g; + $re=~s/\\\?/./g; + return $re; +} #}}} package IkiWiki::FailReason; @@ -1279,7 +1313,9 @@ use overload ( #{{{ ); #}}} sub new { #{{{ - return bless \$_[1], $_[0]; + my $class = shift; + my $value = shift; + return bless \$value, $class; } #}}} package IkiWiki::SuccessReason; @@ -1292,7 +1328,9 @@ use overload ( #{{{ ); #}}} sub new { #{{{ - return bless \$_[1], $_[0]; + my $class = shift; + my $value = shift; + return bless \$value, $class; }; #}}} package IkiWiki::PageSpec; @@ -1311,12 +1349,8 @@ sub match_glob ($$;@) { #{{{ $glob="$from/$glob" if length $from; } - # turn glob into safe regexp - $glob=quotemeta($glob); - $glob=~s/\\\*/.*/g; - $glob=~s/\\\?/./g; - - if ($page=~/^$glob$/i) { + my $regexp=IkiWiki::glob2re($glob); + if ($page=~/^$regexp$/i) { if (! IkiWiki::isinternal($page) || $params{internal}) { return IkiWiki::SuccessReason->new("$glob matches $page"); }