Commit e7d2b86c authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 301507: Move PutHeader and PutFooter into Template.pm - Patch by Frédéric…

Bug 301507: Move PutHeader and PutFooter into Template.pm - Patch by Frédéric Buclin <LpSolit@gmail.com> r/a=justdave
parent d0303ab3
...@@ -34,11 +34,13 @@ use strict; ...@@ -34,11 +34,13 @@ use strict;
use Bugzilla::Config qw(:DEFAULT $templatedir $datadir); use Bugzilla::Config qw(:DEFAULT $templatedir $datadir);
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::User; use Bugzilla::User;
use Bugzilla::Error;
# for time2str - replace by TT Date plugin?? # for time2str - replace by TT Date plugin??
use Date::Format (); use Date::Format ();
use base qw(Template); use base qw(Template);
use vars qw($vars);
# Convert the constants in the Bugzilla::Constants module into a hash we can # Convert the constants in the Bugzilla::Constants module into a hash we can
# pass to the template object for reflection into its "constants" namespace # pass to the template object for reflection into its "constants" namespace
...@@ -130,6 +132,23 @@ sub getTemplateIncludePath () { ...@@ -130,6 +132,23 @@ sub getTemplateIncludePath () {
@usedlanguages)]; @usedlanguages)];
} }
# Write the header for non yet templatized .cgi files.
sub put_header {
my $self = shift;
($vars->{'title'}, $vars->{'h1'}, $vars->{'h2'}) = (@_);
$self->process("global/header.html.tmpl", $vars)
|| ThrowTemplateError($self->error());
$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());
}
############################################################################### ###############################################################################
# Templatization Code # Templatization Code
......
...@@ -50,20 +50,7 @@ sub CGI_pl_sillyness { ...@@ -50,20 +50,7 @@ sub CGI_pl_sillyness {
require 'globals.pl'; require 'globals.pl';
use vars qw($template $vars); use vars qw($vars);
sub PutHeader {
($vars->{'title'}, $vars->{'h1'}, $vars->{'h2'}) = (@_);
$::template->process("global/header.html.tmpl", $::vars)
|| ThrowTemplateError($::template->error());
$vars->{'header_done'} = 1;
}
sub PutFooter {
$::template->process("global/footer.html.tmpl", $::vars)
|| ThrowTemplateError($::template->error());
}
############# Live code below here (that is, not subroutine defs) ############# ############# Live code below here (that is, not subroutine defs) #############
......
...@@ -35,6 +35,7 @@ require "CGI.pl"; ...@@ -35,6 +35,7 @@ require "CGI.pl";
Bugzilla->login(LOGIN_REQUIRED); Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template;
print $cgi->header(); print $cgi->header();
...@@ -43,7 +44,7 @@ UserInGroup("tweakparams") ...@@ -43,7 +44,7 @@ UserInGroup("tweakparams")
action => "modify", action => "modify",
object => "parameters"}); object => "parameters"});
PutHeader("Saving new parameters"); $template->put_header("Saving new parameters");
my $howto = ""; my $howto = "";
...@@ -90,7 +91,7 @@ foreach my $i (GetParamList()) { ...@@ -90,7 +91,7 @@ foreach my $i (GetParamList()) {
print "New value for " . html_quote($name) . print "New value for " . html_quote($name) .
" is invalid: $ok<p>\n"; " is invalid: $ok<p>\n";
print "Please hit <b>Back</b> and try again.\n"; print "Please hit <b>Back</b> and try again.\n";
PutFooter(); $template->put_footer();
exit; exit;
} }
} }
...@@ -115,4 +116,4 @@ print $howto; ...@@ -115,4 +116,4 @@ print $howto;
print "<a href=\"editparams.cgi\">Edit the params some more.</a><p>\n"; print "<a href=\"editparams.cgi\">Edit the params some more.</a><p>\n";
print "<a href=\"query.cgi\">Go back to the query page.</a>\n"; print "<a href=\"query.cgi\">Go back to the query page.</a>\n";
PutFooter(); $template->put_footer();
...@@ -33,6 +33,8 @@ require "CGI.pl"; ...@@ -33,6 +33,8 @@ require "CGI.pl";
Bugzilla->login(LOGIN_REQUIRED); Bugzilla->login(LOGIN_REQUIRED);
my $template = Bugzilla->template;
print Bugzilla->cgi->header(); print Bugzilla->cgi->header();
UserInGroup("tweakparams") UserInGroup("tweakparams")
...@@ -40,7 +42,7 @@ UserInGroup("tweakparams") ...@@ -40,7 +42,7 @@ UserInGroup("tweakparams")
action => "modify", action => "modify",
object => "parameters"}); object => "parameters"});
PutHeader("Edit parameters"); $template->put_header("Edit parameters");
print "This lets you edit the basic operating parameters of bugzilla.\n"; print "This lets you edit the basic operating parameters of bugzilla.\n";
print "Be careful!\n"; print "Be careful!\n";
...@@ -141,4 +143,4 @@ print "<input type=submit value=\"Submit changes\">\n"; ...@@ -141,4 +143,4 @@ print "<input type=submit value=\"Submit changes\">\n";
print "</form>\n"; print "</form>\n";
print "<p><a href=query.cgi>Skip all this, and go back to the query page</a>\n"; print "<p><a href=query.cgi>Skip all this, and go back to the query page</a>\n";
PutFooter(); $template->put_footer();
...@@ -118,7 +118,7 @@ sub CheckClassification ($) ...@@ -118,7 +118,7 @@ sub CheckClassification ($)
# For the transition period, as this file is templatised bit by bit, # For the transition period, as this file is templatised bit by bit,
# we need this routine, which does things properly, and will # we need this routine, which does things properly, and will
# eventually be the only version. (The older versions assume a # eventually be the only version. (The older versions assume a
# PutHeader() call has been made) # $template->put_header() call has been made)
sub CheckClassificationNew ($) sub CheckClassificationNew ($)
{ {
my $cl = shift; my $cl = shift;
...@@ -271,7 +271,7 @@ sub PutTrailer (@) ...@@ -271,7 +271,7 @@ sub PutTrailer (@)
} }
$num++; $num++;
} }
PutFooter(); $template->put_footer();
} }
...@@ -408,7 +408,7 @@ if (!$action && !$product) { ...@@ -408,7 +408,7 @@ if (!$action && !$product) {
# #
if ($action eq 'add') { if ($action eq 'add') {
PutHeader("Add product"); $template->put_header("Add product");
if (Param('useclassification')) { if (Param('useclassification')) {
CheckClassification($classification); CheckClassification($classification);
...@@ -449,7 +449,7 @@ if ($action eq 'add') { ...@@ -449,7 +449,7 @@ if ($action eq 'add') {
# #
if ($action eq 'new') { if ($action eq 'new') {
PutHeader("Adding new product"); $template->put_header("Adding new product");
# Cleanups and validity checks # Cleanups and validity checks
...@@ -777,7 +777,7 @@ if ($action eq 'delete') { ...@@ -777,7 +777,7 @@ if ($action eq 'delete') {
# #
if ($action eq 'edit' || (!$action && $product)) { if ($action eq 'edit' || (!$action && $product)) {
PutHeader("Edit product"); $template->put_header("Edit product");
CheckProduct($product); CheckProduct($product);
my $classification_id=1; my $classification_id=1;
if (Param('useclassification')) { if (Param('useclassification')) {
...@@ -1003,7 +1003,7 @@ if ($action eq 'updategroupcontrols') { ...@@ -1003,7 +1003,7 @@ if ($action eq 'updategroupcontrols') {
exit; exit;
} }
} }
PutHeader("Update group access controls for product \"$product\""); $template->put_header("Update group access controls for product \"$product\"");
$headerdone = 1; $headerdone = 1;
SendSQL("SELECT id, name FROM groups " . SendSQL("SELECT id, name FROM groups " .
"WHERE isbuggroup != 0 AND isactive != 0"); "WHERE isbuggroup != 0 AND isactive != 0");
...@@ -1167,7 +1167,7 @@ if ($action eq 'updategroupcontrols') { ...@@ -1167,7 +1167,7 @@ if ($action eq 'updategroupcontrols') {
# #
if ($action eq 'update') { if ($action eq 'update') {
PutHeader("Update product"); $template->put_header("Update product");
my $productold = trim($cgi->param('productold') || ''); my $productold = trim($cgi->param('productold') || '');
my $description = trim($cgi->param('description') || ''); my $description = trim($cgi->param('description') || '');
...@@ -1448,5 +1448,5 @@ if ($action eq 'editgroupcontrols') { ...@@ -1448,5 +1448,5 @@ if ($action eq 'editgroupcontrols') {
# No valid action found # No valid action found
# #
PutHeader("Error"); $template->put_header("Error");
print "I don't have a clue what you want.<BR>\n"; print "I don't have a clue what you want.<BR>\n";
...@@ -81,12 +81,12 @@ sub Unlock { ...@@ -81,12 +81,12 @@ sub Unlock {
if (!defined $cgi->param('buglist')) { if (!defined $cgi->param('buglist')) {
print $cgi->header(); print $cgi->header();
PutHeader("Move Bugs"); $template->put_header("Move Bugs");
print "Move bugs either from the bug display page or perform a "; print "Move bugs either from the bug display page or perform a ";
print "<A HREF=\"query.cgi\">query</A> and change several bugs at once.\n"; print "<A HREF=\"query.cgi\">query</A> and change several bugs at once.\n";
print "If you don't see the move button, then you either aren't "; print "If you don't see the move button, then you either aren't ";
print "logged in or aren't permitted to."; print "logged in or aren't permitted to.";
PutFooter(); $template->put_footer();
exit; exit;
} }
...@@ -96,9 +96,9 @@ $movers =~ s/\s?,\s?/|/g; ...@@ -96,9 +96,9 @@ $movers =~ s/\s?,\s?/|/g;
$movers =~ s/@/\@/g; $movers =~ s/@/\@/g;
unless ($exporter =~ /($movers)/) { unless ($exporter =~ /($movers)/) {
print $cgi->header(); print $cgi->header();
PutHeader("Move Bugs"); $template->put_header("Move Bugs");
print "<P>You do not have permission to move bugs<P>\n"; print "<P>You do not have permission to move bugs<P>\n";
PutFooter(); $template->put_footer();
exit; exit;
} }
......
...@@ -592,7 +592,7 @@ if (defined $cgi->param('action')) { ...@@ -592,7 +592,7 @@ if (defined $cgi->param('action')) {
if (Param("move-enabled") && $action eq Param("move-button-text")) { if (Param("move-enabled") && $action eq Param("move-button-text")) {
$cgi->param('buglist', join (":", @idlist)); $cgi->param('buglist', join (":", @idlist));
do "move.pl" || die "Error executing move.cgi: $!"; do "move.pl" || die "Error executing move.cgi: $!";
PutFooter(); $template->put_footer();
exit; exit;
} }
......
...@@ -63,6 +63,7 @@ GetVersionTable(); ...@@ -63,6 +63,7 @@ GetVersionTable();
Bugzilla->switch_to_shadow_db(); Bugzilla->switch_to_shadow_db();
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template;
# We only want those products that the user has permissions for. # We only want those products that the user has permissions for.
my @myproducts; my @myproducts;
...@@ -72,7 +73,7 @@ push( @myproducts, GetSelectableProducts()); ...@@ -72,7 +73,7 @@ push( @myproducts, GetSelectableProducts());
if (! defined $cgi->param('product')) { if (! defined $cgi->param('product')) {
choose_product(@myproducts); choose_product(@myproducts);
PutFooter(); $template->put_footer();
} else { } else {
my $product = $cgi->param('product'); my $product = $cgi->param('product');
...@@ -93,11 +94,11 @@ if (! defined $cgi->param('product')) { ...@@ -93,11 +94,11 @@ if (! defined $cgi->param('product')) {
print $cgi->header(-Content_Disposition=>'inline; filename=bugzilla_report.html'); print $cgi->header(-Content_Disposition=>'inline; filename=bugzilla_report.html');
PutHeader("Bug Charts"); $template->put_header("Bug Charts");
show_chart($product); show_chart($product);
PutFooter(); $template->put_footer();
} }
...@@ -119,7 +120,7 @@ sub choose_product { ...@@ -119,7 +120,7 @@ sub choose_product {
|| ThrowCodeError("chart_file_open_fail", {filename => "$dir/$datafile"}); || ThrowCodeError("chart_file_open_fail", {filename => "$dir/$datafile"});
print $cgi->header(); print $cgi->header();
PutHeader("Bug Charts"); $template->put_header("Bug Charts");
print <<FIN; print <<FIN;
<center> <center>
......
...@@ -75,6 +75,7 @@ Bugzilla->login(LOGIN_REQUIRED); ...@@ -75,6 +75,7 @@ Bugzilla->login(LOGIN_REQUIRED);
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template;
# Make sure the user is authorized to access sanitycheck.cgi. Access # Make sure the user is authorized to access sanitycheck.cgi. Access
# is restricted to logged-in users who have "editbugs" privileges, # is restricted to logged-in users who have "editbugs" privileges,
...@@ -92,7 +93,7 @@ print $cgi->header(); ...@@ -92,7 +93,7 @@ print $cgi->header();
my @row; my @row;
PutHeader("Bugzilla Sanity Check"); $template->put_header("Bugzilla Sanity Check");
########################################################################### ###########################################################################
# Fix vote cache # Fix vote cache
...@@ -272,7 +273,7 @@ if (defined $cgi->param('rescanallBugMail')) { ...@@ -272,7 +273,7 @@ if (defined $cgi->param('rescanallBugMail')) {
Status("Unsent mail has been sent."); Status("Unsent mail has been sent.");
} }
PutFooter(); $template->put_footer();
exit; exit;
} }
...@@ -887,4 +888,4 @@ if (@badbugs > 0) { ...@@ -887,4 +888,4 @@ if (@badbugs > 0) {
########################################################################### ###########################################################################
Status("Sanity check completed."); Status("Sanity check completed.");
PutFooter(); $template->put_footer();
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