X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/810a355308d276ef922ff4312bff0c7935676633..45388ed356a3e7b88632bbf0f245527f36c43710:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 4368870b8..063cef8e0 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -77,7 +77,8 @@ sub defaultconfig () { #{{{ adminuser => undef, adminemail => undef, plugin => [qw{mdwn link inline htmlscrubber passwordauth openid - signinedit lockedit conditional recentchanges}], + signinedit lockedit conditional recentchanges + parentlinks}], libdir => undef, timeformat => '%c', locale => undef, @@ -189,11 +190,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->(); @@ -337,7 +333,7 @@ sub readfile ($;$$) { #{{{ return $ret; } #}}} -sub prep_writefile ($$) { +sub prep_writefile ($$) { #{{{ my $file=shift; my $destdir=shift; @@ -361,7 +357,7 @@ sub prep_writefile ($$) { } return 1; -} +} #}}} sub writefile ($$$;$$) { #{{{ my $file=shift; # can include subdirs @@ -533,13 +529,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; } #}}} @@ -549,7 +550,7 @@ sub urlto ($$) { #{{{ my $from=shift; if (! length $to) { - return beautify_url(baseurl($from)."index.$config{htmlext}"); + return beautify_urlpath(baseurl($from)."index.$config{htmlext}"); } if (! $destsources{$to}) { @@ -558,7 +559,7 @@ sub urlto ($$) { #{{{ my $link = abs2rel($to, dirname(htmlpage($from))); - return beautify_url($link); + return beautify_urlpath($link); } #}}} sub htmllink ($$$;@) { #{{{ @@ -605,7 +606,7 @@ sub htmllink ($$$;@) { #{{{ } $bestlink=abs2rel($bestlink, dirname(htmlpage($page))); - $bestlink=beautify_url($bestlink); + $bestlink=beautify_urlpath($bestlink); if (! $opts{noimageinline} && isinlinableimage($bestlink)) { return "\"$linktext\""; @@ -768,21 +769,30 @@ sub preprocess ($$$;$$) { #{{{ } my $ret; if (! $scan) { - $ret=$hooks{preprocess}{$command}{call}->( - @params, - page => $page, - destpage => $destpage, - preview => $preprocess_preview, - ); + $ret=eval { + $hooks{preprocess}{$command}{call}->( + @params, + page => $page, + destpage => $destpage, + preview => $preprocess_preview, + ); + }; + if ($@) { + chomp $@; + $ret="[[!$command ". + gettext("Error").": $@"."]]"; + } } else { # use void context during scan pass - $hooks{preprocess}{$command}{call}->( - @params, - page => $page, - destpage => $destpage, - preview => $preprocess_preview, - ); + eval { + $hooks{preprocess}{$command}{call}->( + @params, + page => $page, + destpage => $destpage, + preview => $preprocess_preview, + ); + }; $ret=""; } $preprocessing{$page}--; @@ -816,7 +826,8 @@ sub preprocess ($$$;$$) { #{{{ *)? # 0 or more parameters \]\] # directive closed }sx; - } else { + } + else { $regex = qr{ (\\?) # 1: escape? \[\[(!?) # directive open; 2: optional prefix @@ -1197,6 +1208,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;