X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/c20c4066311341e332dc425023f856b6414de9ae..a5fdf4714732c754c6bee16ff65fa85968737010:/IkiWiki/CGI.pm?ds=sidebyside diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index cf6000314..f589ca41d 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -4,6 +4,7 @@ use warnings; use strict; use IkiWiki; use IkiWiki::UserInfo; +use encoding 'utf8'; # force use of utf8 for io layer package IkiWiki; @@ -32,6 +33,11 @@ sub cgi_recentchanges ($) { #{{{ 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" ); @@ -43,7 +49,7 @@ sub cgi_recentchanges ($) { #{{{ styleurl => styleurl(), baseurl => "$config{url}/", ); - print $q->header, $template->output; + print $q->header(-charset=>'utf-8'), $template->output; } #}}} sub cgi_signin ($$) { #{{{ @@ -55,6 +61,7 @@ sub cgi_signin ($$) { #{{{ title => "signin", fields => [qw(do title page subpage from name password confirm_password email)], header => 1, + charset => "utf-8", method => 'POST', validate => { confirm_password => { @@ -172,7 +179,7 @@ sub cgi_signin ($$) { #{{{ $form->field(name => "confirm_password", type => "hidden"); $form->field(name => "email", type => "hidden"); $form->text("Registration successful. Now you can Login."); - print $session->header(); + print $session->header(-charset=>'utf-8'); print misctemplate($form->title, $form->render(submit => ["Login"])); } else { @@ -202,12 +209,12 @@ sub cgi_signin ($$) { #{{{ $form->text("Your password has been emailed to you."); $form->field(name => "name", required => 0); - print $session->header(); + print $session->header(-charset=>'utf-8'); print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"])); } } else { - print $session->header(); + print $session->header(-charset=>'utf-8'); print misctemplate($form->title, $form->render(submit => ["Login", "Register", "Mail Password"])); } } #}}} @@ -222,6 +229,7 @@ sub cgi_prefs ($$) { #{{{ fields => [qw(do name password confirm_password email subscriptions locked_pages)], header => 0, + charset => "utf-8", method => 'POST', validate => { confirm_password => { @@ -281,7 +289,7 @@ sub cgi_prefs ($$) { #{{{ $form->text("Preferences saved."); } - print $session->header(); + print $session->header(-charset=>'utf-8'); print misctemplate($form->title, $form->render(submit => \@buttons)); } #}}} @@ -293,6 +301,7 @@ sub cgi_editpage ($$) { #{{{ my $form = CGI::FormBuilder->new( fields => [qw(do rcsinfo subpage from page editcontent comments)], header => 1, + charset => "utf-8", method => 'POST', validate => { editcontent => '/.+/', @@ -349,9 +358,17 @@ sub cgi_editpage ($$) { #{{{ } 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}, - linkify($page, $page, $form->field('editcontent')))); + linkify($page, $page, $content))); } else { $form->tmpl_param("page_preview", ""); @@ -431,13 +448,17 @@ sub cgi_editpage ($$) { #{{{ # 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 "; - if (length $session->param("name")) { + if (defined $session->param("name") && + length $session->param("name")) { $message.="by ".$session->param("name"); } else { @@ -445,7 +466,7 @@ sub cgi_editpage ($$) { #{{{ } if (defined $form->field('comments') && length $form->field('comments')) { - $message.=": ".$form->field('comments'); + $message.=Encode::decode_utf8(": ".$form->field('comments')); } if ($config{rcs}) {