summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--lib/VNDB/Handler/Misc.pm11
-rw-r--r--lib/VNDB/Util/Auth.pm4
-rwxr-xr-xutil/vndb.pl44
4 files changed, 46 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index ad508ffa..906346f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,7 @@
- Don't allow page > 100 or sorting on username or title on tag link browser
- Added users_prefs table and removed the following columns from users:
skin, customcss, show_nsfw, show_list, notify_announce, notify_dbedit
+ - Store l10n preference in the database for logged-in users
2.15 - 2010-12-15
- Removed expand/collapse from history browser and /u+/posts and switched to
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 4e4e5479..8b4b8900 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -340,10 +340,17 @@ sub setlang {
return 404 if $lang->{_err};
$lang = $lang->{lang};
+ my $browser = VNDB::L10N->get_handle()->language_tag();
+
(my $ref = $self->reqHeader('Referer')||'/') =~ s/^\Q$self->{url}//;
$self->resRedirect($ref, 'post');
- $self->resHeader('Set-Cookie', "l10n=$lang; expires=Sat, 01-Jan-2030 00:00:00 GMT; path=/; domain=$self->{cookie_domain}")
- if $lang ne $self->{l10n}->language_tag();
+ if($lang ne $self->{l10n}->language_tag()) {
+ $self->authInfo->{id}
+ ? $self->authPref(l10n => $lang eq $browser ? undef : $lang)
+ : $self->resHeader('Set-Cookie', sprintf 'l10n=%s; expires=%s; path=/; domain=%s',
+ $lang, $lang eq $browser ? 'Sat, 01-Jan-2000 00:00:00 GMT' : 'Sat, 01-Jan-2030 00:00:00 GMT',
+ $self->{cookie_domain});
+ }
}
diff --git a/lib/VNDB/Util/Auth.pm b/lib/VNDB/Util/Auth.pm
index 932a48ee..9ad76894 100644
--- a/lib/VNDB/Util/Auth.pm
+++ b/lib/VNDB/Util/Auth.pm
@@ -70,6 +70,10 @@ sub authLogout {
$self->resRedirect('/', 'temp');
_rmcookie($self);
+
+ # set l10n cookie if the user has a preferred language set
+ my $l10n = $self->authPref('l10n');
+ $self->resHeader('Set-Cookie', "l10n=$l10n; expires=Sat, 01-Jan-2030 00:00:00 GMT; path=/; domain=$self->{cookie_domain}") if $l10n;
}
diff --git a/util/vndb.pl b/util/vndb.pl
index 183cea4d..0fd6e08d 100755
--- a/util/vndb.pl
+++ b/util/vndb.pl
@@ -54,22 +54,42 @@ YAWF::init(
sub reqinit {
my $self = shift;
+ # check authentication cookies
+ $self->authInit;
+
# Determine language
- # if the cookie is set, use that. Otherwise, interpret the Accept-Language header or fall back to English.
- # if the cookie is set and is the same as either the Accept-Language header or the fallback, remove it
- my $conf = $self->reqCookie('l10n');
- $conf = '' if !$conf || !grep $_ eq $conf, VNDB::L10N::languages;
+ my $cookie = $self->reqCookie('l10n');
+ $cookie = '' if !$cookie || !grep $_ eq $cookie, VNDB::L10N::languages;
+ my $handle = VNDB::L10N->get_handle(); # falls back to English
+ my $browser = $handle->language_tag();
+ my $rmcookie = 0;
+
+ # when logged in, the setting is kept in the DB even if it's the same as what
+ # the browser requests. This is to ensure a user gets the same language even
+ # when switching PCs
+ if($self->authInfo->{id}) {
+ my $db = $self->authPref('l10n');
+ if($db && !grep $_ eq $db, VNDB::L10N::languages) {
+ $self->authPref(l10n => undef);
+ $db = '';
+ }
+ $rmcookie = 1 if $cookie;
+ if(!$db && $cookie && $cookie ne $browser) {
+ $self->authPref(l10n => $cookie);
+ $db = $cookie;
+ }
+ $handle = VNDB::L10N->get_handle($db) if $db && $db ne $browser;
+ }
- $self->{l10n} = VNDB::L10N->get_handle(); # this uses I18N::LangTags::Detect
+ else {
+ $rmcookie = 1 if $cookie && $cookie eq $browser;
+ $handle = VNDB::L10N->get_handle($cookie) if $cookie && $browser ne $cookie;
+ }
$self->resHeader('Set-Cookie', "l10n= ; expires=Sat, 01-Jan-2000 00:00:00 GMT; path=/; domain=$self->{cookie_domain}")
- if $conf && $self->{l10n}->language_tag() eq $conf;
- $self->{l10n} = VNDB::L10N->get_handle($conf) if $conf && $self->{l10n}->language_tag() ne $conf;
-
-
- # check authentication cookies
- $self->authInit;
+ if $rmcookie;
+ $self->{l10n} = $handle;
- # check for IE6
+ # check for IE
if($self->reqHeader('User-Agent') && $self->reqHeader('User-Agent') =~ /MSIE [67]/
&& !$self->reqCookie('ie-sucks') && $self->reqPath ne 'we-dont-like-ie') {
# act as if we're opening /we-dont-like-ie6 (ugly hack, until YAWF supports preventing URL handlers from firing)