#!/usr/bin/perl
package IkiWiki;
+
use warnings;
use strict;
use Encode;
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,
account_creation_password => "",
prefix_directives => 0,
hardlink => 0,
+ cgi_disable_uploads => 1,
} #}}}
sub checkconfig () { #{{{
sub error ($;$) { #{{{
my $message=shift;
my $cleaner=shift;
- if ($config{cgi}) {
- print "Content-type: text/html\n\n";
- print misctemplate(gettext("Error"),
- "<p>".gettext("Error").": $message</p>");
- }
log_message('err' => $message) if $config{syslog};
if (defined $cleaner) {
$cleaner->();
return $ret;
} #}}}
-sub prep_writefile ($$) {
+sub prep_writefile ($$) { #{{{
my $file=shift;
my $destdir=shift;
}
return 1;
-}
+} #}}}
sub writefile ($$$;$$) { #{{{
my $file=shift; # can include subdirs
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;
} #}}}
-sub urlto ($$) { #{{{
+sub urlto ($$;$) { #{{{
my $to=shift;
my $from=shift;
-
+ my $absolute=shift;
+
if (! length $to) {
- return beautify_url(baseurl($from));
+ return beautify_urlpath(baseurl($from)."index.$config{htmlext}");
}
if (! $destsources{$to}) {
$to=htmlpage($to);
}
+ if ($absolute) {
+ return $config{url}.beautify_urlpath("/".$to);
+ }
+
my $link = abs2rel($to, dirname(htmlpage($from)));
- return beautify_url($link);
+ return beautify_urlpath($link);
} #}}}
sub htmllink ($$$;@) { #{{{
return "<span class=\"createlink\"><a href=\"".
cgiurl(
do => "create",
- page => pagetitle(lc($link), 1),
+ page => lc($link),
from => $lpage
).
"\" rel=\"nofollow\">?</a>$linktext</span>"
}
$bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
- $bestlink=beautify_url($bestlink);
+ $bestlink=beautify_urlpath($bestlink);
if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
return "<img src=\"$bestlink\" alt=\"$linktext\" />";
}
} #}}}
-sub htmlize ($$$) { #{{{
+sub htmlize ($$$$) { #{{{
my $page=shift;
+ my $destpage=shift;
my $type=shift;
my $content=shift;
run_hooks(sanitize => sub {
$content=shift->(
page => $page,
+ destpage => $destpage,
content => $content,
);
});
return $content;
} #}}}
-my %preprocessing;
+our %preprocessing;
our $preprocess_preview=0;
sub preprocess ($$$;$$) { #{{{
my $page=shift; # the page the data comes from
if ($preprocessing{$page}++ > 3) {
# Avoid loops of preprocessed pages preprocessing
# other pages that preprocess them, etc.
- #translators: The first parameter is a
- #translators: preprocessor directive name,
- #translators: the second a page name, the
- #translators: third a number.
- return "[[".sprintf(gettext("%s preprocessing loop detected on %s at depth %i"),
- $command, $page, $preprocessing{$page}).
- "]]";
+ return "[[!$command <span class=\"error\">".
+ sprintf(gettext("preprocessing loop detected on %s at depth %i"),
+ $page, $preprocessing{$page}).
+ "</span>]]";
}
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 <span class=\"error\">".
+ gettext("Error").": $@"."</span>]]";
+ }
}
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}--;
*)? # 0 or more parameters
\]\] # directive closed
}sx;
- } else {
+ }
+ else {
$regex = qr{
(\\?) # 1: escape?
\[\[(!?) # directive open; 2: optional prefix
}
} #}}}
+sub yesno ($) { #{{{
+ my $val=shift;
+
+ return (defined $val && lc($val) eq gettext("yes"));
+} #}}}
+
sub pagespec_merge ($$) { #{{{
my $a=shift;
my $b=shift;
my $sub=pagespec_translate($spec);
return ! $@;
} #}}}
+
+sub glob2re ($) { #{{{
+ my $re=quotemeta(shift);
+ $re=~s/\\\*/.*/g;
+ $re=~s/\\\?/./g;
+ return $re;
+} #}}}
package IkiWiki::FailReason;
$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");
}