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/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 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 32 deletions(-) create mode 100755 Bugzilla/User/Setting/Lang.pm (limited to 'Bugzilla') 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 -- cgit v1.2.3-24-g4f1b