From 78be753e3be38903b0eeb81e36a7c51704bc6cf3 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Sun, 28 Feb 2010 17:33:29 -0800 Subject: Bug 508823: Make it so that you don't ever have to reset template_inner (like Bugzilla->template_inner("")). r=LpSolit, a=LpSolit --- Bugzilla/BugMail.pm | 1 - Bugzilla/Flag.pm | 1 - Bugzilla/Template.pm | 23 ++++++++++++++++++++--- Bugzilla/Template/Plugin/Hook.pm | 7 ++++--- Bugzilla/Token.pm | 3 --- 5 files changed, 24 insertions(+), 11 deletions(-) (limited to 'Bugzilla') 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. -- cgit v1.2.3-24-g4f1b