use warnings;
use strict;
use Encode;
-use HTML::Entities;
use URI::Escape q{uri_escape_utf8};
use POSIX ();
use Storable;
use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
%pagestate %wikistate %renderedfiles %oldrenderedfiles
- %pagesources %destsources %depends %depends_simple %hooks
- %forcerebuild %loaded_plugins %typedlinks %oldtypedlinks
+ %pagesources %destsources %depends %depends_simple @mass_depends
+ %hooks %forcerebuild %loaded_plugins %typedlinks %oldtypedlinks
%autofiles};
use Exporter q{import};
templatedir => {
type => "string",
default => "$installdir/share/ikiwiki/templates",
- description => "location of template files",
+ description => "additional directory to search for template files",
advanced => 1,
safe => 0, # path
rebuild => 1,
safe => 1,
rebuild => 1,
},
+ html5 => {
+ type => "boolean",
+ default => 0,
+ description => "generate HTML5? (experimental)",
+ advanced => 1,
+ safe => 1,
+ rebuild => 1,
+ },
sslcookie => {
type => "boolean",
default => 0,
return $ret;
}
-sub displaytime ($;$) {
+sub displaytime ($;$$) {
# Plugins can override this function to mark up the time to
# display.
- return '<span class="date">'.formattime(@_).'</span>';
+ my $time=formattime($_[0], $_[1]);
+ if ($config{html5}) {
+ return '<time datetime="'.date_3339($_[0]).'"'.
+ ($_[2] ? ' pubdate' : '').
+ '>'.$time.'</time>';
+ }
+ else {
+ return '<span class="date">'.$time.'</span>';
+ }
}
sub formattime ($;$) {
return decode_utf8(POSIX::strftime($format, localtime($time)));
}
+sub date_3339 ($) {
+ my $time=shift;
+
+ my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
+ POSIX::setlocale(&POSIX::LC_TIME, "C");
+ my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", gmtime($time));
+ POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
+ return $ret;
+}
+
sub beautify_urlpath ($) {
my $url=shift;
return $content;
}
-sub indexlink () {
- return "<a href=\"$config{url}\">$config{wikiname}</a>";
-}
-
sub check_canedit ($$$;$) {
my $page=shift;
my $q=shift;
my $d=$pages->{$src};
my $page=pagename($src);
$pagectime{$page}=$d->{ctime};
+ $pagesources{$page}=$src;
if (! $config{rebuild}) {
- $pagesources{$page}=$src;
$pagemtime{$page}=$d->{mtime};
$renderedfiles{$page}=$d->{dest};
if (exists $d->{links} && ref $d->{links}) {
sub template_file ($) {
my $name=shift;
- my $tpage=($name =~ /^\//) ? $name : "templates/$name";
+ my $tpage=($name =~ s/^\///) ? $name : "templates/$name";
if ($name !~ /\.tmpl$/ && exists $pagesources{$tpage}) {
$tpage=$pagesources{$tpage};
$name.=".tmpl";
my $template=srcfile($tpage, 1);
if (defined $template) {
- return $template, $tpage if wantarray;
+ return $template, $tpage, 1 if wantarray;
return $template;
}
-
- $name=~s:/::; # avoid path traversal
-
- foreach my $dir ($config{templatedir},
- "$installdir/share/ikiwiki/templates") {
- return "$dir/$name" if -e "$dir/$name";
+ else {
+ $name=~s:/::; # avoid path traversal
+ foreach my $dir ($config{templatedir},
+ "$installdir/share/ikiwiki/templates") {
+ if (-e "$dir/$name") {
+ $template="$dir/$name";
+ last;
+ }
+ }
+ if (defined $template) {
+ return $template, $tpage if wantarray;
+ return $template;
+ }
}
+
return;
}
my $name=shift;
my $page=shift;
- my ($filename, $tpage)=template_file($name);
+ my ($filename, $tpage, $untrusted)=template_file($name);
if (defined $page && defined $tpage) {
add_depends($page, $tpage);
}
return unless defined $filename;
- require HTML::Template;
- return HTML::Template->new(
+ my @opts=(
filter => sub {
my $text_ref = shift;
${$text_ref} = decode_utf8(${$text_ref});
die_on_bad_params => 0,
filename => $filename,
@_,
- no_includes => 1,
+ ($untrusted ? (no_includes => 1) : ()),
);
+ return @opts if wantarray;
+
+ require HTML::Template;
+ return HTML::Template->new(@opts);
}
sub template ($;@) {
sub misctemplate ($$;@) {
my $title=shift;
- my $pagebody=shift;
+ my $content=shift;
- my $template=template("misc.tmpl",
+ my $template=template("page.tmpl");
+
+ run_hooks(pagetemplate => sub {
+ shift->(page => "", destpage => "", template => $template);
+ });
+
+ $template->param(
+ dynamic => 1,
+ have_actions => 0, # force off
title => $title,
- indexlink => indexlink(),
wikiname => $config{wikiname},
- pagebody => $pagebody,
+ content => $content,
baseurl => baseurl(),
+ html5 => $config{html5},
@_,
);
- run_hooks(pagetemplate => sub {
- shift->(page => "", destpage => "", template => $template);
- });
+
return $template->output;
}
my $regexp=IkiWiki::glob2re($glob);
if ($page=~/^$regexp$/i) {
- if (! IkiWiki::isinternal($page) || $params{internal}) {
+ if ($params{onlypage} &&
+ ! defined IkiWiki::pagetype($IkiWiki::pagesources{$page})) {
+ return IkiWiki::FailReason->new("$page is not a page");
+ }
+ elsif (! IkiWiki::isinternal($page) || $params{internal}) {
return IkiWiki::SuccessReason->new("$glob matches $page");
}
else {
return match_glob($_[0], $_[1], @_, internal => 1)
}
+sub match_page ($$;@) {
+ return match_glob($_[0], $_[1], @_, onlypage => 1)
+}
+
sub match_link ($$;@) {
my $page=shift;
my $link=lc(shift);