Commit 78be753e authored by Max Kanat-Alexander's avatar Max Kanat-Alexander

Bug 508823: Make it so that you don't ever have to reset template_inner (like

Bugzilla->template_inner("")). r=LpSolit, a=LpSolit
parent 5080ecd2
...@@ -176,17 +176,17 @@ sub init_page { ...@@ -176,17 +176,17 @@ sub init_page {
sub template { sub template {
my $class = shift; my $class = shift;
$class->request_cache->{language} = "";
$class->request_cache->{template} ||= Bugzilla::Template->create(); $class->request_cache->{template} ||= Bugzilla::Template->create();
return $class->request_cache->{template}; return $class->request_cache->{template};
} }
sub template_inner { sub template_inner {
my ($class, $lang) = @_; my ($class, $lang) = @_;
$lang = defined($lang) ? $lang : ($class->request_cache->{language} || ""); my $cache = $class->request_cache;
$class->request_cache->{language} = $lang; my $current_lang = $cache->{template_current_lang}->[0];
$lang ||= $current_lang || '';
$class->request_cache->{"template_inner_$lang"} $class->request_cache->{"template_inner_$lang"}
||= Bugzilla::Template->create(); ||= Bugzilla::Template->create(language => $lang);
return $class->request_cache->{"template_inner_$lang"}; return $class->request_cache->{"template_inner_$lang"};
} }
......
...@@ -647,7 +647,6 @@ sub sendMail { ...@@ -647,7 +647,6 @@ sub sendMail {
my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'}); my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
$template->process("email/newchangedmail.txt.tmpl", $vars, \$msg) $template->process("email/newchangedmail.txt.tmpl", $vars, \$msg)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
Bugzilla->template_inner("");
MessageToMTA($msg); MessageToMTA($msg);
......
...@@ -1012,7 +1012,6 @@ sub notify { ...@@ -1012,7 +1012,6 @@ sub notify {
$template->process("request/email.txt.tmpl", $vars, \$message) $template->process("request/email.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
Bugzilla->template_inner("");
MessageToMTA($message); MessageToMTA($message);
} }
} }
......
...@@ -84,9 +84,9 @@ sub _load_constants { ...@@ -84,9 +84,9 @@ sub _load_constants {
# settings of the user and of the available languages # settings of the user and of the available languages
# If no Accept-Language is present it uses the defined default # If no Accept-Language is present it uses the defined default
# Templates may also be found in the extensions/ tree # Templates may also be found in the extensions/ tree
sub getTemplateIncludePath { sub _include_path {
my $lang = shift || '';
my $cache = Bugzilla->request_cache; my $cache = Bugzilla->request_cache;
my $lang = $cache->{'language'} || '';
$cache->{"template_include_path_$lang"} ||= $cache->{"template_include_path_$lang"} ||=
template_include_path({ language => $lang }); template_include_path({ language => $lang });
return $cache->{"template_include_path_$lang"}; return $cache->{"template_include_path_$lang"};
...@@ -428,6 +428,17 @@ $Template::Stash::SCALAR_OPS->{ truncate } = ...@@ -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 # Construct the Template object
# Note that all of the failure cases here can't use templateable errors, # Note that all of the failure cases here can't use templateable errors,
...@@ -442,7 +453,8 @@ sub create { ...@@ -442,7 +453,8 @@ sub create {
my $config = { my $config = {
# Colon-separated list of directories containing templates. # 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 # Remove white-space before template directives (PRE_CHOMP) and at the
# beginning and end of templates and template blocks (TRIM) for better # beginning and end of templates and template blocks (TRIM) for better
...@@ -787,6 +799,11 @@ sub create { ...@@ -787,6 +799,11 @@ sub create {
Bugzilla::Hook::process('template_before_create', { config => $config }); Bugzilla::Hook::process('template_before_create', { config => $config });
my $template = $class->new($config) my $template = $class->new($config)
|| die("Template creation failed: " . $class->error()); || 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; return $template;
} }
......
...@@ -62,7 +62,7 @@ sub process { ...@@ -62,7 +62,7 @@ sub process {
# Get the hooks out of the cache if they exist. Otherwise, read them # Get the hooks out of the cache if they exist. Otherwise, read them
# from the disk. # from the disk.
my $cache = Bugzilla->request_cache->{template_plugin_hook_cache} ||= {}; my $cache = Bugzilla->request_cache->{template_plugin_hook_cache} ||= {};
my $lang = Bugzilla->request_cache->{language} || ''; my $lang = $context->{bz_language} || '';
$cache->{"${lang}__$extension_template"} $cache->{"${lang}__$extension_template"}
||= $self->_get_hooks($extension_template); ||= $self->_get_hooks($extension_template);
...@@ -75,7 +75,7 @@ sub process { ...@@ -75,7 +75,7 @@ sub process {
sub _get_hooks { sub _get_hooks {
my ($self, $extension_template) = @_; my ($self, $extension_template) = @_;
my $template_sets = _template_hook_include_path(); my $template_sets = $self->_template_hook_include_path();
my @hooks; my @hooks;
foreach my $dir_set (@$template_sets) { foreach my $dir_set (@$template_sets) {
foreach my $template_dir (@$dir_set) { foreach my $template_dir (@$dir_set) {
...@@ -93,8 +93,9 @@ sub _get_hooks { ...@@ -93,8 +93,9 @@ sub _get_hooks {
} }
sub _template_hook_include_path { sub _template_hook_include_path {
my $self = shift;
my $cache = Bugzilla->request_cache; my $cache = Bugzilla->request_cache;
my $language = $cache->{language} || ''; my $language = $self->_context->{bz_language} || '';
my $cache_key = "template_plugin_hook_include_path_$language"; my $cache_key = "template_plugin_hook_include_path_$language";
$cache->{$cache_key} ||= template_include_path({ $cache->{$cache_key} ||= template_include_path({
language => $language, language => $language,
......
...@@ -122,7 +122,6 @@ sub IssueEmailChangeToken { ...@@ -122,7 +122,6 @@ sub IssueEmailChangeToken {
$template->process("account/email/change-new.txt.tmpl", $vars, \$message) $template->process("account/email/change-new.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
Bugzilla->template_inner("");
MessageToMTA($message); MessageToMTA($message);
} }
...@@ -160,7 +159,6 @@ sub IssuePasswordToken { ...@@ -160,7 +159,6 @@ sub IssuePasswordToken {
$vars, \$message) $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
Bugzilla->template_inner("");
MessageToMTA($message); MessageToMTA($message);
} }
...@@ -300,7 +298,6 @@ sub Cancel { ...@@ -300,7 +298,6 @@ sub Cancel {
$template->process("account/cancel-token.txt.tmpl", $vars, \$message) $template->process("account/cancel-token.txt.tmpl", $vars, \$message)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
Bugzilla->template_inner("");
MessageToMTA($message); MessageToMTA($message);
# Delete the token from the database. # Delete the token from the database.
......
...@@ -800,7 +800,6 @@ sub _remove_votes { ...@@ -800,7 +800,6 @@ sub _remove_votes {
$template->process("voting/votes-removed.txt.tmpl", $vars, \$msg); $template->process("voting/votes-removed.txt.tmpl", $vars, \$msg);
push(@messages, $msg); push(@messages, $msg);
} }
Bugzilla->template_inner("");
my $votes = $dbh->selectrow_array("SELECT SUM(vote_count) " . my $votes = $dbh->selectrow_array("SELECT SUM(vote_count) " .
"FROM votes WHERE bug_id = ?", "FROM votes WHERE bug_id = ?",
......
...@@ -164,7 +164,6 @@ elsif ($action eq 'begin-sudo') { ...@@ -164,7 +164,6 @@ elsif ($action eq 'begin-sudo') {
my $message; my $message;
my $mail_template = Bugzilla->template_inner($target_user->settings->{'lang'}->{'value'}); my $mail_template = Bugzilla->template_inner($target_user->settings->{'lang'}->{'value'});
$mail_template->process('email/sudo.txt.tmpl', { reason => $reason }, \$message); $mail_template->process('email/sudo.txt.tmpl', { reason => $reason }, \$message);
Bugzilla->template_inner("");
MessageToMTA($message); MessageToMTA($message);
$vars->{'message'} = 'sudo_started'; $vars->{'message'} = 'sudo_started';
......
...@@ -395,7 +395,6 @@ sub mail { ...@@ -395,7 +395,6 @@ sub mail {
$template->process("whine/multipart-mime.txt.tmpl", $args, \$msg) $template->process("whine/multipart-mime.txt.tmpl", $args, \$msg)
or die($template->error()); or die($template->error());
Bugzilla->template_inner("");
MessageToMTA($msg); MessageToMTA($msg);
delete $args->{'boundary'}; delete $args->{'boundary'};
......
...@@ -89,7 +89,6 @@ foreach my $email (sort (keys %bugs)) { ...@@ -89,7 +89,6 @@ foreach my $email (sort (keys %bugs)) {
$template->process("email/whine.txt.tmpl", $vars, \$msg) $template->process("email/whine.txt.tmpl", $vars, \$msg)
or die($template->error()); or die($template->error());
Bugzilla->template_inner("");
MessageToMTA($msg); MessageToMTA($msg);
print "$email " . join(" ", @{$bugs{$email}}) . "\n"; print "$email " . join(" ", @{$bugs{$email}}) . "\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment