summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-03-01 02:33:29 +0100
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-03-01 02:33:29 +0100
commit78be753e3be38903b0eeb81e36a7c51704bc6cf3 (patch)
tree295e7a99a07ed742872570d1ecf72f4312978109
parent5080ecd2f4c2711b228127e1c12647906d37f3bd (diff)
downloadbugzilla-78be753e3be38903b0eeb81e36a7c51704bc6cf3.tar.gz
bugzilla-78be753e3be38903b0eeb81e36a7c51704bc6cf3.tar.xz
Bug 508823: Make it so that you don't ever have to reset template_inner (like
Bugzilla->template_inner("")). r=LpSolit, a=LpSolit
-rw-r--r--Bugzilla.pm8
-rw-r--r--Bugzilla/BugMail.pm1
-rw-r--r--Bugzilla/Flag.pm1
-rw-r--r--Bugzilla/Template.pm23
-rw-r--r--Bugzilla/Template/Plugin/Hook.pm7
-rw-r--r--Bugzilla/Token.pm3
-rw-r--r--extensions/Voting/Extension.pm1
-rwxr-xr-xrelogin.cgi1
-rwxr-xr-xwhine.pl1
-rwxr-xr-xwhineatnews.pl1
10 files changed, 28 insertions, 19 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm
index fb640091e..e8a405412 100644
--- a/Bugzilla.pm
+++ b/Bugzilla.pm
@@ -176,17 +176,17 @@ sub init_page {
sub template {
my $class = shift;
- $class->request_cache->{language} = "";
$class->request_cache->{template} ||= Bugzilla::Template->create();
return $class->request_cache->{template};
}
sub template_inner {
my ($class, $lang) = @_;
- $lang = defined($lang) ? $lang : ($class->request_cache->{language} || "");
- $class->request_cache->{language} = $lang;
+ my $cache = $class->request_cache;
+ my $current_lang = $cache->{template_current_lang}->[0];
+ $lang ||= $current_lang || '';
$class->request_cache->{"template_inner_$lang"}
- ||= Bugzilla::Template->create();
+ ||= Bugzilla::Template->create(language => $lang);
return $class->request_cache->{"template_inner_$lang"};
}
diff --git a/Bugzilla/BugMail.pm b/Bugzilla/BugMail.pm
index e7694c32e..a4fbfa3d8 100644
--- a/Bugzilla/BugMail.pm
+++ b/Bugzilla/BugMail.pm
@@ -647,7 +647,6 @@ sub sendMail {
my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
$template->process("email/newchangedmail.txt.tmpl", $vars, \$msg)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($msg);
diff --git a/Bugzilla/Flag.pm b/Bugzilla/Flag.pm
index 90944a2a8..af07bfaa1 100644
--- a/Bugzilla/Flag.pm
+++ b/Bugzilla/Flag.pm
@@ -1012,7 +1012,6 @@ sub notify {
$template->process("request/email.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($message);
}
}
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index 44282e4bc..79382ece2 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -84,9 +84,9 @@ sub _load_constants {
# settings of the user and of the available languages
# If no Accept-Language is present it uses the defined default
# Templates may also be found in the extensions/ tree
-sub getTemplateIncludePath {
+sub _include_path {
+ my $lang = shift || '';
my $cache = Bugzilla->request_cache;
- my $lang = $cache->{'language'} || '';
$cache->{"template_include_path_$lang"} ||=
template_include_path({ language => $lang });
return $cache->{"template_include_path_$lang"};
@@ -428,6 +428,17 @@ $Template::Stash::SCALAR_OPS->{ truncate } =
###############################################################################
+sub process {
+ my $self = shift;
+ # All of this current_langs stuff allows template_inner to correctly
+ # determine what-language Template object it should instantiate.
+ my $current_langs = Bugzilla->request_cache->{template_current_lang} ||= [];
+ unshift(@$current_langs, $self->context->{bz_language});
+ my $retval = $self->SUPER::process(@_);
+ shift @$current_langs;
+ return $retval;
+}
+
# Construct the Template object
# Note that all of the failure cases here can't use templateable errors,
@@ -442,7 +453,8 @@ sub create {
my $config = {
# Colon-separated list of directories containing templates.
- INCLUDE_PATH => $opts{'include_path'} || getTemplateIncludePath(),
+ INCLUDE_PATH => $opts{'include_path'}
+ || _include_path($opts{'language'}),
# Remove white-space before template directives (PRE_CHOMP) and at the
# beginning and end of templates and template blocks (TRIM) for better
@@ -787,6 +799,11 @@ sub create {
Bugzilla::Hook::process('template_before_create', { config => $config });
my $template = $class->new($config)
|| die("Template creation failed: " . $class->error());
+
+ # Pass on our current language to any template hooks or inner templates
+ # called by this Template object.
+ $template->context->{bz_language} = $opts{language} || '';
+
return $template;
}
diff --git a/Bugzilla/Template/Plugin/Hook.pm b/Bugzilla/Template/Plugin/Hook.pm
index 1370f58e0..f2434817c 100644
--- a/Bugzilla/Template/Plugin/Hook.pm
+++ b/Bugzilla/Template/Plugin/Hook.pm
@@ -62,7 +62,7 @@ sub process {
# Get the hooks out of the cache if they exist. Otherwise, read them
# from the disk.
my $cache = Bugzilla->request_cache->{template_plugin_hook_cache} ||= {};
- my $lang = Bugzilla->request_cache->{language} || '';
+ my $lang = $context->{bz_language} || '';
$cache->{"${lang}__$extension_template"}
||= $self->_get_hooks($extension_template);
@@ -75,7 +75,7 @@ sub process {
sub _get_hooks {
my ($self, $extension_template) = @_;
- my $template_sets = _template_hook_include_path();
+ my $template_sets = $self->_template_hook_include_path();
my @hooks;
foreach my $dir_set (@$template_sets) {
foreach my $template_dir (@$dir_set) {
@@ -93,8 +93,9 @@ sub _get_hooks {
}
sub _template_hook_include_path {
+ my $self = shift;
my $cache = Bugzilla->request_cache;
- my $language = $cache->{language} || '';
+ my $language = $self->_context->{bz_language} || '';
my $cache_key = "template_plugin_hook_include_path_$language";
$cache->{$cache_key} ||= template_include_path({
language => $language,
diff --git a/Bugzilla/Token.pm b/Bugzilla/Token.pm
index 2cd9e3f9c..06e95bb50 100644
--- a/Bugzilla/Token.pm
+++ b/Bugzilla/Token.pm
@@ -122,7 +122,6 @@ sub IssueEmailChangeToken {
$template->process("account/email/change-new.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($message);
}
@@ -160,7 +159,6 @@ sub IssuePasswordToken {
$vars, \$message)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($message);
}
@@ -300,7 +298,6 @@ sub Cancel {
$template->process("account/cancel-token.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error());
- Bugzilla->template_inner("");
MessageToMTA($message);
# Delete the token from the database.
diff --git a/extensions/Voting/Extension.pm b/extensions/Voting/Extension.pm
index 06b8a6e9a..5a1cc518e 100644
--- a/extensions/Voting/Extension.pm
+++ b/extensions/Voting/Extension.pm
@@ -800,7 +800,6 @@ sub _remove_votes {
$template->process("voting/votes-removed.txt.tmpl", $vars, \$msg);
push(@messages, $msg);
}
- Bugzilla->template_inner("");
my $votes = $dbh->selectrow_array("SELECT SUM(vote_count) " .
"FROM votes WHERE bug_id = ?",
diff --git a/relogin.cgi b/relogin.cgi
index 40e15ac7e..100fc2c7f 100755
--- a/relogin.cgi
+++ b/relogin.cgi
@@ -164,7 +164,6 @@ elsif ($action eq 'begin-sudo') {
my $message;
my $mail_template = Bugzilla->template_inner($target_user->settings->{'lang'}->{'value'});
$mail_template->process('email/sudo.txt.tmpl', { reason => $reason }, \$message);
- Bugzilla->template_inner("");
MessageToMTA($message);
$vars->{'message'} = 'sudo_started';
diff --git a/whine.pl b/whine.pl
index 10e9a5e13..1f22b65fc 100755
--- a/whine.pl
+++ b/whine.pl
@@ -395,7 +395,6 @@ sub mail {
$template->process("whine/multipart-mime.txt.tmpl", $args, \$msg)
or die($template->error());
- Bugzilla->template_inner("");
MessageToMTA($msg);
delete $args->{'boundary'};
diff --git a/whineatnews.pl b/whineatnews.pl
index df9006230..7be485d29 100755
--- a/whineatnews.pl
+++ b/whineatnews.pl
@@ -89,7 +89,6 @@ foreach my $email (sort (keys %bugs)) {
$template->process("email/whine.txt.tmpl", $vars, \$msg)
or die($template->error());
- Bugzilla->template_inner("");
MessageToMTA($msg);
print "$email " . join(" ", @{$bugs{$email}}) . "\n";