]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 100094 - use generic template handling code
authorbbaetz%student.usyd.edu.au <>
Wed, 13 Feb 2002 10:27:20 +0000 (10:27 +0000)
committerbbaetz%student.usyd.edu.au <>
Wed, 13 Feb 2002 10:27:20 +0000 (10:27 +0000)
r=mattyt, afranke

12 files changed:
Attachment.pm
Bugzilla/Attachment.pm
attachment.cgi
colchange.cgi
createaccount.cgi
editattachstatuses.cgi
enter_bug.cgi
globals.pl
index.cgi
query.cgi
quips.cgi
sidebar.cgi

index 4b4b19ec326a005b8e1527dd338c550cd537587c..1b6d74062e08a16898f05e7640b1af3841860f7d 100644 (file)
 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;
index 4b4b19ec326a005b8e1527dd338c550cd537587c..1b6d74062e08a16898f05e7640b1af3841860f7d 100644 (file)
 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;
index f58844835b485c0ce2436d734d44b909f56b0080..ea17c29e5e261e3c69988d6f6ffba85a2b7f50fe 100755 (executable)
@@ -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();
index 5d3222afcb9efebcba0a578c6e46707fbcd25317..f2ac55aa9ad8d3d1a0212c578c17e8ad288974e8 100755 (executable)
@@ -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
index 86a994483cd2d6941f05d33c9085b5d59813c96c..ecf3a68f67b1bd27273bd41f138375aff35ac0c4 100755 (executable)
@@ -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();
 
index 6596a79c991eac99354185fb13f99f16a4747b60..0642d6bb8f67029f95de1fed2e0537ae24f5c4f3 100755 (executable)
 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.
index eea2947bd5870919c53118a514bbb1cd90be7236..0ab18d9a902dbda48794a5217288ff865ed73b7d 100755 (executable)
@@ -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"));
index f88347f13d88c40d6fe97340fb57c0a4a85c028c..e1f3302f3d7ef08556161c914912c3848f033fd9 100644 (file)
@@ -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;
index 5c300992dbd471129237713e1b35b01f2d8cca2b..2fe393391128307650a01acf6265f96ed9284140 100755 (executable)
--- 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.
index 3149d07b7ab51b09759e232452f82fe99c0edb8f..b41620d3639eb558c306e377c9b07ef2c7100845 100755 (executable)
--- 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
index f1a41b4b944136dce0737cfefd951c219d120429..1b5213e978edb2699177fadf02e73216bfc42d12 100755 (executable)
--- a/quips.cgi
+++ b/quips.cgi
 
 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") {
index 073a1ecffcafa112de0ae14f7ae30c79ecb4185f..385086b5bc737250e7c55a23183a43a29dd9a56e 100755 (executable)
@@ -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();