diff options
author | bbaetz%student.usyd.edu.au <> | 2002-04-27 11:16:28 +0200 |
---|---|---|
committer | bbaetz%student.usyd.edu.au <> | 2002-04-27 11:16:28 +0200 |
commit | 8d97865049b228736912bbf64620987484bf697a (patch) | |
tree | e193a90260656eda143813a4d9418e4666eac85c | |
parent | 150660ee3f4201df06c96b802dbed17753e72b68 (diff) | |
download | bugzilla-8d97865049b228736912bbf64620987484bf697a.tar.gz bugzilla-8d97865049b228736912bbf64620987484bf697a.tar.xz |
Bug 97832 - turn on template compilation. This means that the minimum TT
version is now 2.07.
r=myk, gerv
-rwxr-xr-x | checksetup.pl | 116 | ||||
-rw-r--r-- | docs/rel_notes.txt | 26 | ||||
-rw-r--r-- | globals.pl | 7 |
3 files changed, 133 insertions, 16 deletions
diff --git a/checksetup.pl b/checksetup.pl index 8df823614..336bc4d5b 100755 --- a/checksetup.pl +++ b/checksetup.pl @@ -181,7 +181,7 @@ unless (have_vers("Data::Dumper",0)) { push @missing,"Data::Dumper" } unless (have_vers("DBD::mysql","1.2209")) { push @missing,"DBD::mysql" } unless (have_vers("Date::Parse",0)) { push @missing,"Date::Parse" } unless (have_vers("AppConfig","1.52")) { push @missing,"AppConfig" } -unless (have_vers("Template","2.06")) { push @missing,"Template" } +unless (have_vers("Template","2.07")) { push @missing,"Template" } unless (have_vers("Text::Wrap","2001.0131")) { push @missing,"Text::Wrap" } unless (have_vers("File::Spec", "0.82")) { push @missing,"File::Spec" } @@ -525,6 +525,20 @@ my @my_priorities = @{*{$main::{'priorities'}}{ARRAY}}; my @my_platforms = @{*{$main::{'platforms'}}{ARRAY}}; my @my_opsys = @{*{$main::{'opsys'}}{ARRAY}}; +if ($my_webservergroup && ($< != 0)) { # zach: if not root, yell at them, bug 87398 + print <<EOF; + +Warning: you have entered a value for the "webservergroup" parameter +in localconfig, but you are not running this script as root. +This can cause permissions problems and decreased security. If you +experience problems running Bugzilla scripts, log in as root and re-run +this script, or remove the value of the "webservergroup" parameter. +Note that any warnings about "uninitialized values" that you may +see below are caused by this. + +EOF + } + ########################################################################### # Global Utility Library ########################################################################### @@ -737,6 +751,90 @@ END } } +{ + eval("use Date::Parse"); + # Templates will be recompiled if the source changes, but not if the + # settings in globals.pl change, so we need to be able to force a rebuild + # if that happens + + # The last time the global template params were changed. Keep in UTC, + # YYYY-MM-DD + my $lastTemplateParamChange = str2time("2002-04-24", "UTC"); + if (-e 'data/template') { + unless (-d 'data/template' && -e 'data/template/.lastRebuild' && + (stat('data/template/.lastRebuild'))[9] >= $lastTemplateParamChange) { + # If File::Path::rmtree reported errors, then I'd use that + use File::Find; + sub remove { + return if $_ eq "."; + if (-d $_) { + rmdir $_ || die "Couldn't rmdir $_: $!\n"; + } else { + unlink $_ || die "Couldn't unlink $_: $!\n"; + } + } + finddepth(\&remove, 'data/template'); + } + } + + # Precompile stuff. This speeds up initial access (so the template isn't + # compiled multiple times simulataneously by different servers), and helps + # to get the permissions right. + eval("use Template"); + my $redir = ($^O =~ /MSWin32/i) ? "NUL" : "/dev/null"; + my $template = Template->new( + { + # Output to /dev/null here + OUTPUT => $redir, + + # Colon-separated list of directories containing templates. + INCLUDE_PATH => "template/en/custom:template/en/default", + + PRE_CHOMP => 1 , + TRIM => 1 , + + COMPILE_DIR => "data", # becomes data/template/en/{custom,default} + + # These don't actually need to do anything here, just exist + FILTERS => + { + strike => sub { return $_; } , + js => sub { return $_; }, + html => sub { return $_; }, + url_quote => sub { return $_; } + }, + }) || die ("Could not create Template: " . Template->error() . "\n"); + + sub compile { + return if (-d $_); + return if ($_ !~ /\.tmpl$/); + s!template/en/default/!!; # trim the bit we don't pass to TT + + $template->process($_, {}) + || die "Could not compile $_:" . $template->error() . "\n"; + } + + { + use File::Find; + + # Disable warnings which come from running the compiled templates + # This way is OK, because they're all runtime warnings. + # The reason we get these warnings here is that none of the required + # vars will be present. + local ($^W) = 0; + + # Traverse the default hierachy. Custom templates will be picked up + # via the INCLUDE_PATH, but we know that bugzilla will only be + # calling stuff which exists in en/default + # FIXME - if we start doing dynamic INCLUDE_PATH we may have to + # recurse all of template/, changing the INCLUDE_PATH each time + + find({wanted => \&compile, no_chdir => 1}, "template/en/default"); + } + # update the time on the stamp file + open FILE, '>data/template/.lastRebuild'; close FILE; + utime $lastTemplateParamChange, $lastTemplateParamChange, ('data/template/.lastRebuild'); +} # Just to be sure ... unlink "data/versioncache"; @@ -852,20 +950,6 @@ sub fixPerms { } if ($my_webservergroup) { - unless ($< == 0) { # zach: if not root, yell at them, bug 87398 - print <<EOF; - -Warning: you have entered a value for the "webservergroup" parameter -in localconfig, but you are not running this script as root. -This can cause permissions problems and decreased security. If you -experience problems running Bugzilla scripts, log in as root and re-run -this script, or remove the value of the "webservergroup" parameter. -Note that any warnings about "uninitialized values" that you may -see below are caused by this. - -EOF - } - # Funny! getgrname returns the GID if fed with NAME ... my $webservergid = getgrnam($my_webservergroup); # chown needs to be called with a valid uid, not 0. $< returns the @@ -873,6 +957,7 @@ EOF # userid. fixPerms('.htaccess', $<, $webservergid, 027); # glob('*') doesn't catch dotfiles fixPerms('data/.htaccess', $<, $webservergid, 027); + fixPerms('data/template', $<, $webservergid, 007, 1); # webserver will write to these fixPerms('data/webdot/.htaccess', $<, $webservergid, 027); fixPerms('data/params', $<, $webservergid, 017); fixPerms('*', $<, $webservergid, 027); @@ -887,6 +972,7 @@ EOF my $gid = (split " ", $()[0]; fixPerms('.htaccess', $<, $gid, 022); # glob('*') doesn't catch dotfiles fixPerms('data/.htaccess', $<, $gid, 022); + fixPerms('data/template', $<, $gid, 022, 1); fixPerms('data/webdot/.htaccess', $<, $gid, 022); fixPerms('data/params', $<, $gid, 011); fixPerms('*', $<, $gid, 022); diff --git a/docs/rel_notes.txt b/docs/rel_notes.txt index 705cd8f97..3a2ffd589 100644 --- a/docs/rel_notes.txt +++ b/docs/rel_notes.txt @@ -41,7 +41,7 @@ Perl v5.005 DBI v1.13 DBD::MySQL v1.2209 AppConfig v1.52 -Template Toolkit v2.06 +Template Toolkit v2.07 Text::Wrap v20001.0131 Data::Dumper, Date::Parse, CGI::Carp (any) GD v1.19 (optional) @@ -87,6 +87,30 @@ XML::Parser (any) the MySQL optimiser. (bug 96101) +- This release of Bugzilla uses the Template Toolkit. For speed, + compiled templates are cached on disk. If you modify the templates + in order to customise the look and feel of your Bugzilla instalation, + the toolkit will normally detect the changes, and recompile the + changed templates. + + However, if you do not set a webservergroup in the localconfig file, + (a generally unwise thing on a production installation of Bugzilla) + the template directory would have to be world-writable for automatic + recompilation to happen. + + Doing that would be a security risk. So, if you modify templates locally + and do not have a webservergroup set, you will have to rerun checksetup.pl + to recompile the templates manually. If you do not do this, the changes + you make will not appear, and an error message will be reported. + + Adding new directories anywhere inside the template directory may cause + permission errors. If you see these, rerun checksetup.pl as root. If you + do not have root access, or cannot get someone who does to do this for you, + you can rename the data/template directory to data/template.old (or any + other name bugzilla doesn't use). Then rerun checksetup.pl to regenerate + the compiled templates. + (bug 97832) + ************************************************************ *** USERS UPGRADING FROM 2.14.1 OR EARLIER - 2.16 ISSUES *** ************************************************************ diff --git a/globals.pl b/globals.pl index 248bcd594..4c93e800a 100644 --- a/globals.pl +++ b/globals.pl @@ -1527,6 +1527,11 @@ use Template; # Create the global template object that processes templates and specify # configuration parameters that apply to all templates processed in this script. + +# IMPORTANT - If you make any configuration changes here, make sure to make +# them in t/004.template.t and checksetup.pl. You may also need to change the +# date settings were last changed - see the comments in checksetup.pl for +# details $::template ||= Template->new( { # Colon-separated list of directories containing templates. @@ -1539,6 +1544,8 @@ $::template ||= Template->new( PRE_CHOMP => 1 , TRIM => 1 , + COMPILE_DIR => 'data', + # Functions for processing text within templates in various ways. FILTERS => { |