gitweb: picon avatar provider
Simple implementation of picon that only relies on the indiana.edu database. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Giuseppe Bilotta committed
Jun 30, 2009 at 00:00 UTC
679a1a1d420616be1647bdf8b2e93f1f86c7bdae
1 file changed
+27
-7
gitweb/gitweb.perl
+27
-7
@@ -378,15 +378,18 @@ our %feature = (
378
# shortlog or commit will display an avatar associated with
379
# the email of the committer(s) and/or author(s).
380
381
- # Currently only the gravatar provider is available, and it
382
- # depends on Digest::MD5. If an unknown provider is specified,
383
- # the feature is disabled.
381
+ # Currently available providers are gravatar and picon.
382
+ # If an unknown provider is specified, the feature is disabled.
383
+
384
+ # Gravatar depends on Digest::MD5.
385
+ # Picon currently relies on the indiana.edu database.
386
387
# To enable system wide have in $GITWEB_CONFIG
386
- # $feature{'avatar'}{'default'} = ['gravatar'];
388
+ # $feature{'avatar'}{'default'} = ['<provider>'];
389
+ # where <provider> is either gravatar or picon.
390
# To have project specific config enable override in $GITWEB_CONFIG
391
# $feature{'avatar'}{'override'} = 1;
389
- # and in project config gitweb.avatar = gravatar;
392
+ # and in project config gitweb.avatar = <provider>;
393
'avatar' => {
394
'sub' => \&feature_avatar,
395
'override' => 0,
@@ -853,6 +856,8 @@ our @snapshot_fmts = gitweb_get_feature('snapshot');
856
our ($git_avatar) = gitweb_get_feature('avatar');
857
if ($git_avatar eq 'gravatar') {
858
$git_avatar = '' unless (eval { require Digest::MD5; 1; });
859
+} elsif ($git_avatar eq 'picon') {
860
+ # no dependencies
861
} else {
862
$git_avatar = '';
863
}
@@ -1520,6 +1525,20 @@ sub format_subject_html {
1525
# given page, there's no risk for cache conflicts.
1526
our %avatar_cache = ();
1527
1528
+# Compute the picon url for a given email, by using the picon search service over at
1529
+# http://www.cs.indiana.edu/picons/search.html
1530
+sub picon_url {
1531
+ my $email = lc shift;
1532
+ if (!$avatar_cache{$email}) {
1533
+ my ($user, $domain) = split('@', $email);
1534
+ $avatar_cache{$email} =
1535
+ "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1536
+ "$domain/$user/" .
1537
+ "users+domains+unknown/up/single";
1538
+ }
1539
+ return $avatar_cache{$email};
1540
+}
1541
+
1542
# Compute the gravatar url for a given email, if it's not in the cache already.
1543
# Gravatar stores only the part of the URL before the size, since that's the
1544
# one computationally more expensive. This also allows reuse of the cache for
@@ -1544,9 +1563,10 @@ sub git_get_avatar {
1563
my $url = "";
1564
if ($git_avatar eq 'gravatar') {
1565
$url = gravatar_url($email, $size);
1566
+ } elsif ($git_avatar eq 'picon') {
1567
+ $url = picon_url($email);
1568
}
1548
- # Currently only gravatars are supported, but other forms such as
1549
- # picons can be added by putting an else up here and defining $url
1569
+ # Other providers can be added by extending the if chain, defining $url
1570
# as needed. If no variant puts something in $url, we assume avatars
1571
# are completely disabled/unavailable.
1572
if ($url) {