]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 283989: CGI.pl global init code should be moved to Bugzilla::CGI
authormkanat%kerio.com <>
Thu, 14 Jul 2005 13:01:34 +0000 (13:01 +0000)
committermkanat%kerio.com <>
Thu, 14 Jul 2005 13:01:34 +0000 (13:01 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=wurblzap, a=justdave

Bugzilla.pm
Bugzilla/CGI.pm
Bugzilla/Util.pm
CGI.pl
template/en/default/global/message.txt.tmpl [new file with mode: 0644]

index 0deb6e16e56e1ac328f6008c21e05df1275d9e85..d3b1a59709fff098a64949dfb24deb06f6c5f0f2 100644 (file)
@@ -33,6 +33,59 @@ use Bugzilla::Constants;
 use Bugzilla::DB;
 use Bugzilla::Template;
 use Bugzilla::User;
+use Bugzilla::Error;
+use Bugzilla::Util;
+
+use File::Basename;
+
+#####################################################################
+# Constants
+#####################################################################
+
+# Scripts that are not stopped by shutdownhtml being in effect.
+use constant SHUTDOWNHTML_EXEMPT => [
+    'doeditparams.cgi',
+    'editparams.cgi',
+    'checksetup.pl',
+];
+
+#####################################################################
+# Global Code
+#####################################################################
+
+# If Bugzilla is shut down, do not allow anything to run, just display a
+# message to the user about the downtime.  Scripts listed in 
+# SHUTDOWNHTML_EXEMPT are exempt from this message.
+#
+# This code must go here. It cannot go anywhere in Bugzilla::CGI, because
+# it uses Template, and that causes various dependency loops.
+if (Param("shutdownhtml") 
+    && lsearch(SHUTDOWNHTML_EXEMPT, basename($0)) == -1) 
+{
+    my $template = Bugzilla->template;
+    my $vars = {};
+    $vars->{'message'} = 'shutdown';
+    # Generate and return a message about the downtime, appropriately
+    # for if we're a command-line script or a CGI sript.
+    my $extension;
+    if (i_am_cgi() && (!Bugzilla->cgi->param('format') 
+                       || Bugzilla->cgi->param('format') eq 'html')) {
+        $extension = 'html';
+    }
+    else {
+        $extension = 'txt';
+    }
+    print Bugzilla->cgi->header() if i_am_cgi();
+    my $t_output;
+    $template->process("global/message.$extension.tmpl", $vars, \$t_output)
+        || ThrowTemplateError($template->error);
+    print $t_output . "\n";
+    exit;
+}
+
+#####################################################################
+# Subroutines and Methods
+#####################################################################
 
 my $_template;
 sub template {
index 6f5a6f6d75c6b8568b6c83770f1f482120206849..c2d61780fb7dbfb4696e42b5b02fbe32dc20623e 100644 (file)
@@ -25,9 +25,18 @@ use strict;
 
 package Bugzilla::CGI;
 
+BEGIN {
+    if ($^O =~ /MSWin32/i) {
+        # Help CGI find the correct temp directory as the default list
+        # isn't Windows friendly (Bug 248988)
+        $ENV{'TMPDIR'} = $ENV{'TEMP'} || $ENV{'TMP'} || "$ENV{'WINDIR'}\\TEMP";
+    }
+}
+
 use CGI qw(-no_xhtml -oldstyle_urls :private_tempfiles :unique_headers SERVER_PUSH);
 
 use base qw(CGI);
+use CGI::Carp qw(fatalsToBrowser);
 
 use Bugzilla::Error;
 use Bugzilla::Util;
index 83c9bf7d3fe29c51fbc2a8062a21ef2267cd7c4f..1ac25d1aa3a33d21b1e60e4db5a999ef91ae366a 100644 (file)
@@ -33,6 +33,7 @@ use base qw(Exporter);
                              detaint_signed
                              html_quote url_quote value_quote xml_quote
                              css_class_quote
+                             i_am_cgi
                              lsearch max min
                              diff_arrays diff_strings
                              trim wrap_comment find_wrap_point
@@ -130,6 +131,12 @@ sub xml_quote {
     return $var;
 }
 
+sub i_am_cgi () {
+    # I use SERVER_SOFTWARE because it's required to be
+    # defined for all requests in the CGI spec.
+    return exists $ENV{'SERVER_SOFTWARE'} ? 1 : 0;
+}
+
 sub lsearch {
     my ($list,$item) = (@_);
     my $count = 0;
@@ -376,6 +383,9 @@ Bugzilla::Util - Generic utility functions for bugzilla
   value_quote($var);
   xml_quote($var);
 
+  # Functions that tell you about your environment
+  my $is_cgi = i_am_cgi();
+
   # Functions for searching
   $loc = lsearch(\@arr, $val);
   $val = max($a, $b, $c);
@@ -480,6 +490,12 @@ This is similar to C<html_quote>, except that ' is escaped to &apos;. This
 is kept separate from html_quote partly for compatibility with previous code
 (for &apos;) and partly for future handling of non-ASCII characters.
 
+=item C<i_am_cgi()>
+
+Tells you whether or not you are being run as a CGI script in a web
+server. For example, it would return false if the caller is running
+in a command-line script.
+
 =back
 
 =head2 Searching
diff --git a/CGI.pl b/CGI.pl
index 73df776954dbd81d1da3afed0ad3641c373e452a..78ef20fef0d03017644c7aee33770eab3b23383b 100644 (file)
--- a/CGI.pl
+++ b/CGI.pl
@@ -32,14 +32,6 @@ use lib ".";
 
 # use Carp;                       # for confess
 
-BEGIN {
-    if ($^O =~ /MSWin32/i) {
-        # Help CGI find the correct temp directory as the default list
-        # isn't Windows friendly (Bug 248988)
-        $ENV{'TMPDIR'} = $ENV{'TEMP'} || $ENV{'TMP'} || "$ENV{'WINDIR'}\\TEMP";
-    }
-}
-
 use Bugzilla::Util;
 use Bugzilla::Config;
 use Bugzilla::Constants;
@@ -60,28 +52,10 @@ sub CGI_pl_sillyness {
     $zz = $::buffer;
 }
 
-use CGI::Carp qw(fatalsToBrowser);
-
 require 'globals.pl';
 
 use vars qw($template $vars);
 
-# 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$:) {
-    $::vars->{'message'} = "shutdown";
-    
-    # Return the appropriate HTTP response headers.
-    print Bugzilla->cgi->header();
-    
-    # Generate and return an HTML message about the downtime.
-    $::template->process("global/message.html.tmpl", $::vars)
-      || ThrowTemplateError($::template->error());
-    exit;
-}
-
 # Implementations of several of the below were blatently stolen from CGI.pm,
 # by Lincoln D. Stein.
 
diff --git a/template/en/default/global/message.txt.tmpl b/template/en/default/global/message.txt.tmpl
new file mode 100644 (file)
index 0000000..07ee05b
--- /dev/null
@@ -0,0 +1,26 @@
+[%# 1.0@bugzilla.org %]
+[%# The contents of this file are subject to the Mozilla Public
+  # License Version 1.1 (the "License"); you may not use this file
+  # except in compliance with the License. You may obtain a copy of
+  # the License at http://www.mozilla.org/MPL/
+  #
+  # Software distributed under the License is distributed on an "AS
+  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+  # implied. See the License for the specific language governing
+  # rights and limitations under the License.
+  #
+  # The Original Code is the Bugzilla Bug Tracking System.
+  #
+  # The Initial Developer of the Original Code is Max Kanat-Alexander.
+  # Portions created by Max Kanat-Alexander are Copyright (C) 2005
+  # Max Kanat-Alexander. All Rights Reserved.
+  #
+  # Contributor(s): Max Kanat-Alexander <mkanat@kerio.com>
+  #%]
+
+[% PROCESS global/variables.none.tmpl %]
+
+[%# Yes, this may show some HTML. But it's the best we
+  # can do at the moment. %]
+[% PROCESS global/messages.html.tmpl %]
+[% message %]