]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Render.pm
* More security review.
[ikiwiki.git] / IkiWiki / Render.pm
index f33d6e66eb7de041d43734b0a4ec4ef3aa7b9b7c..886a30f6b7eb587be217ca215748fbe70dec0ecc 100644 (file)
@@ -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");
@@ -178,7 +182,7 @@ sub genpage ($$$) { #{{{
                $actions++;
        }
        if ($config{discussion}) {
-               $template->param(discussionlink => htmllink($page, "Discussion", 1, 1));
+               $template->param(discussionlink => htmllink($page, $page, "Discussion", 1, 1));
                $actions++;
        }
 
@@ -198,7 +202,7 @@ sub genpage ($$$) { #{{{
                parentlinks => [parentlinks($page)],
                content => $content,
                backlinks => [backlinks($page)],
-               mtime => scalar(gmtime($mtime)),
+               mtime => displaytime($mtime),
                styleurl => styleurl($page),
        );
        
@@ -219,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;
        
@@ -264,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);
                
@@ -410,7 +426,7 @@ FILE:               foreach my $file (@files) {
        }
 
        # Handle backlinks; if a page has added/removed links, update the
-       # pages it links to. Also handles rebuilding dependat pages.
+       # pages it links to. Also handles rebuilding dependant pages.
        # TODO: inefficient; pages may get rendered above and again here;
        # problem is the backlinks could be wrong in the first pass render
        # above