* Centralised all calls to HTML::Template and force all the templates

to be read as utf8.
master
joey 2006-07-02 19:06:08 +00:00
parent 2ed1419c1d
commit d1d212203c
9 changed files with 42 additions and 40 deletions

View File

@ -3,8 +3,6 @@
package IkiWiki; package IkiWiki;
use warnings; use warnings;
use strict; use strict;
use File::Spec;
use HTML::Template;
use vars qw{%config %links %oldlinks %oldpagemtime %pagectime use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
%renderedfiles %pagesources %depends %hooks}; %renderedfiles %pagesources %depends %hooks};
@ -304,6 +302,7 @@ sub htmllink ($$$;$$$) { #{{{
"\">?</a>$linktext</span>" "\">?</a>$linktext</span>"
} }
require File::Spec;
$bestlink=File::Spec->abs2rel($bestlink, dirname($page)); $bestlink=File::Spec->abs2rel($bestlink, dirname($page));
if (! $noimageinline && isinlinableimage($bestlink)) { if (! $noimageinline && isinlinableimage($bestlink)) {
@ -390,13 +389,24 @@ sub saveindex () { #{{{
close OUT; close OUT;
} #}}} } #}}}
sub template_params (@) { #{{{
my $filename=shift;
require Encode;
require HTML::Template;
return filter => \&Encode::decode_utf8,
filename => "$config{templatedir}/$filename", @_;
} #}}}
sub template ($;@) { #{{{
HTML::Template->new(template_params(@_));
} #}}}
sub misctemplate ($$) { #{{{ sub misctemplate ($$) { #{{{
my $title=shift; my $title=shift;
my $pagebody=shift; my $pagebody=shift;
my $template=HTML::Template->new( my $template=template("misc.tmpl");
filename => "$config{templatedir}/misc.tmpl"
);
$template->param( $template->param(
title => $title, title => $title,
indexlink => indexlink(), indexlink => indexlink(),

View File

@ -33,11 +33,7 @@ sub cgi_recentchanges ($) { #{{{
unlockwiki(); unlockwiki();
# Force reading the template as utf-8, necessary if my $template=template("recentchanges.tmpl");
# rcs_recentchanges returns true utf-8 strings.
require Encode;
my $template=HTML::Template->new(filter => \&Encode::decode_utf8,
filename => "$config{templatedir}/recentchanges.tmpl");
$template->param( $template->param(
title => "RecentChanges", title => "RecentChanges",
indexlink => indexlink(), indexlink => indexlink(),
@ -72,7 +68,7 @@ sub cgi_signin ($$) { #{{{
action => $config{cgiurl}, action => $config{cgiurl},
header => 0, header => 0,
template => (-e "$config{templatedir}/signin.tmpl" ? template => (-e "$config{templatedir}/signin.tmpl" ?
"$config{templatedir}/signin.tmpl" : ""), {template_params("signin.tmpl")} : ""),
stylesheet => styleurl(), stylesheet => styleurl(),
); );
@ -185,9 +181,7 @@ sub cgi_signin ($$) { #{{{
} }
elsif ($form->submitted eq 'Mail Password') { elsif ($form->submitted eq 'Mail Password') {
my $user_name=$form->field("name"); my $user_name=$form->field("name");
my $template=HTML::Template->new( my $template=template("passwordmail.tmpl");
filename => "$config{templatedir}/passwordmail.tmpl"
);
$template->param( $template->param(
user_name => $user_name, user_name => $user_name,
user_password => userinfo_get($user_name, "password"), user_password => userinfo_get($user_name, "password"),
@ -239,7 +233,7 @@ sub cgi_prefs ($$) { #{{{
params => $q, params => $q,
action => $config{cgiurl}, action => $config{cgiurl},
template => (-e "$config{templatedir}/prefs.tmpl" ? template => (-e "$config{templatedir}/prefs.tmpl" ?
"$config{templatedir}/prefs.tmpl" : ""), {template_params("prefs.tmpl")} : ""),
stylesheet => styleurl(), stylesheet => styleurl(),
); );
my @buttons=("Save Preferences", "Logout", "Cancel"); my @buttons=("Save Preferences", "Logout", "Cancel");
@ -308,7 +302,7 @@ sub cgi_editpage ($$) { #{{{
params => $q, params => $q,
action => $config{cgiurl}, action => $config{cgiurl},
table => 0, table => 0,
template => "$config{templatedir}/editpage.tmpl" template => {template_params("editpage.tmpl")},
); );
my @buttons=("Save Page", "Preview", "Cancel"); my @buttons=("Save Page", "Preview", "Cancel");

View File

@ -40,8 +40,7 @@ sub preprocess_inline (@) { #{{{
if (exists $params{rootpage}) { if (exists $params{rootpage}) {
# Add a blog post form, with a rss link button. # Add a blog post form, with a rss link button.
my $formtemplate=HTML::Template->new(blind_cache => 1, my $formtemplate=template("blogpost.tmpl", blind_cache => 1);
filename => "$config{templatedir}/blogpost.tmpl");
$formtemplate->param(cgiurl => $config{cgiurl}); $formtemplate->param(cgiurl => $config{cgiurl});
$formtemplate->param(rootpage => $params{rootpage}); $formtemplate->param(rootpage => $params{rootpage});
if ($config{rss}) { if ($config{rss}) {
@ -51,16 +50,17 @@ sub preprocess_inline (@) { #{{{
} }
elsif ($config{rss}) { elsif ($config{rss}) {
# Add a rss link button. # Add a rss link button.
my $linktemplate=HTML::Template->new(blind_cache => 1, my $linktemplate=template("rsslink.tmpl", blind_cache => 1);
filename => "$config{templatedir}/rsslink.tmpl");
$linktemplate->param(rssurl => rsspage(basename($params{page}))); $linktemplate->param(rssurl => rsspage(basename($params{page})));
$ret.=$linktemplate->output; $ret.=$linktemplate->output;
} }
my $template=HTML::Template->new(blind_cache => 1, my $template=template(
filename => (($params{archive} eq "no") (($params{archive} eq "no")
? "$config{templatedir}/inlinepage.tmpl" ? "inlinepage.tmpl"
: "$config{templatedir}/inlinepagetitle.tmpl")); : "inlinepagetitle.tmpl"),
blind_cache => 1,
);
my @pages; my @pages;
foreach my $page (blog_list($params{pages}, $params{show})) { foreach my $page (blog_list($params{pages}, $params{show})) {
@ -146,8 +146,7 @@ sub genrss ($@) { #{{{
my $url="$config{url}/".htmlpage($page); my $url="$config{url}/".htmlpage($page);
my $template=HTML::Template->new(blind_cache => 1, my $template=template("rsspage.tmpl", blind_cache => 1);
filename => "$config{templatedir}/rsspage.tmpl");
my @items; my @items;
foreach my $p (@pages) { foreach my $p (@pages) {

View File

@ -87,9 +87,7 @@ sub estcfg () { #{{{
close TEMPLATE; close TEMPLATE;
open(TEMPLATE, ">$estdir/$cgi.conf") || open(TEMPLATE, ">$estdir/$cgi.conf") ||
error("write $estdir/$cgi.conf: $!"); error("write $estdir/$cgi.conf: $!");
my $template=HTML::Template->new( my $template=template("estseek.conf");
filename => "$config{templatedir}/estseek.conf"
);
eval q{use Cwd 'abs_path'}; eval q{use Cwd 'abs_path'};
$template->param( $template->param(
index => $estdir, index => $estdir,

View File

@ -449,9 +449,7 @@ sub rcs_notify () { #{{{
} }
$subject .= " by $user"; $subject .= " by $user";
my $template = HTML::Template->new( my $template = template("notifymail.tmpl");
filename => "$config{templatedir}/notifymail.tmpl"
);
$template->param( $template->param(
wikiname => $config{wikiname}, wikiname => $config{wikiname},
diff => $diff, diff => $diff,

View File

@ -202,9 +202,7 @@ sub rcs_notify () { #{{{
} }
$subject.=" by $user"; $subject.=" by $user";
my $template=HTML::Template->new( my $template=template("notifymail.tmpl");
filename => "$config{templatedir}/notifymail.tmpl"
);
$template->param( $template->param(
wikiname => $config{wikiname}, wikiname => $config{wikiname},
diff => $diff, diff => $diff,

View File

@ -25,11 +25,13 @@ sub htmlize ($$) { #{{{
my $content=shift; my $content=shift;
if (! $INC{"/usr/bin/markdown"}) { if (! $INC{"/usr/bin/markdown"}) {
# Note: a proper perl module is available in Debian
# for markdown, but not upstream yet.
no warnings 'once'; no warnings 'once';
$blosxom::version="is a proper perl module too much to ask?"; $blosxom::version="is a proper perl module too much to ask?";
use warnings 'all'; use warnings 'all';
do "/usr/bin/markdown"; do "/usr/bin/markdown";
use Encode; require Encode;
} }
if ($type eq '.mdwn') { if ($type eq '.mdwn') {
@ -171,8 +173,7 @@ sub genpage ($$$) { #{{{
my $title=pagetitle(basename($page)); my $title=pagetitle(basename($page));
my $template=HTML::Template->new(blind_cache => 1, my $template=template("page.tmpl", blind_cache => 1);
filename => "$config{templatedir}/page.tmpl");
my $actions=0; my $actions=0;
if (length $config{cgiurl}) { if (length $config{cgiurl}) {

4
debian/changelog vendored
View File

@ -20,8 +20,10 @@ ikiwiki (1.8) UNRELEASED; urgency=low
perl, #376329. Also added a test case for it. perl, #376329. Also added a test case for it.
* Improve layout of edit page so formatting help link is always visible w/o * Improve layout of edit page so formatting help link is always visible w/o
getting in the way of the preview. getting in the way of the preview.
* Centralised all calls to HTML::Template and force all the templates
to be read as utf8.
-- Joey Hess <joeyh@debian.org> Sun, 2 Jul 2006 13:43:56 -0400 -- Joey Hess <joeyh@debian.org> Sun, 2 Jul 2006 14:55:40 -0400
ikiwiki (1.7) unstable; urgency=low ikiwiki (1.7) unstable; urgency=low

View File

@ -17,4 +17,6 @@ won't cache templates.
Could be approached by using HTML::Template's support for filters. Just make it use a filter that turns on utf-8 Could be approached by using HTML::Template's support for filters. Just make it use a filter that turns on utf-8
Or by subclassing it and overriding the \_init\_template method, though that's a bit uglier Or by subclassing it and overriding the \_init\_template method, though that's a bit uglier
[[bugs/done]]