From c56f5e3c03177edf52172c8a164f66c354d0e147 Mon Sep 17 00:00:00 2001 From: "wurblzap%gmail.com" <> Date: Wed, 22 Aug 2007 01:47:51 +0000 Subject: Bug 365378 – The 'languages' parameter is not necessary. Patch by Marc Schumann ; r=LpSolit; a=LpSolit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla.pm | 24 ++++++++++++++++ Bugzilla/Config/Common.pm | 25 ++--------------- Bugzilla/Install.pm | 8 +++--- Bugzilla/Install/DB.pm | 14 ++++++++++ Bugzilla/Template.pm | 5 +--- Bugzilla/Template/Plugin/Hook.pm | 2 +- Bugzilla/User/Setting/Lang.pm | 60 ++++++++++++++++++++++++++++++++++++++++ docs/xml/customization.xml | 8 ------ editparams.cgi | 12 -------- 9 files changed, 106 insertions(+), 52 deletions(-) create mode 100755 Bugzilla/User/Setting/Lang.pm diff --git a/Bugzilla.pm b/Bugzilla.pm index e4947fbe1..47cf256ff 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -40,6 +40,7 @@ use Bugzilla::Util; use Bugzilla::Field; use File::Basename; +use File::Spec::Functions; use Safe; # This creates the request cache for non-mod_perl installations. @@ -308,6 +309,24 @@ sub dbh { return request_cache()->{dbh}; } +sub languages { + return request_cache()->{languages} if request_cache()->{languages}; + + my @files = glob(catdir(bz_locations->{'templatedir'}, '*')); + my @languages; + foreach my $dir_entry (@files) { + # It's a language directory only if it contains "default" or + # "custom". This auto-excludes CVS directories as well. + next unless (-d catdir($dir_entry, 'default') + || -d catdir($dir_entry, 'custom')); + $dir_entry = basename($dir_entry); + # Check for language tag format conforming to RFC 1766. + next unless $dir_entry =~ /^[a-zA-Z]{1,8}(-[a-zA-Z]{1,8})?$/; + push(@languages, $dir_entry); + } + return request_cache()->{languages} = \@languages; +} + sub error_mode { my $class = shift; my $newval = shift; @@ -627,6 +646,11 @@ used to automatically answer or skip prompts. The current database handle. See L. +=item C + +Currently installed languages. +Returns a reference to a list of RFC 1766 language tags of installed languages. + =item C Switch from using the main database to using the shadow database. diff --git a/Bugzilla/Config/Common.pm b/Bugzilla/Config/Common.pm index 8435b20a1..2e5e7d15d 100644 --- a/Bugzilla/Config/Common.pm +++ b/Bugzilla/Config/Common.pm @@ -49,8 +49,8 @@ use base qw(Exporter); check_sslbase check_priority check_severity check_platform check_opsys check_shadowdb check_urlbase check_webdotbase check_netmask check_user_verify_class check_image_converter - check_languages check_mail_delivery_method check_notification - check_timezone check_utf8 check_bug_status + check_mail_delivery_method check_notification check_timezone check_utf8 + check_bug_status ); # Checking functions for the various values @@ -304,27 +304,6 @@ sub check_image_converter { return ""; } -sub check_languages { - my ($lang) = @_; - my @languages = split(/[,\s]+/, trim($lang)); - if(!scalar(@languages)) { - return "You need to specify a language tag." - } - my $templatedir = bz_locations()->{'templatedir'}; - my %lang_seen; - my @validated_languages; - foreach my $language (@languages) { - if( ! -d "$templatedir/$language/custom" - && ! -d "$templatedir/$language/default") { - return "The template directory for $language does not exist"; - } - push(@validated_languages, $language) unless $lang_seen{$language}++; - } - # Rebuild the list of language tags, avoiding duplicates. - $_[0] = join(', ', @validated_languages); - return ""; -} - sub check_mail_delivery_method { my $check = check_multi(@_); return $check if $check; diff --git a/Bugzilla/Install.pm b/Bugzilla/Install.pm index 7e3a97b7d..f251e4d1c 100644 --- a/Bugzilla/Install.pm +++ b/Bugzilla/Install.pm @@ -36,7 +36,6 @@ use Bugzilla::Util qw(get_text); use Bugzilla::Version; sub SETTINGS { - my @languages = split(/[\s,]+/, Bugzilla->params->{'languages'}); return { # 2005-03-03 travis@sedsystems.ca -- Bug 41972 display_quips => { options => ["on", "off"], default => "on" }, @@ -59,10 +58,11 @@ sub SETTINGS { # 2006-08-04 wurblzap@gmail.com -- Bug 322693 skin => { subclass => 'Skin', default => 'Dusk' }, # 2006-12-10 LpSolit@gmail.com -- Bug 297186 - lang => { options => \@languages, - default => $languages[0] }, + lang => { subclass => 'Lang', + default => ${Bugzilla->languages}[0] }, # 2007-07-02 altlist@gmail.com -- Bug 225731 - quote_replies => { options => ['quoted_reply', 'simple_reply', 'off'], default => "quoted_reply" } + quote_replies => { options => ['quoted_reply', 'simple_reply', 'off'], + default => "quoted_reply" } } }; diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index d2abe9da6..327487cd9 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -512,6 +512,9 @@ sub update_table_definitions { # 2007-08-08 LpSolit@gmail.com - Bug 332149 $dbh->bz_add_column('groups', 'icon_url', {TYPE => 'TINYTEXT'}); + # 2007-08-21 wurblzap@gmail.com - Bug 365378 + _make_lang_setting_dynamic(); + ################################################################ # New --TABLE-- changes should go *** A B O V E *** this point # ################################################################ @@ -2884,6 +2887,17 @@ sub _initialize_workflow { Bugzilla::Status::add_missing_bug_status_transitions(); } +sub _make_lang_setting_dynamic { + my $dbh = Bugzilla->dbh; + my $count = $dbh->selectrow_array(q{SELECT 1 FROM setting + WHERE name = 'lang' + AND subclass IS NULL}); + if ($count) { + $dbh->do(q{UPDATE setting SET subclass = 'Lang' WHERE name = 'lang'}); + $dbh->do(q{DELETE FROM setting_value WHERE name = 'lang'}); + } +} + 1; __END__ diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 20fe83112..b0c185830 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -87,7 +87,7 @@ sub getTemplateIncludePath { my $cache = Bugzilla->request_cache; my $lang = $cache->{'language'} || ""; $cache->{"template_include_path_$lang"} ||= template_include_path({ - use_languages => [split(/[\s,]+/, Bugzilla->params->{'languages'})], + use_languages => Bugzilla->languages, only_language => $lang }); return $cache->{"template_include_path_$lang"}; } @@ -767,9 +767,6 @@ sub precompile_templates { -d "$templatedir/$dir/default" || -d "$templatedir/$dir/custom" || next; local $ENV{'HTTP_ACCEPT_LANGUAGE'} = $dir; - # We locally hack this parameter so that Bugzilla::Template - # accepts this language no matter what. - local Bugzilla->params->{'languages'} = "$dir,en"; my $template = Bugzilla::Template->create(clean_cache => 1); # Precompile all the templates found in all the directories. diff --git a/Bugzilla/Template/Plugin/Hook.pm b/Bugzilla/Template/Plugin/Hook.pm index b1f27990e..54ce02a67 100644 --- a/Bugzilla/Template/Plugin/Hook.pm +++ b/Bugzilla/Template/Plugin/Hook.pm @@ -107,7 +107,7 @@ sub process { # get a list of languages we accept so we can find the hook # that corresponds to our desired languages: sub getLanguages() { - my $languages = trim(Bugzilla->params->{'languages'}); + my $languages = join(',', @{Bugzilla->languages}); if (not ($languages =~ /,/)) { # only one language return $languages; } diff --git a/Bugzilla/User/Setting/Lang.pm b/Bugzilla/User/Setting/Lang.pm new file mode 100755 index 000000000..79372704d --- /dev/null +++ b/Bugzilla/User/Setting/Lang.pm @@ -0,0 +1,60 @@ +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# 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 Marc Schumann. +# Portions created by Marc Schumann are Copyright (c) 2007 Marc Schumann. +# All rights reserved. +# +# Contributor(s): Marc Schumann + +package Bugzilla::User::Setting::Lang; + +use strict; + +use base qw(Bugzilla::User::Setting); + +use Bugzilla::Constants; + +sub legal_values { + my ($self) = @_; + + return $self->{'legal_values'} if defined $self->{'legal_values'}; + + return $self->{'legal_values'} = Bugzilla->languages; +} + +1; + +__END__ + +=head1 NAME + +Bugzilla::User::Setting::Lang - Object for a user preference setting for preferred language + +=head1 DESCRIPTION + +Lang.pm extends Bugzilla::User::Setting and implements a class specialized for +setting the preferred language. + +=head1 METHODS + +=over + +=item C + +Description: Returns all legal languages +Params: none +Returns: A reference to an array containing the names of all legal languages + +=back diff --git a/docs/xml/customization.xml b/docs/xml/customization.xml index ce48ab940..90d2d6208 100644 --- a/docs/xml/customization.xml +++ b/docs/xml/customization.xml @@ -434,14 +434,6 @@ url="http://www.bugzilla.org/download.html#localizations"/>. Instructions for submitting new languages are also available from that location. - - After untarring the localizations (or creating your own) in the - BUGZILLA_ROOT/template directory, - you must update the parameter to contain any - localizations you'd like to permit. You may also wish to re-order - the parameter so that en - doesn't come first, if you don't want English to be the default language. - diff --git a/editparams.cgi b/editparams.cgi index 38d486656..819c8c645 100755 --- a/editparams.cgi +++ b/editparams.cgi @@ -75,7 +75,6 @@ if ($action eq 'save' && $current_module) { my @changes = (); my @module_param_list = "Bugzilla::Config::${current_module}"->get_param_list(1); - my $update_lang_user_pref = 0; foreach my $i (@module_param_list) { my $name = $i->{'name'}; my $value = $cgi->param($name); @@ -135,22 +134,11 @@ if ($action eq 'save' && $current_module) { if (($name eq "shutdownhtml") && ($value ne "")) { $vars->{'shutdown_is_active'} = 1; } - if ($name eq 'languages') { - $update_lang_user_pref = 1; - } if ($name eq 'duplicate_or_move_bug_status') { Bugzilla::Status::add_missing_bug_status_transitions($value); } } } - if ($update_lang_user_pref) { - # We have to update the list of languages users can choose. - # If some users have selected a language which is no longer available, - # then we delete it (the user pref is reset to the default one). - my @languages = split(/[\s,]+/, Bugzilla->params->{'languages'}); - map {trick_taint($_)} @languages; - add_setting('lang', \@languages, $languages[0], undef, 1); - } $vars->{'message'} = 'parameters_updated'; $vars->{'param_changed'} = \@changes; -- cgit v1.2.3-24-g4f1b