From: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
To: git@vger.kernel.org
Cc: Jakub Narebski <jnareb@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Subject: [PATCHv2] gitweb: gravatar support
Date: Fri, 19 Jun 2009 20:21:10 +0200 [thread overview]
Message-ID: <1245435670-5688-1-git-send-email-giuseppe.bilotta@gmail.com> (raw)
Introduce gravatar support by adding the appropriate img tag next to
author and committer in commit, shortlog and log view.
The feature is disabled by default, and depends on Digest::MD5, which
is available in most Perl installations.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
gitweb/gitweb.css | 4 ++++
gitweb/gitweb.perl | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 48 insertions(+), 7 deletions(-)
Changes from the previous version include gravatar use in history view,
CSS use and the possibility to override the feature on a per-project basis.
diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css
index a01eac8..ca716e6 100644
--- a/gitweb/gitweb.css
+++ b/gitweb/gitweb.css
@@ -28,6 +28,10 @@ img.logo {
border-width: 0px;
}
+img.gravatar {
+ vertical-align:middle;
+}
+
div.page_header {
height: 25px;
padding: 8px;
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1e7e2d8..c06356b 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -365,6 +365,21 @@ our %feature = (
'sub' => \&feature_patches,
'override' => 0,
'default' => [16]},
+
+ # Gravatar support. When this feature is enabled, views such as
+ # shortlog or commit will display the gravatar associated with
+ # the email of the committer(s) and/or author(s). Please note that
+ # the feature depends on Digest::MD5.
+
+ # To enable system wide have in $GITWEB_CONFIG
+ # $feature{'gravatar'}{'default'} = [1];
+ # To have project specific config enable override in $GITWEB_CONFIG
+ # $feature{'gravatar'}{'override'} = 1;
+ # and in project config gitweb.gravatar = 0|1;
+ 'gravatar' => {
+ 'sub' => sub { feature_bool('gravatar', @_) },
+ 'override' => 0,
+ 'default' => [0]},
);
sub gitweb_get_feature {
@@ -814,6 +829,10 @@ $git_dir = "$projectroot/$project" if $project;
our @snapshot_fmts = gitweb_get_feature('snapshot');
@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts);
+# check if gravatars are enabled and dependencies are satisfied
+our $git_gravatar_enabled = gitweb_check_feature('gravatar') &&
+ (eval { use Digest::MD5 qw(md5_hex); 1; });
+
# dispatch
if (!defined $action) {
if (defined $hash) {
@@ -3214,11 +3233,26 @@ sub git_print_header_div {
"\n</div>\n";
}
+# insert a gravatar for the given $email at the given $size if the feature
+# is enabled
+sub git_get_gravatar {
+ if ($git_gravatar_enabled) {
+ my ($email, $size, $whitespace) = @_;
+ $whitespace = 0 unless defined($whitespace);
+ $size = 32 if (!defined($size) || $size <= 0);
+ return "<img class=\"gravatar\" src=\"http://www.gravatar.com/avatar.php?gravatar_id=" .
+ md5_hex(lc $email) . "&size=$size\" />" . ($whitespace ? " " : "");
+ } else {
+ return "";
+ }
+}
+
sub git_print_authorship {
my $co = shift;
my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'});
print "<div class=\"author_date\">" .
+ git_get_gravatar($co->{'author_email'}, 16, 1) .
esc_html($co->{'author_name'}) .
" [$ad{'rfc2822'}";
if ($ad{'hour_local'} < 6) {
@@ -4145,7 +4179,7 @@ sub git_shortlog_body {
my $author = chop_and_escape_str($co{'author_name'}, 10);
# git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
- "<td><i>" . $author . "</i></td>\n" .
+ "<td>" . git_get_gravatar($co{'author_email'}, 16, 1) . "<i>" . $author . "</i></td>\n" .
"<td>";
print format_subject_html($co{'title'}, $co{'title_short'},
href(action=>"commit", hash=>$commit), $ref);
@@ -4196,7 +4230,7 @@ sub git_history_body {
# shortlog uses chop_str($co{'author_name'}, 10)
my $author = chop_and_escape_str($co{'author_name'}, 15, 3);
print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
- "<td><i>" . $author . "</i></td>\n" .
+ "<td>" . git_get_gravatar($co{'author_email'}, 16, 1) . "<i>" . $author . "</i></td>\n" .
"<td>";
# originally git_history used chop_str($co{'title'}, 50)
print format_subject_html($co{'title'}, $co{'title_short'},
@@ -4352,7 +4386,7 @@ sub git_search_grep_body {
$alternate ^= 1;
my $author = chop_and_escape_str($co{'author_name'}, 15, 5);
print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
- "<td><i>" . $author . "</i></td>\n" .
+ "<td>" . git_get_gravatar($co{'author_email'}, 16, 1) . "<i>" . $author . "</i></td>\n" .
"<td>" .
$cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
-class => "list subject"},
@@ -5095,8 +5129,9 @@ sub git_log {
$cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") .
"<br/>\n" .
"</div>\n" .
- "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
- "</div>\n";
+ "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i> " .
+ git_get_gravatar($co{'author_email'}, 16) .
+ "<br/>\n</div>\n";
print "<div class=\"log_body\">\n";
git_print_log($co{'comment'}, -final_empty_line=> 1);
@@ -5183,7 +5218,8 @@ sub git_commit {
}
print "<div class=\"title_text\">\n" .
"<table class=\"object_header\">\n";
- print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
+ print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td>".
+ "<td rowspan=\"2\">" .git_get_gravatar($co{'author_email'}) . "</td></tr>\n" .
"<tr>" .
"<td></td><td> $ad{'rfc2822'}";
if ($ad{'hour_local'} < 6) {
@@ -5195,7 +5231,8 @@ sub git_commit {
}
print "</td>" .
"</tr>\n";
- print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
+ print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td>".
+ "<td rowspan=\"2\">" .git_get_gravatar($co{'committer_email'}) . "</td></tr>\n";
print "<tr><td></td><td> $cd{'rfc2822'}" .
sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
"</td></tr>\n";
--
1.6.3.rc1.192.gdbfcb
next reply other threads:[~2009-06-19 18:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-19 18:21 Giuseppe Bilotta [this message]
2009-06-19 18:26 ` [PATCHv2] gitweb: gravatar support Johannes Schindelin
2009-06-19 18:36 ` Johannes Schindelin
2009-06-19 20:28 ` Junio C Hamano
2009-06-19 22:43 ` Giuseppe Bilotta
2009-06-20 19:24 ` Jakub Narebski
2009-06-20 10:57 ` Jakub Narebski
2009-06-20 14:16 ` Aaron Crane
2009-06-20 16:58 ` Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1245435670-5688-1-git-send-email-giuseppe.bilotta@gmail.com \
--to=giuseppe.bilotta@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).