@@ -195,6 +195,14 @@ BEGIN
195195 ' x-zip' => undef , ' ' => undef ,
196196);
197197
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+
198206# You define site-wide feature defaults here; override them with
199207# $GITWEB_CONFIG as necessary.
200208our %feature = (
@@ -365,6 +373,24 @@ BEGIN
365373 ' sub' => \&feature_patches,
366374 ' override' => 0,
367375 ' 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' => [' ' ]},
368394);
369395
370396sub gitweb_get_feature {
@@ -433,6 +459,12 @@ sub feature_patches {
433459 return ($_ [0]);
434460}
435461
462+ sub feature_avatar {
463+ my @val = (git_get_project_config(' avatar' ));
464+
465+ return @val ? @val : @_ ;
466+ }
467+
436468# checking HEAD file with -e is fragile if the repository was
437469# initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
438470# and then pruned.
@@ -814,6 +846,17 @@ sub evaluate_path_info {
814846our @snapshot_fmts = gitweb_get_feature(' snapshot' );
815847@snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts );
816848
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+
817860# dispatch
818861if (!defined $action ) {
819862 if (defined $hash ) {
@@ -1469,14 +1512,44 @@ sub format_subject_html {
14691512 }
14701513}
14711514
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+
14721543# format the author name of the given commit with the given tag
14731544# the author name is chopped and escaped according to the other
14741545# optional parameters (see chop_str).
14751546sub format_author_html {
14761547 my $tag = shift ;
14771548 my $co = shift ;
14781549 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 >" ;
14801553}
14811554
14821555# format git diff header line, i.e. "diff --(git|combined|cc) ..."
@@ -3252,7 +3325,8 @@ sub git_print_authorship {
32523325 esc_html($co -> {' author_name' }) .
32533326 " [$ad {'rfc2822'}" ;
32543327 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 " ;
32563330}
32573331
32583332# Outputs table rows containing the full author or committer information,
@@ -3267,7 +3341,10 @@ sub git_print_authorship_rows {
32673341 @people = (' author' , ' committer' ) unless @people ;
32683342 foreach my $who (@people ) {
32693343 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 " .
32713348 " <tr>" .
32723349 " <td></td><td> $wd {'rfc2822'}" ;
32733350 print_local_time(%wd );
0 commit comments