calendar, prettydate: Fix strftime encoding bug
strftime is a C function, it does not return decoded utf8. Several places in ikiwiki manually decoded it, but at least two forgot to. Also, strftime might not return even encoded utf8, if LC_TIME is set to a non-utf8 value. Went ahead and supported decoding whatever encoding it uses. The remaining direct calls to strftime() are all ones that first set LC_TIME=C, in order to get times that are not for human display.master
parent
0ba0d09824
commit
a78126c55e
16
IkiWiki.pm
16
IkiWiki.pm
|
@ -20,7 +20,7 @@ use Exporter q{import};
|
|||
our @EXPORT = qw(hook debug error htmlpage template template_depends
|
||||
deptype add_depends pagespec_match pagespec_match_list bestlink
|
||||
htmllink readfile writefile pagetype srcfile pagename
|
||||
displaytime will_render gettext ngettext urlto targetpage
|
||||
displaytime strftime_utf8 will_render gettext ngettext urlto targetpage
|
||||
add_underlay pagetitle titlepage linkpage newpagefile
|
||||
inject add_link add_autofile
|
||||
%config %links %pagestate %wikistate %renderedfiles
|
||||
|
@ -1148,9 +1148,19 @@ sub formattime ($;$) {
|
|||
$format=$config{timeformat};
|
||||
}
|
||||
|
||||
return strftime_utf8($format, localtime($time));
|
||||
}
|
||||
|
||||
my $strftime_encoding;
|
||||
sub strftime_utf8 {
|
||||
# strftime doesn't know about encodings, so make sure
|
||||
# its output is properly treated as utf8
|
||||
return decode_utf8(POSIX::strftime($format, localtime($time)));
|
||||
# its output is properly treated as utf8.
|
||||
# Note that this does not handle utf-8 in the format string.
|
||||
$strftime_encoding = POSIX::setlocale(&POSIX::LC_TIME) =~ m#\.([^@]+)#
|
||||
unless defined $strftime_encoding;
|
||||
$strftime_encoding
|
||||
? Encode::decode($strftime_encoding, POSIX::strftime(@_))
|
||||
: POSIX::strftime(@_);
|
||||
}
|
||||
|
||||
sub date_3339 ($) {
|
||||
|
|
|
@ -22,7 +22,6 @@ use warnings;
|
|||
use strict;
|
||||
use IkiWiki 3.00;
|
||||
use Time::Local;
|
||||
use POSIX ();
|
||||
|
||||
my $time=time;
|
||||
my @now=localtime($time);
|
||||
|
@ -123,10 +122,10 @@ sub format_month (@) {
|
|||
}
|
||||
|
||||
# Find out month names for this, next, and previous months
|
||||
my $monthabbrev=POSIX::strftime("%b", @monthstart);
|
||||
my $monthname=POSIX::strftime("%B", @monthstart);
|
||||
my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$pmonth-1,$pyear-1900)));
|
||||
my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$nmonth-1,$nyear-1900)));
|
||||
my $monthabbrev=strftime_utf8("%b", @monthstart);
|
||||
my $monthname=strftime_utf8("%B", @monthstart);
|
||||
my $pmonthname=strftime_utf8("%B", localtime(timelocal(0,0,0,1,$pmonth-1,$pyear-1900)));
|
||||
my $nmonthname=strftime_utf8("%B", localtime(timelocal(0,0,0,1,$nmonth-1,$nyear-1900)));
|
||||
|
||||
my $archivebase = 'archives';
|
||||
$archivebase = $config{archivebase} if defined $config{archivebase};
|
||||
|
@ -182,7 +181,7 @@ EOF
|
|||
my %dowabbr;
|
||||
for my $dow ($week_start_day..$week_start_day+6) {
|
||||
my @day=localtime(timelocal(0,0,0,$start_day++,$params{month}-1,$params{year}-1900));
|
||||
my $downame = POSIX::strftime("%A", @day);
|
||||
my $downame = strftime_utf8("%A", @day);
|
||||
my $dowabbr = substr($downame, 0, 1);
|
||||
$downame{$dow % 7}=$downame;
|
||||
$dowabbr{$dow % 7}=$dowabbr;
|
||||
|
@ -329,8 +328,8 @@ EOF
|
|||
for (my $month = 1; $month <= 12; $month++) {
|
||||
my @day=localtime(timelocal(0,0,0,15,$month-1,$params{year}-1900));
|
||||
my $murl;
|
||||
my $monthname = POSIX::strftime("%B", @day);
|
||||
my $monthabbr = POSIX::strftime("%b", @day);
|
||||
my $monthname = strftime_utf8("%B", @day);
|
||||
my $monthabbr = strftime_utf8("%b", @day);
|
||||
$calendar.=qq{\t<tr>\n} if ($month % $params{months_per_row} == 1);
|
||||
my $tag;
|
||||
my $mtag=sprintf("%02d", $month);
|
||||
|
|
|
@ -9,7 +9,6 @@ use warnings;
|
|||
use strict;
|
||||
use IkiWiki 3.00;
|
||||
use Encode;
|
||||
use POSIX qw(strftime);
|
||||
|
||||
use constant PREVIEW => "Preview";
|
||||
use constant POST_COMMENT => "Post comment";
|
||||
|
@ -460,7 +459,7 @@ sub editcomment ($$) {
|
|||
}
|
||||
$content .= " subject=\"$subject\"\n";
|
||||
|
||||
$content .= " date=\"" . decode_utf8(strftime('%Y-%m-%dT%H:%M:%SZ', gmtime)) . "\"\n";
|
||||
$content .= " date=\"" . strftime_utf8('%Y-%m-%dT%H:%M:%SZ', gmtime) . "\"\n";
|
||||
|
||||
my $editcontent = $form->field('editcontent');
|
||||
$editcontent="" if ! defined $editcontent;
|
||||
|
|
|
@ -118,10 +118,10 @@ sub IkiWiki::formattime ($;$) {
|
|||
}
|
||||
}
|
||||
|
||||
$t=~s{\%A-}{my @yest=@t; $yest[6]--; strftime("%A", \@yest)}eg;
|
||||
$t=~s{\%A-}{my @yest=@t; $yest[6]--; strftime_utf8("%A", \@yest)}eg;
|
||||
|
||||
$format=~s/\%X/$t/g;
|
||||
return strftime($format, \@t);
|
||||
return strftime_utf8($format, \@t);
|
||||
}
|
||||
|
||||
1
|
||||
|
|
|
@ -5,6 +5,7 @@ ikiwiki (3.20120116) UNRELEASED; urgency=low
|
|||
* Switch to YAML::XS to work around insanity in YAML::Mo. Closes: #657533
|
||||
* cvs: Ensure non-text files are added in binary mode. (Amitai Schlair)
|
||||
* cvs: Various cleanups and testing. (Amitai Schlair)
|
||||
* calendar, prettydate: Fix strftime encoding bug.
|
||||
|
||||
-- Joey Hess <joeyh@debian.org> Mon, 16 Jan 2012 13:41:14 -0400
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ The problem is that I do not know Perl, encoding is one of the thing I would be
|
|||
Cheers,
|
||||
Louis
|
||||
|
||||
> Yes, this seems basically right. I've applied a modified version of this.
|
||||
> [[done]]
|
||||
> --[[Joey]]
|
||||
|
||||
|
||||
diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm
|
||||
index c7d2b7c..1345939 100644
|
||||
|
|
|
@ -15,3 +15,6 @@ Is someone could test it and verify if it works or not?
|
|||
Thanks.
|
||||
|
||||
Zut
|
||||
|
||||
> This was discussed in [[bugs/Encoding_problem_in_calendar_plugin]]
|
||||
> and is now fixed. --[[Joey]]
|
||||
|
|
Loading…
Reference in New Issue