From 75150a5a61b07113e3dd073f614b72fe8a9c8bcc Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" Date: Thu, 25 Aug 2005 14:02:41 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20208761:=20Move=20GetFormat()=20from=20glo?= =?UTF-8?q?bals.pl=20into=20Bugzilla::Template=20-=20Patch=20by=20Fr=C3=A9?= =?UTF-8?q?d=C3=A9ric=20Buclin=20=20r=3Dwicked=20a=3Dju?= =?UTF-8?q?stdave?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://10.0.0.236/trunk@178944 18797224-902f-48f8-a5cc-f745e15eee43 --- .../webtools/bugzilla/Bugzilla/Template.pm | 87 ++++++++++++++++++- mozilla/webtools/bugzilla/buglist.cgi | 4 +- mozilla/webtools/bugzilla/chart.cgi | 2 +- mozilla/webtools/bugzilla/config.cgi | 4 +- .../bugzilla/docs/xml/customization.xml | 2 +- mozilla/webtools/bugzilla/duplicates.cgi | 5 +- mozilla/webtools/bugzilla/enter_bug.cgi | 6 +- mozilla/webtools/bugzilla/globals.pl | 48 ---------- mozilla/webtools/bugzilla/page.cgi | 2 +- mozilla/webtools/bugzilla/post_bug.cgi | 4 +- mozilla/webtools/bugzilla/query.cgi | 6 +- mozilla/webtools/bugzilla/report.cgi | 3 +- mozilla/webtools/bugzilla/show_bug.cgi | 4 +- mozilla/webtools/bugzilla/summarize_time.cgi | 5 +- 14 files changed, 108 insertions(+), 74 deletions(-) diff --git a/mozilla/webtools/bugzilla/Bugzilla/Template.pm b/mozilla/webtools/bugzilla/Bugzilla/Template.pm index 711144a6fd3..52a1bf150fa 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Template.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Template.pm @@ -25,12 +25,14 @@ # Tobias Burnus # Myk Melez # Max Kanat-Alexander +# Frédéric Buclin package Bugzilla::Template; use strict; +use Bugzilla::Constants; use Bugzilla::Config qw(:DEFAULT $templatedir $datadir); use Bugzilla::Util; use Bugzilla::User; @@ -132,7 +134,6 @@ sub getTemplateIncludePath { @usedlanguages)]; } -# Write the header for non yet templatized .cgi files. sub put_header { my $self = shift; ($vars->{'title'}, $vars->{'h1'}, $vars->{'h2'}) = (@_); @@ -142,13 +143,51 @@ sub put_header { $vars->{'header_done'} = 1; } -# Write the footer for non yet templatized .cgi files. sub put_footer { my $self = shift; $self->process("global/footer.html.tmpl", $vars) || ThrowTemplateError($self->error()); } +sub get_format { + my $self = shift; + my ($template, $format, $ctype) = @_; + + $ctype ||= 'html'; + $format ||= ''; + + # Security - allow letters and a hyphen only + $ctype =~ s/[^a-zA-Z\-]//g; + $format =~ s/[^a-zA-Z\-]//g; + trick_taint($ctype); + trick_taint($format); + + $template .= ($format ? "-$format" : ""); + $template .= ".$ctype.tmpl"; + + # Now check that the template actually exists. We only want to check + # if the template exists; any other errors (eg parse errors) will + # end up being detected later. + eval { + $self->context->template($template); + }; + # This parsing may seem fragile, but its OK: + # http://lists.template-toolkit.org/pipermail/templates/2003-March/004370.html + # Even if it is wrong, any sort of error is going to cause a failure + # eventually, so the only issue would be an incorrect error message + if ($@ && $@->info =~ /: not found$/) { + ThrowUserError('format_not_found', {'format' => $format, + 'ctype' => $ctype}); + } + + # Else, just return the info + return + { + 'template' => $template, + 'extension' => $ctype, + 'ctype' => Bugzilla::Constants::contenttypes->{$ctype} + }; +} ############################################################################### # Templatization Code @@ -449,12 +488,19 @@ __END__ =head1 NAME -Bugzilla::Template - Wrapper arround the Template Toolkit C