Bug 100094 - use generic template handling code

r=mattyt, afranke
parent 5938698d
......@@ -27,25 +27,15 @@
use diagnostics;
use strict;
use vars qw(
$template
$vars
);
package Attachment;
# Use the template toolkit (http://www.template-toolkit.org/) to generate
# the user interface (HTML pages and mail messages) using templates in the
# "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
}
);
my $template = $::template;
my $vars = $::vars;
# This module requires that its caller have said "require CGI.pl" to import
# relevant functions from that script and its companion globals.pl.
......@@ -99,16 +89,13 @@ sub list
push @attachments, \%a;
}
my $vars =
{
'bugid' => $bugid ,
'attachments' => \@attachments ,
'Param' => \&::Param , # for retrieving global parameters
'PerformSubsts' => \&::PerformSubsts # for processing global parameters
};
$vars->{'bugid'} = $bugid;
$vars->{'attachments'} = \@attachments;
$template->process("attachment/list.atml", $vars)
|| &::DisplayError("Template process failed: " . $template->error())
&& exit;
}
1;
......@@ -27,25 +27,15 @@
use diagnostics;
use strict;
use vars qw(
$template
$vars
);
package Attachment;
# Use the template toolkit (http://www.template-toolkit.org/) to generate
# the user interface (HTML pages and mail messages) using templates in the
# "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
}
);
my $template = $::template;
my $vars = $::vars;
# This module requires that its caller have said "require CGI.pl" to import
# relevant functions from that script and its companion globals.pl.
......@@ -99,16 +89,13 @@ sub list
push @attachments, \%a;
}
my $vars =
{
'bugid' => $bugid ,
'attachments' => \@attachments ,
'Param' => \&::Param , # for retrieving global parameters
'PerformSubsts' => \&::PerformSubsts # for processing global parameters
};
$vars->{'bugid'} = $bugid;
$vars->{'attachments'} = \@attachments;
$template->process("attachment/list.atml", $vars)
|| &::DisplayError("Template process failed: " . $template->error())
&& exit;
}
1;
......@@ -31,41 +31,17 @@ use strict;
use lib qw(.);
use vars qw(
$template
$vars
);
# Include the Bugzilla CGI and general utility library.
require "CGI.pl";
# Establish a connection to the database backend.
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
# and $::usergroupset variables.
quietly_check_login();
......
......@@ -25,45 +25,15 @@ use strict;
use lib qw(.);
sub sillyness { # shut up "used only once" warnings
my $zz = @::legal_keywords;
$zz = $::buffer;
}
use vars qw(
@legal_keywords
$buffer
$template
$vars
);
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";
# The master list not only says what fields are possible, but what order
......
......@@ -32,27 +32,11 @@ use lib qw(.);
require "CGI.pl";
# Shut up misguided -w warnings about "used only once":
use vars %::FORM;
# Use the template toolkit (http://www.template-toolkit.org/)
use Template;
# 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,
};
use vars qw(
%FORM
$template
$vars
);
ConnectToDatabase();
......
......@@ -29,41 +29,17 @@
use diagnostics;
use strict;
use vars qw(
$template
$vars
);
# Include the Bugzilla CGI and general utility library.
require "CGI.pl";
# Establish a connection to the database backend.
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
# (i.e. the user has "editcomponents" privileges), since attachment
# statuses are product-specific.
......
......@@ -51,10 +51,6 @@ use vars qw(
%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
# user is right from the start.
confirm_login() if (Param("usebuggroupsentry"));
......
......@@ -1578,9 +1578,6 @@ $::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 ,
# Remove white-space before template directives (PRE_CHOMP) and at the
# beginning and end of templates and template blocks (TRIM) for better
# looking, more compact content. Use the plus sign at the beginning
......@@ -1593,6 +1590,17 @@ $::template = Template->new(
{
# Render text in strike-through style.
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 =
# Function for processing global parameters that contain references
# to other global parameters.
'PerformSubsts' => \&PerformSubsts ,
# Generic linear search function
'lsearch' => \&lsearch ,
};
1;
......@@ -37,38 +37,13 @@ use strict;
use lib ".";
require "CGI.pl";
# Establish a connection to the database backend.
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,
POST_CHOMP => 1,
}
use vars qw(
$template
$vars
);
# 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
};
# Establish a connection to the database backend.
ConnectToDatabase();
# Check whether or not the user is logged in and, if so, set the $::userid
# and $::usergroupset variables.
......
......@@ -34,68 +34,26 @@ require "CGI.pl";
# that no longer exist), since we don't want to die in the query page.
$::CheckOptionValues = 0;
use vars
@::CheckOptionValues,
@::legal_resolution,
@::legal_bug_status,
@::legal_components,
@::legal_keywords,
@::legal_opsys,
@::legal_platform,
@::legal_priority,
@::legal_product,
@::legal_severity,
@::legal_target_milestone,
@::legal_versions,
@::log_columns,
%::versions,
%::components,
%::FORM;
# 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,
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,
};
use vars qw(
@CheckOptionValues
@legal_resolution
@legal_bug_status
@legal_components
@legal_keywords
@legal_opsys
@legal_platform
@legal_priority
@legal_product
@legal_severity
@legal_target_milestone
@legal_versions
@log_columns
%versions
%components
%FORM
$template
$vars
);
if (defined $::FORM{"GoAheadAndLogIn"}) {
# We got here from a login page, probably from relogin.cgi. We better
......
......@@ -23,31 +23,17 @@
use diagnostics;
use strict;
use vars ( %::FORM );
use vars qw(
%FORM
$template
$vars
);
use lib qw(.);
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'} || "";
if ($action eq "show") {
......
......@@ -22,39 +22,13 @@ use lib ".";
require "CGI.pl";
# Shut up "Used Only Once" errors
use vars qw { $anyvotesallowed };
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,
POST_CHOMP =>1,
}
use vars qw(
$anyvotesallowed
$template
$vars
);
# 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 that tells us if the logged in user is in a specific group.
'UserInGroup' => \&UserInGroup ,
};
ConnectToDatabase();
# Needed for $::anyvotesallowed
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