X-Git-Url: https://scripts.mit.edu/gitweb/www/ikiwiki.git/blobdiff_plain/282893be819eab14f3a2078f1741ec9c9ed363b1..7a1e12675ec5f1ea605d4de06a0b82079073fb20:/IkiWiki/Render.pm diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 5bc7f6ebb..c5922c933 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -7,13 +7,14 @@ use strict; use File::Spec; use IkiWiki; -sub linkify ($$) { #{{{ +sub linkify ($$$) { #{{{ + my $lpage=shift; my $page=shift; my $content=shift; $content =~ s{(\\?)$config{wiki_link_regexp}}{ - $2 ? ( $1 ? "[[$2|$3]]" : htmllink($page, titlepage($3), 0, 0, pagetitle($2))) - : ( $1 ? "[[$3]]" : htmllink($page, titlepage($3))) + $2 ? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, titlepage($3), 0, 0, pagetitle($2))) + : ( $1 ? "[[$3]]" : htmllink($lpage, $page, titlepage($3))) }eg; return $content; @@ -28,10 +29,13 @@ sub htmlize ($$) { #{{{ $blosxom::version="is a proper perl module too much to ask?"; use warnings 'all'; do "/usr/bin/markdown"; + require Encode; } if ($type eq '.mdwn') { - $content=Markdown::Markdown($content); + # Markdown does character based stuff that does not work + # well with utf-8 strings. + $content=Encode::decode_utf8(Markdown::Markdown(Encode::encode_utf8($content))); } else { error("htmlization of $type not supported"); @@ -160,22 +164,30 @@ sub genpage ($$$) { #{{{ my $template=HTML::Template->new(blind_cache => 1, filename => "$config{templatedir}/page.tmpl"); - + my $actions=0; + if (length $config{cgiurl}) { $template->param(editurl => cgiurl(do => "edit", page => $page)); $template->param(prefsurl => cgiurl(do => "prefs")); if ($config{rcs}) { $template->param(recentchangesurl => cgiurl(do => "recentchanges")); } + $actions++; } if (length $config{historyurl}) { my $u=$config{historyurl}; $u=~s/\[\[file\]\]/$pagesources{$page}/g; $template->param(historyurl => $u); + $actions++; } if ($config{discussion}) { - $template->param(discussionlink => htmllink($page, "Discussion", 1, 1)); + $template->param(discussionlink => htmllink($page, $page, "Discussion", 1, 1)); + $actions++; + } + + if ($actions) { + $template->param(have_actions => 1); } if (exists $hooks{pagetemplate}) { @@ -190,7 +202,7 @@ sub genpage ($$$) { #{{{ parentlinks => [parentlinks($page)], content => $content, backlinks => [backlinks($page)], - mtime => scalar(gmtime($mtime)), + mtime => displaytime($mtime), styleurl => styleurl($page), ); @@ -211,6 +223,18 @@ sub check_overwrite ($$) { #{{{ } } #}}} +sub displaytime ($) { #{{{ + my $time=shift; + + if ($config{timeformat} eq '%c') { + return scalar(localtime($time)); # optimisation + } + else { + eval q{use POSIX}; + return POSIX::strftime($config{timeformat}, localtime($time)); + } +} #}}} + sub mtime ($) { #{{{ my $file=shift; @@ -256,7 +280,7 @@ sub render ($) { #{{{ $links{$page}=[findlinks($page, $content)]; - $content=linkify($page, $content); + $content=linkify($page, $page, $content); $content=preprocess($page, $content); $content=htmlize($type, $content); @@ -347,8 +371,12 @@ sub refresh () { #{{{ push @add, $file; $links{$page}=[]; $pagesources{$page}=$file; - $pagectime{$page}=mtime(srcfile($file)) - unless exists $pagectime{$page}; + if ($config{getctime} && -e "$config{srcdir}/$file") { + $pagectime{$page}=rcs_getctime("$config{srcdir}/$file"); + } + elsif (! exists $pagectime{$page}) { + $pagectime{$page}=mtime(srcfile($file)); + } } } my @del;