@@ -195,6 +195,14 @@ BEGIN
195
195
' x-zip' => undef , ' ' => undef ,
196
196
);
197
197
198
+ # Pixel sizes for icons and avatars. If the default font sizes or lineheights
199
+ # are changed, it may be appropriate to change these values too via
200
+ # $GITWEB_CONFIG.
201
+ our %avatar_size = (
202
+ ' default' => 16,
203
+ ' double' => 32
204
+ );
205
+
198
206
# You define site-wide feature defaults here; override them with
199
207
# $GITWEB_CONFIG as necessary.
200
208
our %feature = (
@@ -365,6 +373,24 @@ BEGIN
365
373
' sub' => \&feature_patches,
366
374
' override' => 0,
367
375
' default' => [16]},
376
+
377
+ # Avatar support. When this feature is enabled, views such as
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.
384
+
385
+ # To enable system wide have in $GITWEB_CONFIG
386
+ # $feature{'avatar'}{'default'} = ['gravatar'];
387
+ # To have project specific config enable override in $GITWEB_CONFIG
388
+ # $feature{'avatar'}{'override'} = 1;
389
+ # and in project config gitweb.avatar = gravatar;
390
+ ' avatar' => {
391
+ ' sub' => \&feature_avatar,
392
+ ' override' => 0,
393
+ ' default' => [' ' ]},
368
394
);
369
395
370
396
sub gitweb_get_feature {
@@ -433,6 +459,12 @@ sub feature_patches {
433
459
return ($_ [0]);
434
460
}
435
461
462
+ sub feature_avatar {
463
+ my @val = (git_get_project_config(' avatar' ));
464
+
465
+ return @val ? @val : @_ ;
466
+ }
467
+
436
468
# checking HEAD file with -e is fragile if the repository was
437
469
# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
438
470
# and then pruned.
@@ -814,6 +846,17 @@ sub evaluate_path_info {
814
846
our @snapshot_fmts = gitweb_get_feature(' snapshot' );
815
847
@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts );
816
848
849
+ # check that the avatar feature is set to a known provider name,
850
+ # and for each provider check if the dependencies are satisfied.
851
+ # if the provider name is invalid or the dependencies are not met,
852
+ # reset $git_avatar to the empty string.
853
+ our ($git_avatar ) = gitweb_get_feature(' avatar' );
854
+ if ($git_avatar eq ' gravatar' ) {
855
+ $git_avatar = ' ' unless (eval { require Digest::MD5; 1; });
856
+ } else {
857
+ $git_avatar = ' ' ;
858
+ }
859
+
817
860
# dispatch
818
861
if (!defined $action ) {
819
862
if (defined $hash ) {
@@ -1469,14 +1512,44 @@ sub format_subject_html {
1469
1512
}
1470
1513
}
1471
1514
1515
+ # Insert an avatar for the given $email at the given $size if the feature
1516
+ # is enabled.
1517
+ sub git_get_avatar {
1518
+ my ($email , %opts ) = @_ ;
1519
+ my $pre_white = ($opts {-pad_before} ? " " : " " );
1520
+ my $post_white = ($opts {-pad_after} ? " " : " " );
1521
+ $opts {-size} ||= ' default' ;
1522
+ my $size = $avatar_size {$opts {-size}} || $avatar_size {' default' };
1523
+ my $url = " " ;
1524
+ if ($git_avatar eq ' gravatar' ) {
1525
+ $url = " http://www.gravatar.com/avatar/" .
1526
+ Digest::MD5::md5_hex(lc $email ) . " ?s=$size " ;
1527
+ }
1528
+ # Currently only gravatars are supported, but other forms such as
1529
+ # picons can be added by putting an else up here and defining $url
1530
+ # as needed. If no variant puts something in $url, we assume avatars
1531
+ # are completely disabled/unavailable.
1532
+ if ($url ) {
1533
+ return $pre_white .
1534
+ " <img width=\" $size \" " .
1535
+ " class=\" avatar\" " .
1536
+ " src=\" $url \" " .
1537
+ " />" . $post_white ;
1538
+ } else {
1539
+ return " " ;
1540
+ }
1541
+ }
1542
+
1472
1543
# format the author name of the given commit with the given tag
1473
1544
# the author name is chopped and escaped according to the other
1474
1545
# optional parameters (see chop_str).
1475
1546
sub format_author_html {
1476
1547
my $tag = shift ;
1477
1548
my $co = shift ;
1478
1549
my $author = chop_and_escape_str($co -> {' author_name' }, @_ );
1479
- return " <$tag class=\" author\" >" . $author . " </$tag >" ;
1550
+ return " <$tag class=\" author\" >" .
1551
+ git_get_avatar($co -> {' author_email' }, -pad_after => 1) .
1552
+ $author . " </$tag >" ;
1480
1553
}
1481
1554
1482
1555
# format git diff header line, i.e. "diff --(git|combined|cc) ..."
@@ -3252,7 +3325,8 @@ sub git_print_authorship {
3252
3325
esc_html($co -> {' author_name' }) .
3253
3326
" [$ad {'rfc2822'}" ;
3254
3327
print_local_time(%ad ) if ($opts {-localtime });
3255
- print " ]</$tag >\n " ;
3328
+ print " ]" . git_get_avatar($co -> {' author_email' }, -pad_before => 1)
3329
+ . " </$tag >\n " ;
3256
3330
}
3257
3331
3258
3332
# Outputs table rows containing the full author or committer information,
@@ -3267,7 +3341,10 @@ sub git_print_authorship_rows {
3267
3341
@people = (' author' , ' committer' ) unless @people ;
3268
3342
foreach my $who (@people ) {
3269
3343
my %wd = parse_date($co -> {" ${who} _epoch" }, $co -> {" ${who} _tz" });
3270
- print " <tr><td>$who </td><td>" . esc_html($co -> {$who }) . " </td></tr>\n " .
3344
+ print " <tr><td>$who </td><td>" . esc_html($co -> {$who }) . " </td>" .
3345
+ " <td rowspan=\" 2\" >" .
3346
+ git_get_avatar($co -> {" ${who} _email" }, -size => ' double' ) .
3347
+ " </td></tr>\n " .
3271
3348
" <tr>" .
3272
3349
" <td></td><td> $wd {'rfc2822'}" ;
3273
3350
print_local_time(%wd );
0 commit comments