gitweb: Make JavaScript ability to adjust timezones configurable

Configure JavaScript-based ability to select common timezone for git dates via %feature mechanism, namely 'javascript-timezone' feature. The following settings are configurable: * default timezone (defaults to 'local' i.e. browser timezone); this also can function as a way to disable this ability, by setting it to false-ish value (undef or '') * name of cookie to store user's choice of timezone * class name to mark dates NOTE: This is a bit of abuse of %feature system, which can store only sequence of values, rather than dictionary (hash); usually but not always only a single value is used. Based-on-code-by: John 'Warthog9' Hawley <warthog9@eaglescrag.net> Helped-by: Kevin Cernekee <cernekee@gmail.com> Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Apr 28, 2011 at 21:04 UTC 2e987f92408f5ddd20246d7d9553b57d90767d54
1 file changed +31 -8
gitweb/gitweb.perl
+31 -8
@@ -480,6 +480,18 @@ our %feature = (
480 'override' => 0,
481 'default' => [0]},
482
483 + # Enable and configure ability to change common timezone for dates
484 + # in gitweb output via JavaScript. Enabled by default.
485 + # Project specific override is not supported.
486 + 'javascript-timezone' => {
487 + 'override' => 0,
488 + 'default' => [
489 + 'local', # default timezone: 'utc', 'local', or '(-|+)HHMM' format,
490 + # or undef to turn off this feature
491 + 'gitweb_tz', # name of cookie where to store selected timezone
492 + 'datetime', # CSS class used to mark up dates for manipulation
493 + ]},
494 +
495 # Syntax highlighting support. This is based on Daniel Svensson's
496 # and Sham Chukoury's work in gitweb-xmms2.git.
497 # It requires the 'highlight' program present in $PATH,
@@ -3733,14 +3745,19 @@ sub git_footer_html {
3745 qq! "!. href() .qq!");\n!.
3746 qq!</script>\n!;
3747 } else {
3748 + my ($jstimezone, $tz_cookie, $datetime_class) =
3749 + gitweb_get_feature('javascript-timezone');
3750 +
3751 print qq!<script type="text/javascript">\n!.
3737 - qq!window.onload = function () {\n!.
3738 - (gitweb_check_feature('javascript-actions') ?
3739 - qq! fixLinks();\n! : '').
3740 - # last parameter to onloadTZSetup must be CSS class used by format_timestamp_html
3741 - qq! var tz_cookie = { name: 'gitweb_tz', expires: 14, path: '/' };\n!. # in days
3742 - qq! onloadTZSetup('local', tz_cookie, 'datetime');\n!.
3743 - qq!};\n!.
3752 + qq!window.onload = function () {\n!;
3753 + if (gitweb_check_feature('javascript-actions')) {
3754 + print qq! fixLinks();\n!;
3755 + }
3756 + if ($jstimezone && $tz_cookie && $datetime_class) {
3757 + print qq! var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
3758 + qq! onloadTZSetup('$jstimezone', tz_cookie, '$datetime_class');\n!;
3759 + }
3760 + print qq!};\n!.
3761 qq!</script>\n!;
3762 }
3763
@@ -3946,7 +3963,13 @@ sub git_print_section {
3963
3964 sub format_timestamp_html {
3965 my $date = shift;
3949 - my $strtime = '<span class="datetime">'.$date->{'rfc2822'}.'</span>';
3966 + my $strtime = $date->{'rfc2822'};
3967 +
3968 + my (undef, undef, $datetime_class) =
3969 + gitweb_get_feature('javascript-timezone');
3970 + if ($datetime_class) {
3971 + $strtime = qq!<span class="$datetime_class">$strtime</span>!;
3972 + }
3973
3974 my $localtime_format = '(%02d:%02d %s)';
3975 if ($date->{'hour_local'} < 6) {