]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Fix for bug 121747: Stops every script before it does anything else if Bugzilla is...
authormyk%mozilla.org <>
Sun, 3 Feb 2002 17:27:02 +0000 (17:27 +0000)
committermyk%mozilla.org <>
Sun, 3 Feb 2002 17:27:02 +0000 (17:27 +0000)
instantiation code to globals.pl.
Patch by Myk Melez <myk@mozilla.org>.
r=gerv,kiko

CGI.pl
globals.pl
template/default/global/header
template/default/global/message.html.tmpl [new file with mode: 0644]

diff --git a/CGI.pl b/CGI.pl
index eb8f5f03725907f372490d7df2b87c8e602df76b..f99013e25d720fd003e47163a9be9fb7ef3bcb8b 100644 (file)
--- a/CGI.pl
+++ b/CGI.pl
@@ -52,6 +52,25 @@ use CGI::Carp qw(fatalsToBrowser);
 
 require 'globals.pl';
 
+# If Bugzilla is shut down, do not go any further, just display a message
+# to the user about the downtime.  (do)editparams.cgi is exempted from
+# this message, of course, since it needs to be available in order for
+# the administrator to open Bugzilla back up.
+if (Param("shutdownhtml") && $0 !~ m:[\\/](do)?editparams.cgi$:) {
+    # The shut down message we are going to display to the user.
+    $::vars->{'title'} = "Bugzilla is Down";
+    $::vars->{'h1'} = "Bugzilla is Down";
+    $::vars->{'message'} = Param("shutdownhtml");
+    
+    # Return the appropriate HTTP response headers.
+    print "Content-Type: text/html\n\n";
+    
+    # Generate and return an HTML message about the downtime.
+    $::template->process("global/message.html.tmpl", $::vars)
+      || DisplayError("Template process failed: " . $::template->error());
+    exit;
+}
+
 sub GeneratePersonInput {
     my ($field, $required, $def_value, $extraJavaScript) = (@_);
     $extraJavaScript ||= "";
@@ -1110,16 +1129,6 @@ sub PutHeader {
        $extra = "";
     }
     $jscript ||= "";
-    # If we are shutdown, we want a very basic page to give that
-    # information.  Also, the page title should indicate that
-    # we are down.  
-    if (Param('shutdownhtml')) {
-        $title = "Bugzilla is Down";
-        $h1 = "Bugzilla is currently down";
-        $h2 = "";
-        $extra = "";
-        $jscript = "";
-    }
 
     print qq|
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
index 86478b03c5f4cc0497ed3121c8ff817921680f4c..cc05ae345146fc034ca36a1673dece0e1f4dc493 100644 (file)
@@ -53,6 +53,8 @@ sub globals_pl_sillyness {
     $zz = @main::prodmaxvotes;
     $zz = $main::superusergroupset;
     $zz = $main::userid;
+    $zz = $main::template;
+    $zz = $main::vars;
 }
 
 #
@@ -1549,4 +1551,94 @@ sub trim {
     return $str;
 }
 
+###############################################################################
+# Global Templatization Code
+
+# Use the template toolkit (http://www.template-toolkit.org/) to generate
+# the user interface 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.
+$::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 
+    # of directives to maintain white space (i.e. [%+ DIRECTIVE %]).
+    PRE_CHOMP => 1 ,
+    TRIM => 1 , 
+
+    # Functions for processing text within templates in various ways.
+    FILTERS =>
+      {
+        # Render text in strike-through style.
+        strike => sub { return "<strike>" . $_[0] . "</strike>" } ,
+      } ,
+  }
+);
+
+# Use the Toolkit Template's Stash module to add utility pseudo-methods
+# to template variables.
+use Template::Stash;
+
+# Add "contains***" methods to list variables that search for one or more 
+# items in a list and return boolean values representing whether or not 
+# one/all/any item(s) were found.
+$Template::Stash::LIST_OPS->{ contains } =
+  sub {
+      my ($list, $item) = @_;
+      return grep($_ eq $item, @$list);
+  };
+
+$Template::Stash::LIST_OPS->{ containsany } =
+  sub {
+      my ($list, $items) = @_;
+      foreach my $item (@$items) { 
+          return 1 if grep($_ eq $item, @$list);
+      }
+      return 0;
+  };
+
+# Add a "substr" method to the Template Toolkit's "scalar" object
+# that returns a substring of a string.
+$Template::Stash::SCALAR_OPS->{ substr } = 
+  sub {
+      my ($scalar, $offset, $length) = @_;
+      return substr($scalar, $offset, $length);
+  };
+    
+# Add a "truncate" method to the Template Toolkit's "scalar" object
+# that truncates a string to a certain length.
+$Template::Stash::SCALAR_OPS->{ truncate } = 
+  sub {
+      my ($string, $length, $ellipsis) = @_;
+      $ellipsis ||= "";
+      
+      return $string if !$length || length($string) <= $length;
+      
+      my $strlen = $length - length($ellipsis);
+      my $newstr = substr($string, 0, $strlen) . $ellipsis;
+      return $newstr;
+  };
+    
+# Define the global variables and functions that will be passed to the UI
+# template.  Additional values may be added to this hash before templates
+# are processed.
+$::vars =
+  {
+    # Function for retrieving global parameters.
+    'Param' => \&Param ,
+
+    # Function for processing global parameters that contain references
+    # to other global parameters.
+    'PerformSubsts' => \&PerformSubsts ,
+  };
+
 1;
index 1efdbf51c21a67cfd2bd960ba77fd51bcd2a6100..627a525718d05e698dd387fe4da3297aa18ec013 100755 (executable)
     </table>
 [% END %]
 
-    [% IF message %]
-      <table width="100%" cellspacing="0" cellpadding="5" border="1"><tr><td>
-        <font color="green">[% message %]</font>
-      </td></tr></table>
-    [% END %]
-
-    [% Param('shutdownhtml') %]
-
+[% IF message %]
+  <table width="100%" cellspacing="0" cellpadding="5" border="1"><tr><td>
+    <font color="green">[% message %]</font>
+  </td></tr></table>
+[% END %]
diff --git a/template/default/global/message.html.tmpl b/template/default/global/message.html.tmpl
new file mode 100644 (file)
index 0000000..0325324
--- /dev/null
@@ -0,0 +1,16 @@
+[% DEFAULT title = "Bugzilla Message" %]
+
+[% INCLUDE global/header title=title %]
+
+[%# The "header" template automatically displays the contents of a "message"
+    variable if it finds one, so it is not necessary to display the message
+    here. %]
+
+[%# Display a URL if the calling script has included one. %]
+[% IF url && link %]
+  <p>
+    <a href="[% url %]">[% link %]</a>
+  </p>
+[% END %]
+
+[% INCLUDE global/footer %]