From 9dcd534f3e1edb72944fcfb98076cccb36a71df4 Mon Sep 17 00:00:00 2001 From: James Moger Date: Mon, 14 Nov 2011 17:24:16 -0500 Subject: [PATCH] Added optional Gravatar support --- distrib/gitblit.properties | 5 ++ docs/04_releases.mkd | 9 ++- src/com/gitblit/wicket/GravatarImage.java | 61 ++++++++++++++++++++ src/com/gitblit/wicket/pages/CommitPage.html | 5 ++ src/com/gitblit/wicket/pages/CommitPage.java | 5 +- 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 src/com/gitblit/wicket/GravatarImage.java diff --git a/distrib/gitblit.properties b/distrib/gitblit.properties index 0048e555..083a658e 100644 --- a/distrib/gitblit.properties +++ b/distrib/gitblit.properties @@ -110,6 +110,11 @@ web.enableRpcManagement = false # SINCE 0.7.0 web.enableRpcAdministration = false +# Allow Gravatar images to be displayed in Gitblit pages. +# +# SINCE 0.8.0 +web.allowGravatar = true + # Allow dynamic zip downloads. # # SINCE 0.5.0 diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index 90f4f502..5719b191 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -3,6 +3,13 @@ ### Current Release **%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%) | [war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%) | [api](http://code.google.com/p/gitblit/downloads/detail?name=%API%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* +- added: optional Gravatar integration + **New:** *web.allowGravatar = true* + +### Older Releases + +**0.7.0** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.7.0.zip) | [war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.7.0.war) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=fedclient-0.7.0.zip) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=manager-0.7.0.zip) | [api](http://code.google.com/p/gitblit/downloads/detail?name=gbapi-0.7.0.zip)) based on [JGit 1.1.0 (201109151100-r)][jgit]   *released 2011-11-11* + - **security**: fixed security hole when cloning clone-restricted repository with TortoiseGit (issue 28) - improved: updated ui with Twitter's Bootstrap CSS toolkit **New:** *web.loginMessage = gitblit* @@ -35,8 +42,6 @@ - updated: MarkdownPapers 1.2.5 - updated: Wicket 1.4.19 -### Older Releases - **0.6.0** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.6.0.zip) | [war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.6.0.war) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=fedclient-0.6.0.zip)) based on [JGit 1.1.0 (201109151100-r)][jgit]   *released 2011-09-27* - added: federation feature to allow gitblit instances (or gitblit federation clients) to pull repositories and, optionally, settings and accounts from other gitblit instances. This is something like [svn-sync](http://svnbook.red-bean.com/en/1.5/svn.ref.svnsync.html) for gitblit. diff --git a/src/com/gitblit/wicket/GravatarImage.java b/src/com/gitblit/wicket/GravatarImage.java new file mode 100644 index 00000000..ff26fc09 --- /dev/null +++ b/src/com/gitblit/wicket/GravatarImage.java @@ -0,0 +1,61 @@ +/* + * Copyright 2011 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.wicket; + +import java.text.MessageFormat; + +import org.apache.wicket.AttributeModifier; +import org.apache.wicket.markup.ComponentTag; +import org.apache.wicket.markup.html.WebComponent; +import org.apache.wicket.model.Model; +import org.eclipse.jgit.lib.PersonIdent; + +import com.gitblit.GitBlit; +import com.gitblit.Keys; +import com.gitblit.utils.StringUtils; + +/** + * Represents a Gravatar image. + * + * @author James Moger + * + */ +public class GravatarImage extends WebComponent { + + private static final long serialVersionUID = 1L; + + public GravatarImage(String id, PersonIdent person) { + this(id, person, 0); + } + + public GravatarImage(String id, PersonIdent person, int width) { + super(id); + if (width <= 0) { + width = 60; + } + String authorhash = StringUtils.getMD5(person.getEmailAddress().toLowerCase()); + String url = MessageFormat.format("http://www.gravatar.com/avatar/{0}?s={1,number,0}&d=identicon", authorhash, width); + add(new AttributeModifier("src", true, new Model(url))); + setVisible(GitBlit.getBoolean(Keys.web.allowGravatar, true)); + } + + @Override + protected void onComponentTag(ComponentTag tag) { + super.onComponentTag(tag); + checkComponentTag(tag, "img"); + } + +} \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/CommitPage.html b/src/com/gitblit/wicket/pages/CommitPage.html index f2d328e0..2af05e11 100644 --- a/src/com/gitblit/wicket/pages/CommitPage.html +++ b/src/com/gitblit/wicket/pages/CommitPage.html @@ -15,6 +15,9 @@
[commit header]
+ + + @@ -53,6 +56,8 @@
refs
[references]
+ + diff --git a/src/com/gitblit/wicket/pages/CommitPage.java b/src/com/gitblit/wicket/pages/CommitPage.java index dd3decbe..bfe03f12 100644 --- a/src/com/gitblit/wicket/pages/CommitPage.java +++ b/src/com/gitblit/wicket/pages/CommitPage.java @@ -38,6 +38,7 @@ import com.gitblit.Keys; import com.gitblit.models.GitNote; import com.gitblit.models.PathModel.PathChangeModel; import com.gitblit.utils.JGitUtils; +import com.gitblit.wicket.GravatarImage; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.CommitHeaderPanel; import com.gitblit.wicket.panels.CommitLegendPanel; @@ -81,7 +82,8 @@ public class CommitPage extends RepositoryPage { add(createPersonPanel("commitAuthor", c.getAuthorIdent(), Constants.SearchType.AUTHOR)); add(WicketUtils.createTimestampLabel("commitAuthorDate", c.getAuthorIdent().getWhen(), getTimeZone())); - + add(new GravatarImage("authorAvatar", c.getAuthorIdent())); + // committer add(createPersonPanel("commitCommitter", c.getCommitterIdent(), Constants.SearchType.COMMITTER)); add(WicketUtils.createTimestampLabel("commitCommitterDate", @@ -126,6 +128,7 @@ public class CommitPage extends RepositoryPage { item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef))); item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(), Constants.SearchType.AUTHOR)); + item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent())); item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef .getAuthorIdent().getWhen(), getTimeZone())); item.add(new Label("noteContent", GitBlit.self().processCommitMessage( -- 2.39.5