]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/CGI.pm
FUCK UTF8 fuck fuck fuck!!!
[git.ikiwiki.info.git] / IkiWiki / CGI.pm
index 986a8ee1d6b78a0c107d7732d787282ef1b40a7c..f589ca41da60d39d1d7f7d774598f891313403b2 100644 (file)
@@ -4,6 +4,7 @@ use warnings;
 use strict;
 use IkiWiki;
 use IkiWiki::UserInfo;
 use strict;
 use IkiWiki;
 use IkiWiki::UserInfo;
+use encoding 'utf8'; # force use of utf8 for io layer
 
 package IkiWiki;
 
 
 package IkiWiki;
 
@@ -32,6 +33,11 @@ sub cgi_recentchanges ($) { #{{{
        
        unlockwiki();
 
        
        unlockwiki();
 
+       # Force reading the template as utf-8, necessary if
+       # rcs_recentchanges returns true utf-8 strings.
+       open(TMPL, "<:utf8", "$config{templatedir}/recentchanges.tmpl");
+       my $template=HTML::Template->new(filehandle => *TMPL);
+       close(TMPL);
        my $template=HTML::Template->new(
                filename => "$config{templatedir}/recentchanges.tmpl"
        );
        my $template=HTML::Template->new(
                filename => "$config{templatedir}/recentchanges.tmpl"
        );
@@ -43,8 +49,7 @@ sub cgi_recentchanges ($) { #{{{
                styleurl => styleurl(),
                baseurl => "$config{url}/",
        );
                styleurl => styleurl(),
                baseurl => "$config{url}/",
        );
-       require Encode;
-       print $q->header(-charset=>'utf-8'), Encode::decode_utf8($template->output);
+       print $q->header(-charset=>'utf-8'), $template->output;
 } #}}}
 
 sub cgi_signin ($$) { #{{{
 } #}}}
 
 sub cgi_signin ($$) { #{{{
@@ -353,9 +358,17 @@ sub cgi_editpage ($$) { #{{{
        }
        elsif ($form->submitted eq "Preview") {
                require IkiWiki::Render;
        }
        elsif ($form->submitted eq "Preview") {
                require IkiWiki::Render;
+               # Apparently FormBuilder doesn't not treat input as
+               # utf-8, so decode from it.
+               require Encode;
+               my $content = Encode::decode_utf8($form->field('editcontent'));
+               $form->field(name => "editcontent",
+                               value => $content, force => 1);
+               $form->field(name => "comments",
+                               value => Encode::decode_utf8($form->field('comments')), force => 1);
                $form->tmpl_param("page_preview",
                        htmlize($config{default_pageext},
                $form->tmpl_param("page_preview",
                        htmlize($config{default_pageext},
-                               linkify($page, $page, $form->field('editcontent'))));
+                               linkify($page, $page, $content)));
        }
        else {
                $form->tmpl_param("page_preview", "");
        }
        else {
                $form->tmpl_param("page_preview", "");
@@ -418,8 +431,7 @@ sub cgi_editpage ($$) { #{{{
                            ! length $form->field('editcontent')) {
                                my $content="";
                                if (exists $pagesources{lc($page)}) {
                            ! length $form->field('editcontent')) {
                                my $content="";
                                if (exists $pagesources{lc($page)}) {
-                                       require Encode;
-                                       $content=Encode::decode_utf8(readfile(srcfile($pagesources{lc($page)})));
+                                       $content=readfile(srcfile($pagesources{lc($page)}));
                                        $content=~s/\n/\r\n/g;
                                }
                                $form->field(name => "editcontent", value => $content,
                                        $content=~s/\n/\r\n/g;
                                }
                                $form->field(name => "editcontent", value => $content,
@@ -436,13 +448,17 @@ sub cgi_editpage ($$) { #{{{
                # save page
                page_locked($page, $session);
                
                # save page
                page_locked($page, $session);
                
-               my $content=$form->field('editcontent');
+               # Decode utf-8 since FormBuilder does not
+               require Encode;
+               my $content=Encode::decode_utf8($form->field('editcontent'));
+
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
                writefile($file, $config{srcdir}, $content);
                
                my $message="web commit ";
                $content=~s/\r\n/\n/g;
                $content=~s/\r/\n/g;
                writefile($file, $config{srcdir}, $content);
                
                my $message="web commit ";
-               if (length $session->param("name")) {
+               if (defined $session->param("name") && 
+                   length $session->param("name")) {
                        $message.="by ".$session->param("name");
                }
                else {
                        $message.="by ".$session->param("name");
                }
                else {
@@ -450,7 +466,6 @@ sub cgi_editpage ($$) { #{{{
                }
                if (defined $form->field('comments') &&
                    length $form->field('comments')) {
                }
                if (defined $form->field('comments') &&
                    length $form->field('comments')) {
-                       require Encode;
                        $message.=Encode::decode_utf8(": ".$form->field('comments'));
                }
                
                        $message.=Encode::decode_utf8(": ".$form->field('comments'));
                }