X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/ed75653e4d1ebc9827601ab3649e1422f45ef338..f32369f66924e0c008370c29462af57fd218267a:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 88407584f..d4e19c388 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1,6 +1,7 @@ #!/usr/bin/perl package IkiWiki; + use warnings; use strict; use Encode; @@ -88,6 +89,7 @@ sub defaultconfig () { #{{{ account_creation_password => "", prefix_directives => 0, hardlink => 0, + cgi_disable_uploads => 1, } #}}} sub checkconfig () { #{{{ @@ -103,6 +105,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 $@; @@ -181,11 +189,6 @@ sub loadplugin ($) { #{{{ sub error ($;$) { #{{{ my $message=shift; my $cleaner=shift; - if ($config{cgi}) { - print "Content-type: text/html\n\n"; - print misctemplate(gettext("Error"), - "

".gettext("Error").": $message

"); - } log_message('err' => $message) if $config{syslog}; if (defined $cleaner) { $cleaner->(); @@ -329,7 +332,7 @@ sub readfile ($;$$) { #{{{ return $ret; } #}}} -sub prep_writefile ($$) { +sub prep_writefile ($$) { #{{{ my $file=shift; my $destdir=shift; @@ -353,7 +356,7 @@ sub prep_writefile ($$) { } return 1; -} +} #}}} sub writefile ($$$;$$) { #{{{ my $file=shift; # can include subdirs @@ -525,13 +528,18 @@ sub displaytime ($;$) { #{{{ return decode_utf8(POSIX::strftime($format, localtime($time))); } #}}} -sub beautify_url ($) { #{{{ +sub beautify_urlpath ($) { #{{{ my $url=shift; 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; } #}}} @@ -541,7 +549,7 @@ sub urlto ($$) { #{{{ my $from=shift; if (! length $to) { - return beautify_url(baseurl($from)); + return beautify_urlpath(baseurl($from)."index.$config{htmlext}"); } if (! $destsources{$to}) { @@ -550,7 +558,7 @@ sub urlto ($$) { #{{{ my $link = abs2rel($to, dirname(htmlpage($from))); - return beautify_url($link); + return beautify_urlpath($link); } #}}} sub htmllink ($$$;@) { #{{{ @@ -589,15 +597,15 @@ sub htmllink ($$$;@) { #{{{ return " "create", - page => pagetitle(lc($link), 1), + page => lc($link), from => $lpage ). - "\">?$linktext" + "\" rel=\"nofollow\">?$linktext" } } $bestlink=abs2rel($bestlink, dirname(htmlpage($page))); - $bestlink=beautify_url($bestlink); + $bestlink=beautify_urlpath($bestlink); if (! $opts{noimageinline} && isinlinableimage($bestlink)) { return "\"$linktext\""; @@ -635,8 +643,9 @@ sub userlink ($) { #{{{ } } #}}} -sub htmlize ($$$) { #{{{ +sub htmlize ($$$$) { #{{{ my $page=shift; + my $destpage=shift; my $type=shift; my $content=shift; @@ -655,6 +664,7 @@ sub htmlize ($$$) { #{{{ run_hooks(sanitize => sub { $content=shift->( page => $page, + destpage => $destpage, content => $content, ); }); @@ -686,7 +696,7 @@ sub linkify ($$$) { #{{{ return $content; } #}}} -my %preprocessing; +our %preprocessing; our $preprocess_preview=0; sub preprocess ($$$;$$) { #{{{ my $page=shift; # the page the data comes from @@ -1187,6 +1197,12 @@ sub gettext { #{{{ } } #}}} +sub yesno ($) { #{{{ + my $val=shift; + + return (defined $val && lc($val) eq gettext("yes")); +} #}}} + sub pagespec_merge ($$) { #{{{ my $a=shift; my $b=shift; @@ -1256,6 +1272,7 @@ sub pagespec_translate ($) { #{{{ $code=0; } + no warnings; return eval 'sub { my $page=shift; '.$code.' }'; } #}}} @@ -1270,7 +1287,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); } #}}} @@ -1280,6 +1297,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; @@ -1327,12 +1351,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"); }