]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 508823: Make it so that you don't ever have to reset template_inner (like
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Mon, 1 Mar 2010 01:33:29 +0000 (17:33 -0800)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Mon, 1 Mar 2010 01:33:29 +0000 (17:33 -0800)
Bugzilla->template_inner("")).
r=LpSolit, a=LpSolit

Bugzilla.pm
Bugzilla/BugMail.pm
Bugzilla/Flag.pm
Bugzilla/Template.pm
Bugzilla/Template/Plugin/Hook.pm
Bugzilla/Token.pm
extensions/Voting/Extension.pm
relogin.cgi
whine.pl
whineatnews.pl

index fb640091e54a2d4732fc7d99956de1c8ec5ef81c..e8a40541211ef2fa5b04d2676e3518e63a264fa7 100644 (file)
@@ -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"};
 }
 
index e7694c32e17a59c12c1d0b7d17bc4ede48d16279..a4fbfa3d809338457861e8db58c8b6c9b352d21d 100644 (file)
@@ -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);
 
index 90944a2a8ce8ea9989d0d217943dc4fcaa176842..af07bfaa17e9e810392206f461839f251990b2f8 100644 (file)
@@ -1012,7 +1012,6 @@ sub notify {
         $template->process("request/email.txt.tmpl", $vars, \$message)
           || ThrowTemplateError($template->error());
 
-        Bugzilla->template_inner("");
         MessageToMTA($message);
     }
 }
index 44282e4bcf420e6d7b37429186f957ca12857298..79382ece2cc67d99b170efc1db85c4bab707c011 100644 (file)
@@ -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;
 }
 
index 1370f58e0865ae2b69b53255a5fd5a820dc1525e..f2434817cc538df4603f535d13867f6de010ad24 100644 (file)
@@ -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,
index 2cd9e3f9c4cef39f3be556e1d8b115bff292ab07..06e95bb501e89da319995d79574ae8125ccc511d 100644 (file)
@@ -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.
index 06b8a6e9a1d50d2ba341a3320cc1914a6dffed0f..5a1cc518e1b79749db0f3a6042c2fb8e887384f5 100644 (file)
@@ -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 = ?",
index 40e15ac7e60d0e1856861a4f03dbb36e82d36a73..100fc2c7f165979d1a32c9c795e65a01045c8077 100755 (executable)
@@ -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';
index 10e9a5e13e0c39d4e71fa100a65ac8b99fc618d1..1f22b65fc4fffd9acd7c472e2b1abd14859e2bb4 100755 (executable)
--- 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'};
index df9006230c1468812e80c1c910b6347d4895ea70..7be485d29e75a3cea674ff8f783c4ce20be3db20 100755 (executable)
@@ -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";