From 9dcd534f3e1edb72944fcfb98076cccb36a71df4 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 14 Nov 2011 17:24:16 -0500
Subject: [PATCH] Added optional Gravatar support
---
src/com/gitblit/wicket/GravatarImage.java | 61 ++++++++++++++++++++++++++++++
src/com/gitblit/wicket/pages/CommitPage.java | 5 ++
docs/04_releases.mkd | 9 +++-
distrib/gitblit.properties | 5 ++
src/com/gitblit/wicket/pages/CommitPage.html | 5 ++
5 files changed, 82 insertions(+), 3 deletions(-)
diff --git a/distrib/gitblit.properties b/distrib/gitblit.properties
index 0048e55..083a658 100644
--- a/distrib/gitblit.properties
+++ b/distrib/gitblit.properties
@@ -110,6 +110,11 @@
# 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 90f4f50..5719b19 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*
@@ -34,8 +41,6 @@
- fixed: Gitblit GO allows SSL renegotiation if running on Java 1.6.0_22 or later
- 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*
diff --git a/src/com/gitblit/wicket/GravatarImage.java b/src/com/gitblit/wicket/GravatarImage.java
new file mode 100644
index 0000000..ff26fc0
--- /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<String>(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 f2d328e..2af05e1 100644
--- a/src/com/gitblit/wicket/pages/CommitPage.html
+++ b/src/com/gitblit/wicket/pages/CommitPage.html
@@ -15,6 +15,9 @@
<!-- commit header -->
<div wicket:id="commitHeader">[commit header]</div>
+ <!-- Author Gravatar -->
+ <img style="float:right;vertical-align: top;" wicket:id="authorAvatar" />
+
<!-- commit info -->
<table class="plain">
<tr><th><wicket:message key="gb.refs">refs</wicket:message></th><td><div wicket:id="refsPanel">[references]</div></td></tr>
@@ -53,6 +56,8 @@
<tr><td><span class="sha1" wicket:id="authorName"></span></td></tr>
<tr><td><span class="sha1" wicket:id="authorDate"></span></td></tr>
</table>
+ <!-- Note Author Gravatar -->
+ <img style="vertical-align: top;" wicket:id="noteAuthorAvatar" />
</td>
<td class="message"><span class="sha1" wicket:id="noteContent"></span></td>
</tr>
diff --git a/src/com/gitblit/wicket/pages/CommitPage.java b/src/com/gitblit/wicket/pages/CommitPage.java
index dd3decb..bfe03f1 100644
--- a/src/com/gitblit/wicket/pages/CommitPage.java
+++ b/src/com/gitblit/wicket/pages/CommitPage.java
@@ -38,6 +38,7 @@
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 @@
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 @@
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(
--
Gitblit v1.9.1