summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbbaetz%student.usyd.edu.au <>2002-02-13 11:27:20 +0100
committerbbaetz%student.usyd.edu.au <>2002-02-13 11:27:20 +0100
commite1235d08fc52ff4cb914efecda9b15c2b7943f5a (patch)
tree2673752da715c22fabf9bacc440e48a943afeb82
parent5938698d13c326114857aaebb34a0f7081e1d486 (diff)
downloadbugzilla-e1235d08fc52ff4cb914efecda9b15c2b7943f5a.tar.gz
bugzilla-e1235d08fc52ff4cb914efecda9b15c2b7943f5a.tar.xz
Bug 100094 - use generic template handling code
r=mattyt, afranke
-rw-r--r--Attachment.pm35
-rw-r--r--Bugzilla/Attachment.pm35
-rwxr-xr-xattachment.cgi34
-rwxr-xr-xcolchange.cgi42
-rwxr-xr-xcreateaccount.cgi26
-rwxr-xr-xeditattachstatuses.cgi34
-rwxr-xr-xenter_bug.cgi4
-rw-r--r--globals.pl17
-rwxr-xr-xindex.cgi35
-rwxr-xr-xquery.cgi82
-rwxr-xr-xquips.cgi26
-rwxr-xr-xsidebar.cgi36
12 files changed, 93 insertions, 313 deletions
diff --git a/Attachment.pm b/Attachment.pm
index 4b4b19ec3..1b6d74062 100644
--- a/Attachment.pm
+++ b/Attachment.pm
@@ -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;
diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm
index 4b4b19ec3..1b6d74062 100644
--- a/Bugzilla/Attachment.pm
+++ b/Bugzilla/Attachment.pm
@@ -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;
diff --git a/attachment.cgi b/attachment.cgi
index f58844835..ea17c29e5 100755
--- a/attachment.cgi
+++ b/attachment.cgi
@@ -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();
diff --git a/colchange.cgi b/colchange.cgi
index 5d3222afc..f2ac55aa9 100755
--- a/colchange.cgi
+++ b/colchange.cgi
@@ -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
diff --git a/createaccount.cgi b/createaccount.cgi
index 86a994483..ecf3a68f6 100755
--- a/createaccount.cgi
+++ b/createaccount.cgi
@@ -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();
diff --git a/editattachstatuses.cgi b/editattachstatuses.cgi
index 6596a79c9..0642d6bb8 100755
--- a/editattachstatuses.cgi
+++ b/editattachstatuses.cgi
@@ -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.
diff --git a/enter_bug.cgi b/enter_bug.cgi
index eea2947bd..0ab18d9a9 100755
--- a/enter_bug.cgi
+++ b/enter_bug.cgi
@@ -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"));
diff --git a/globals.pl b/globals.pl
index f88347f13..e1f3302f3 100644
--- a/globals.pl
+++ b/globals.pl
@@ -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;
diff --git a/index.cgi b/index.cgi
index 5c300992d..2fe393391 100755
--- a/index.cgi
+++ b/index.cgi
@@ -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.
diff --git a/query.cgi b/query.cgi
index 3149d07b7..b41620d36 100755
--- a/query.cgi
+++ b/query.cgi
@@ -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
diff --git a/quips.cgi b/quips.cgi
index f1a41b4b9..1b5213e97 100755
--- a/quips.cgi
+++ b/quips.cgi
@@ -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") {
diff --git a/sidebar.cgi b/sidebar.cgi
index 073a1ecff..385086b5b 100755
--- a/sidebar.cgi
+++ b/sidebar.cgi
@@ -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();