Bug 100094 - use generic template handling code

r=mattyt, afranke
parent 5938698d
...@@ -27,25 +27,15 @@ ...@@ -27,25 +27,15 @@
use diagnostics; use diagnostics;
use strict; use strict;
use vars qw(
$template
$vars
);
package Attachment; package Attachment;
# Use the template toolkit (http://www.template-toolkit.org/) to generate my $template = $::template;
# the user interface (HTML pages and mail messages) using templates in the my $vars = $::vars;
# "templates/" subdirectory.
use Template;
# This is the global template object that gets used one or more times by
# the script when it needs to process a template and return the results.
# Configuration parameters can be specified here that apply to all templates
# processed in this file.
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => 'template/custom:template/default' ,
# Allow templates to be specified with relative paths.
RELATIVE => 1
}
);
# This module requires that its caller have said "require CGI.pl" to import # This module requires that its caller have said "require CGI.pl" to import
# relevant functions from that script and its companion globals.pl. # relevant functions from that script and its companion globals.pl.
...@@ -99,16 +89,13 @@ sub list ...@@ -99,16 +89,13 @@ sub list
push @attachments, \%a; push @attachments, \%a;
} }
my $vars = $vars->{'bugid'} = $bugid;
{ $vars->{'attachments'} = \@attachments;
'bugid' => $bugid ,
'attachments' => \@attachments ,
'Param' => \&::Param , # for retrieving global parameters
'PerformSubsts' => \&::PerformSubsts # for processing global parameters
};
$template->process("attachment/list.atml", $vars) $template->process("attachment/list.atml", $vars)
|| &::DisplayError("Template process failed: " . $template->error()) || &::DisplayError("Template process failed: " . $template->error())
&& exit; && exit;
} }
1;
...@@ -27,25 +27,15 @@ ...@@ -27,25 +27,15 @@
use diagnostics; use diagnostics;
use strict; use strict;
use vars qw(
$template
$vars
);
package Attachment; package Attachment;
# Use the template toolkit (http://www.template-toolkit.org/) to generate my $template = $::template;
# the user interface (HTML pages and mail messages) using templates in the my $vars = $::vars;
# "templates/" subdirectory.
use Template;
# This is the global template object that gets used one or more times by
# the script when it needs to process a template and return the results.
# Configuration parameters can be specified here that apply to all templates
# processed in this file.
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => 'template/custom:template/default' ,
# Allow templates to be specified with relative paths.
RELATIVE => 1
}
);
# This module requires that its caller have said "require CGI.pl" to import # This module requires that its caller have said "require CGI.pl" to import
# relevant functions from that script and its companion globals.pl. # relevant functions from that script and its companion globals.pl.
...@@ -99,16 +89,13 @@ sub list ...@@ -99,16 +89,13 @@ sub list
push @attachments, \%a; push @attachments, \%a;
} }
my $vars = $vars->{'bugid'} = $bugid;
{ $vars->{'attachments'} = \@attachments;
'bugid' => $bugid ,
'attachments' => \@attachments ,
'Param' => \&::Param , # for retrieving global parameters
'PerformSubsts' => \&::PerformSubsts # for processing global parameters
};
$template->process("attachment/list.atml", $vars) $template->process("attachment/list.atml", $vars)
|| &::DisplayError("Template process failed: " . $template->error()) || &::DisplayError("Template process failed: " . $template->error())
&& exit; && exit;
} }
1;
...@@ -31,41 +31,17 @@ use strict; ...@@ -31,41 +31,17 @@ use strict;
use lib qw(.); use lib qw(.);
use vars qw(
$template
$vars
);
# Include the Bugzilla CGI and general utility library. # Include the Bugzilla CGI and general utility library.
require "CGI.pl"; require "CGI.pl";
# Establish a connection to the database backend. # Establish a connection to the database backend.
ConnectToDatabase(); ConnectToDatabase();
# Use the template toolkit (http://www.template-toolkit.org/) to generate
# the user interface (HTML pages and mail messages) using templates in the
# "template/" subdirectory.
use Template;
# Create the global template object that processes templates and specify
# configuration parameters that apply to all templates processed in this script.
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => "template/custom:template/default" ,
# Allow templates to be specified with relative paths.
RELATIVE => 1
}
);
# Define the global variables and functions that will be passed to the UI
# template. Individual functions add their own values to this hash before
# sending them to the templates they process.
my $vars =
{
# Function for retrieving global parameters.
'Param' => \&Param ,
# Function for processing global parameters that contain references
# to other global parameters.
'PerformSubsts' => \&PerformSubsts
};
# Check whether or not the user is logged in and, if so, set the $::userid # Check whether or not the user is logged in and, if so, set the $::userid
# and $::usergroupset variables. # and $::usergroupset variables.
quietly_check_login(); quietly_check_login();
......
...@@ -25,45 +25,15 @@ use strict; ...@@ -25,45 +25,15 @@ use strict;
use lib qw(.); use lib qw(.);
sub sillyness { # shut up "used only once" warnings use vars qw(
my $zz = @::legal_keywords; @legal_keywords
$zz = $::buffer; $buffer
} $template
$vars
);
require "CGI.pl"; require "CGI.pl";
# Use the template toolkit (http://www.template-toolkit.org/) to generate
# the user interface (HTML pages and mail messages) using templates in the
# "template/" subdirectory.
use Template;
# Create the global template object that processes templates and specify
# configuration parameters that apply to all templates processed in this script.
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => "template/custom:template/default",
# Allow templates to be specified with relative paths.
RELATIVE => 1,
PRE_CHOMP => 1,
});
# Define the global variables and functions that will be passed to the UI
# template. Individual functions add their own values to this hash before
# sending them to the templates they process.
my $vars =
{
# Function for retrieving global parameters.
'Param' => \&Param,
# Function for processing global parameters that contain references
# to other global parameters.
'PerformSubsts' => \&PerformSubsts,
# Function to search an array for a value
'lsearch' => \&lsearch,
};
print "Content-type: text/html\n"; print "Content-type: text/html\n";
# The master list not only says what fields are possible, but what order # The master list not only says what fields are possible, but what order
......
...@@ -32,27 +32,11 @@ use lib qw(.); ...@@ -32,27 +32,11 @@ use lib qw(.);
require "CGI.pl"; require "CGI.pl";
# Shut up misguided -w warnings about "used only once": # Shut up misguided -w warnings about "used only once":
use vars %::FORM; use vars qw(
%FORM
# Use the template toolkit (http://www.template-toolkit.org/) $template
use Template; $vars
);
# Create the global template object that processes templates
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => "template/custom:template/default",
RELATIVE => 1,
PRE_CHOMP => 1,
});
# Define the global variables and functions that will be passed to the UI
# template.
my $vars =
{
'Param' => \&Param,
'PerformSubsts' => \&PerformSubsts,
};
ConnectToDatabase(); ConnectToDatabase();
......
...@@ -29,41 +29,17 @@ ...@@ -29,41 +29,17 @@
use diagnostics; use diagnostics;
use strict; use strict;
use vars qw(
$template
$vars
);
# Include the Bugzilla CGI and general utility library. # Include the Bugzilla CGI and general utility library.
require "CGI.pl"; require "CGI.pl";
# Establish a connection to the database backend. # Establish a connection to the database backend.
ConnectToDatabase(); ConnectToDatabase();
# Use the template toolkit (http://www.template-toolkit.org/) to generate
# the user interface (HTML pages and mail messages) using templates in the
# "template/" subdirectory.
use Template;
# Create the global template object that processes templates and specify
# configuration parameters that apply to all templates processed in this script.
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => "template/custom:template/default" ,
# Allow templates to be specified with relative paths.
RELATIVE => 1
}
);
# Define the global variables and functions that will be passed to the UI
# template. Individual functions add their own values to this hash before
# sending them to the templates they process.
my $vars =
{
# Function for retrieving global parameters.
'Param' => \&Param ,
# Function for processing global parameters that contain references
# to other global parameters.
'PerformSubsts' => \&PerformSubsts
};
# Make sure the user is logged in and is allowed to edit products # Make sure the user is logged in and is allowed to edit products
# (i.e. the user has "editcomponents" privileges), since attachment # (i.e. the user has "editcomponents" privileges), since attachment
# statuses are product-specific. # statuses are product-specific.
......
...@@ -51,10 +51,6 @@ use vars qw( ...@@ -51,10 +51,6 @@ use vars qw(
%MFORM %MFORM
); );
# Use template variables
my $template = $::template;
my $vars = $::vars;
# If we're using bug groups to restrict bug entry, we need to know who the # If we're using bug groups to restrict bug entry, we need to know who the
# user is right from the start. # user is right from the start.
confirm_login() if (Param("usebuggroupsentry")); confirm_login() if (Param("usebuggroupsentry"));
......
...@@ -1578,9 +1578,6 @@ $::template = Template->new( ...@@ -1578,9 +1578,6 @@ $::template = Template->new(
# Colon-separated list of directories containing templates. # Colon-separated list of directories containing templates.
INCLUDE_PATH => "template/custom:template/default" , INCLUDE_PATH => "template/custom:template/default" ,
# Allow templates to be specified with relative paths.
RELATIVE => 1 ,
# 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
# looking, more compact content. Use the plus sign at the beginning # looking, more compact content. Use the plus sign at the beginning
...@@ -1593,6 +1590,17 @@ $::template = Template->new( ...@@ -1593,6 +1590,17 @@ $::template = Template->new(
{ {
# Render text in strike-through style. # Render text in strike-through style.
strike => sub { return "<strike>" . $_[0] . "</strike>" } , strike => sub { return "<strike>" . $_[0] . "</strike>" } ,
# Returns the text with backslashes, single/double quotes,
# and newlines/carriage returns escaped for use in JS strings.
js => sub
{
my ($var) = @_;
$var =~ s/([\\\'\"])/\\$1/g;
$var =~ s/\n/\\n/g;
$var =~ s/\r/\\r/g;
return $var;
}
} , } ,
} }
); );
...@@ -1652,6 +1660,9 @@ $::vars = ...@@ -1652,6 +1660,9 @@ $::vars =
# Function for processing global parameters that contain references # Function for processing global parameters that contain references
# to other global parameters. # to other global parameters.
'PerformSubsts' => \&PerformSubsts , 'PerformSubsts' => \&PerformSubsts ,
# Generic linear search function
'lsearch' => \&lsearch ,
}; };
1; 1;
...@@ -37,38 +37,13 @@ use strict; ...@@ -37,38 +37,13 @@ use strict;
use lib "."; use lib ".";
require "CGI.pl"; require "CGI.pl";
# Establish a connection to the database backend. use vars qw(
ConnectToDatabase(); $template
$vars
# Use the template toolkit (http://www.template-toolkit.org/) to generate
# the user interface (HTML pages and mail messages) using templates in the
# "template/" subdirectory.
use Template;
# Create the global template object that processes templates and specify
# configuration parameters that apply to all templates processed in this script.
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => "template/custom:template/default",
# Allow templates to be specified with relative paths.
RELATIVE => 1,
POST_CHOMP => 1,
}
); );
# Define the global variables and functions that will be passed to the UI # Establish a connection to the database backend.
# template. Individual functions add their own values to this hash before ConnectToDatabase();
# sending them to the templates they process.
my $vars =
{
# Function for retrieving global parameters.
'Param' => \&Param ,
# Function for processing global parameters that contain references
# to other global parameters.
'PerformSubsts' => \&PerformSubsts
};
# Check whether or not the user is logged in and, if so, set the $::userid # Check whether or not the user is logged in and, if so, set the $::userid
# and $::usergroupset variables. # and $::usergroupset variables.
......
...@@ -34,68 +34,26 @@ require "CGI.pl"; ...@@ -34,68 +34,26 @@ require "CGI.pl";
# that no longer exist), since we don't want to die in the query page. # that no longer exist), since we don't want to die in the query page.
$::CheckOptionValues = 0; $::CheckOptionValues = 0;
use vars use vars qw(
@::CheckOptionValues, @CheckOptionValues
@::legal_resolution, @legal_resolution
@::legal_bug_status, @legal_bug_status
@::legal_components, @legal_components
@::legal_keywords, @legal_keywords
@::legal_opsys, @legal_opsys
@::legal_platform, @legal_platform
@::legal_priority, @legal_priority
@::legal_product, @legal_product
@::legal_severity, @legal_severity
@::legal_target_milestone, @legal_target_milestone
@::legal_versions, @legal_versions
@::log_columns, @log_columns
%::versions, %versions
%::components, %components
%::FORM; %FORM
$template
# Use the template toolkit (http://www.template-toolkit.org/) to generate $vars
# the user interface (HTML pages and mail messages) using templates in the );
# "template/" subdirectory.
use Template;
# Create the global template object that processes templates and specify
# configuration parameters that apply to all templates processed in this script.
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => "template/custom:template/default",
# Allow templates to be specified with relative paths.
RELATIVE => 1,
PRE_CHOMP => 1,
FILTERS =>
{
# Returns the text with backslashes, single/double quotes,
# and newlines/carriage returns escaped for use in JS strings.
'js' => sub
{
my ($var) = @_;
$var =~ s/([\\\'\"])/\\$1/g;
$var =~ s/\n/\\n/g;
$var =~ s/\r/\\r/g;
return $var;
}
},
});
# Define the global variables and functions that will be passed to the UI
# template. Individual functions add their own values to this hash before
# sending them to the templates they process.
my $vars =
{
# Function for retrieving global parameters.
'Param' => \&Param,
# Function for processing global parameters that contain references
# to other global parameters.
'PerformSubsts' => \&PerformSubsts,
# Function to search an array for a value
'lsearch' => \&lsearch,
};
if (defined $::FORM{"GoAheadAndLogIn"}) { if (defined $::FORM{"GoAheadAndLogIn"}) {
# We got here from a login page, probably from relogin.cgi. We better # We got here from a login page, probably from relogin.cgi. We better
......
...@@ -23,31 +23,17 @@ ...@@ -23,31 +23,17 @@
use diagnostics; use diagnostics;
use strict; use strict;
use vars ( %::FORM );
use vars qw(
%FORM
$template
$vars
);
use lib qw(.); use lib qw(.);
require "CGI.pl"; require "CGI.pl";
# Use the template toolkit (http://www.template-toolkit.org/)
use Template;
# Create the global template object that processes templates
my $template = Template->new(
{
INCLUDE_PATH => "template/custom:template/default",
RELATIVE => 1,
PRE_CHOMP => 1,
});
# Define the global variables and functions that will be passed to the UI
# template.
my $vars =
{
'Param' => \&Param,
'PerformSubsts' => \&PerformSubsts,
};
my $action = $::FORM{'action'} || ""; my $action = $::FORM{'action'} || "";
if ($action eq "show") { if ($action eq "show") {
......
...@@ -22,39 +22,13 @@ use lib "."; ...@@ -22,39 +22,13 @@ use lib ".";
require "CGI.pl"; require "CGI.pl";
# Shut up "Used Only Once" errors # Shut up "Used Only Once" errors
use vars qw { $anyvotesallowed }; use vars qw(
$anyvotesallowed
ConnectToDatabase(); $template
$vars
# Use the template toolkit (http://www.template-toolkit.org/) to generate
# the user interface (HTML pages and mail messages) using templates in the
# "template/" subdirectory.
use Template;
# Create the global template object that processes templates and specify
# configuration parameters that apply to all templates processed in this script.
my $template = Template->new(
{
# Colon-separated list of directories containing templates.
INCLUDE_PATH => "template/custom:template/default",
# Allow templates to be specified with relative paths.
RELATIVE => 1,
POST_CHOMP =>1,
}
); );
# Define the global variables and functions that will be passed to the UI ConnectToDatabase();
# template. Individual functions add their own values to this hash before
# sending them to the templates they process.
my $vars =
{
# Function for retrieving global parameters.
'Param' => \&Param ,
# Function that tells us if the logged in user is in a specific group.
'UserInGroup' => \&UserInGroup ,
};
# Needed for $::anyvotesallowed # Needed for $::anyvotesallowed
GetVersionTable(); GetVersionTable();
......
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