#!/usr/bin/perl
package IkiWiki;
+
use warnings;
use strict;
use Encode;
account_creation_password => "",
prefix_directives => 0,
hardlink => 0,
+ cgi_disable_uploads => 1,
} #}}}
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 $@;
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") unless $nothrow;
return;
} #}}}
+sub srcfile ($;$) { #{{{
+ return (srcfile_stat(@_))[0];
+} #}}}
+
sub add_underlay ($) { #{{{
my $dir=shift;
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;
} #}}}
my $from=shift;
if (! length $to) {
- return beautify_url(baseurl($from));
+ return beautify_urlpath(baseurl($from)."index.$config{htmlext}");
}
if (! $destsources{$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
).
- "\">?</a>$linktext</span>"
+ "\" 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
}
} #}}}
+sub yesno ($) { #{{{
+ my $val=shift;
+
+ return (defined $val && lc($val) eq gettext("yes"));
+} #}}}
+
sub pagespec_merge ($$) { #{{{
my $a=shift;
my $b=shift;
$code=0;
}
+ no warnings;
return eval 'sub { my $page=shift; '.$code.' }';
} #}}}
}
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);
} #}}}
my $sub=pagespec_translate($spec);
return ! $@;
} #}}}
+
+sub glob2re ($) { #{{{
+ my $re=quotemeta(shift);
+ $re=~s/\\\*/.*/g;
+ $re=~s/\\\?/./g;
+ return $re;
+} #}}}
package IkiWiki::FailReason;
); #}}}
sub new { #{{{
- return bless \$_[1], $_[0];
+ my $class = shift;
+ my $value = shift;
+ return bless \$value, $class;
} #}}}
package IkiWiki::SuccessReason;
); #}}}
sub new { #{{{
- return bless \$_[1], $_[0];
+ my $class = shift;
+ my $value = shift;
+ return bless \$value, $class;
}; #}}}
package IkiWiki::PageSpec;
$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");
}