# SINCE 0.8.0
web.allowGravatar = true
+# Define which class will generate the avatar URL.
+# This class must inherit from com.gitblit.AvatarGenerator
+# It must use a no argument constructor
+#
+# SINCE 1.7.0
+web.avatarClass = com.gitblit.GravatarGenerator
+
# Allow dynamic zip downloads.
#
# SINCE 0.5.0
--- /dev/null
+/*
+ * Copyright 2015 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;
+
+public abstract class AvatarGenerator {
+
+ public abstract String getURL(String username, String emailaddress, boolean identicon, int width);
+
+ /**
+ * A method that can extract custom settings for the avatar generator
+ * The default does nothing, it can be overridden
+ *
+ * @param settings
+ */
+ public void configure(IStoredSettings settings) {
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2015 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;
+
+import com.gitblit.utils.ActivityUtils;
+
+public class GravatarGenerator extends AvatarGenerator {
+
+ public String getURL(String username, String emailaddress,
+ boolean identicon, int width) {
+ String email = emailaddress == null ? username.toLowerCase() : emailaddress.toLowerCase();
+ if (identicon) {
+ return ActivityUtils.getGravatarIdenticonUrl(email, width);
+ } else {
+ return ActivityUtils.getGravatarThumbnailUrl(email, width);
+ }
+ }
+
+}
import ro.fortsoft.pf4j.PluginState;
import ro.fortsoft.pf4j.PluginWrapper;
+import com.gitblit.AvatarGenerator;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.extensions.GitblitWicketPlugin;
}
}
- // customize the Wicket class resolver to load from plugins
+ // customize the Wicket class resolver to load from plugins
IClassResolver coreResolver = getApplicationSettings().getClassResolver();
- PluginClassResolver classResolver = new PluginClassResolver(coreResolver, pluginManager);
- getApplicationSettings().setClassResolver(classResolver);
+ PluginClassResolver classResolver = new PluginClassResolver(coreResolver, pluginManager);
+ getApplicationSettings().setClassResolver(classResolver);
getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
+
+ buildAvatarGenerator();
+
}
/* (non-Javadoc)
public static GitBlitWebApp get() {
return (GitBlitWebApp) WebApplication.get();
}
+
+ AvatarGenerator generator = null;
+ @SuppressWarnings("unchecked")
+ private void buildAvatarGenerator() {
+ Class<AvatarGenerator> clazz;
+ try {
+ clazz = (Class<AvatarGenerator>) getClass().getClassLoader().loadClass(settings.getString(Keys.web.avatarClass, "com.gitblit.GravatarGenerator"));
+ generator = clazz.newInstance();
+ generator.configure(settings);
+ } catch (ClassNotFoundException | SecurityException | InstantiationException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ public String buildAvatarUrl(String username, String emailaddress, String cssClass, int width, boolean identicon) {
+ if (width <= 0) {
+ width = 50;
+ }
+ if(generator != null) {
+ return (String) generator.getURL(username, emailaddress, identicon, width);
+ }
+ return null;
+ }
+
+
}
public abstract TimeZone getTimezone();
+ public String buildAvatarUrl(String username, String emailaddress, String cssClass, int width, boolean identicon);
+
}
\ No newline at end of file
import com.gitblit.wicket.panels.CommitHeaderPanel;
import com.gitblit.wicket.panels.CommitLegendPanel;
import com.gitblit.wicket.panels.DiffStatPanel;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.RefsPanel;
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(new AvatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,
import com.gitblit.wicket.panels.CommitLegendPanel;\r
import com.gitblit.wicket.panels.CompressedDownloadsPanel;\r
import com.gitblit.wicket.panels.DiffStatPanel;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
+import com.gitblit.wicket.panels.AvatarImage;\r
import com.gitblit.wicket.panels.LinkPanel;\r
import com.gitblit.wicket.panels.RefsPanel;\r
\r
item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));\r
item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),\r
Constants.SearchType.AUTHOR));\r
- item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));\r
+ item.add(new AvatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));\r
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef\r
.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));\r
item.add(new Label("noteContent", bugtraqProcessor().processPlainCommitMessage(getRepository(), repositoryName,\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
+import com.gitblit.wicket.panels.AvatarImage;\r
import com.gitblit.wicket.panels.LinkPanel;\r
\r
public class ForksPage extends RepositoryPage {\r
user = new UserModel(repository.projectPath.substring(1));\r
}\r
PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);\r
- item.add(new GravatarImage("anAvatar", ident, 20));\r
+ item.add(new AvatarImage("anAvatar", ident, 20));\r
if (pageRepository.equals(repository)) {\r
// do not link to self\r
item.add(new Label("aProject", user.getDisplayName()));\r
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.SessionlessForm;
import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.AvatarImage;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.NavigationPanel;
boolean standardLogin = authenticationType.isStandard();
if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
- add(new GravatarImage("username", user, "navbarGravatar", 20, false));
+ add(new AvatarImage("username", user, "navbarGravatar", 20, false));
} else {
add(new Label("username", user.getDisplayName()));
}
import com.gitblit.wicket.CacheControl;\r
import com.gitblit.wicket.CacheControl.LastModified;\r
import com.gitblit.wicket.WicketUtils;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
+import com.gitblit.wicket.panels.AvatarImage;\r
import com.gitblit.wicket.panels.LinkPanel;\r
import com.gitblit.wicket.panels.RefsPanel;\r
\r
linkClass = CommitPage.class;\r
break;\r
}\r
- add(new GravatarImage("taggerAvatar", tagRef.getAuthorIdent()));\r
+ add(new AvatarImage("taggerAvatar", tagRef.getAuthorIdent()));\r
\r
add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));\r
add(new Label("tagId", tagRef.getObjectId().getName()));\r
import com.gitblit.wicket.panels.BasePanel.JavascriptTextPrompt;\r
import com.gitblit.wicket.panels.CommentPanel;\r
import com.gitblit.wicket.panels.DiffStatPanel;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
+import com.gitblit.wicket.panels.AvatarImage;\r
import com.gitblit.wicket.panels.IconAjaxLink;\r
import com.gitblit.wicket.panels.LinkPanel;\r
import com.gitblit.wicket.panels.ShockWaveComponent;\r
if (user == null) {\r
user = new UserModel(username);\r
}\r
- item.add(new GravatarImage("participant", user.getDisplayName(),\r
+ item.add(new AvatarImage("participant", user.getDisplayName(),\r
user.emailAddress, null, 25, true));\r
}\r
};\r
} else {\r
// permit user to comment\r
Fragment newComment = new Fragment("newComment", "newCommentFragment", this);\r
- GravatarImage img = new GravatarImage("newCommentAvatar", user.username, user.emailAddress,\r
+ AvatarImage img = new AvatarImage("newCommentAvatar", user.username, user.emailAddress,\r
"gravatar-round", avatarWidth, true);\r
newComment.add(img);\r
CommentPanel commentPanel = new CommentPanel("commentPanel", user, ticket, null, TicketsPage.class);\r
public void populateItem(final Item<RevCommit> item) {\r
RevCommit commit = item.getModelObject();\r
PersonIdent author = commit.getAuthorIdent();\r
- item.add(new GravatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));\r
+ item.add(new AvatarImage("authorAvatar", author.getName(), author.getEmailAddress(), null, 16, false));\r
item.add(new Label("author", commit.getAuthorIdent().getName()));\r
item.add(new LinkPanel("commitId", null, getShortObjectId(commit.getName()),\r
CommitPage.class, WicketUtils.newObjectParameter(repositoryName, commit.getName()), true));\r
UserModel commenter = app().users().getUserModel(entry.author);\r
if (commenter == null) {\r
// unknown user\r
- container.add(new GravatarImage("changeAvatar", entry.author,\r
+ container.add(new AvatarImage("changeAvatar", entry.author,\r
entry.author, null, avatarSize, false).setVisible(avatarSize > 0));\r
container.add(new Label("changeAuthor", entry.author.toLowerCase()));\r
} else {\r
// known user\r
- container.add(new GravatarImage("changeAvatar", commenter.getDisplayName(),\r
+ container.add(new AvatarImage("changeAvatar", commenter.getDisplayName(),\r
commenter.emailAddress, avatarSize > 24 ? "gravatar-round" : null,\r
avatarSize, true).setVisible(avatarSize > 0));\r
container.add(new LinkPanel("changeAuthor", null, commenter.getDisplayName(),\r
.getWhen(), getTimeZone(), getTimeUtils()));\r
\r
// avatar\r
- commitItem.add(new GravatarImage("avatar", commit.getAuthorIdent(), 40));\r
+ commitItem.add(new AvatarImage("avatar", commit.getAuthorIdent(), 40));\r
\r
// merge icon\r
if (commit.getParentCount() > 1) {\r
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml" \r
+ xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd" \r
+ xml:lang="en" \r
+ lang="en">\r
+<wicket:panel>\r
+<img wicket:id="image"></img>\r
+</wicket:panel>\r
+</html>
\ No newline at end of file
--- /dev/null
+/*
+ * 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.panels;
+
+import org.eclipse.jgit.lib.PersonIdent;
+
+import com.gitblit.Keys;
+import com.gitblit.models.UserModel;
+import com.gitblit.wicket.ExternalImage;
+import com.gitblit.wicket.WicketUtils;
+
+/**
+ * Represents a Gravatar image.
+ *
+ * @author James Moger
+ *
+ */
+public class AvatarImage extends BasePanel {
+
+ private static final long serialVersionUID = 1L;
+
+ public AvatarImage(String id, PersonIdent person) {
+ this(id, person, 0);
+ }
+
+ public AvatarImage(String id, PersonIdent person, int width) {
+ this(id, person.getName(), person.getEmailAddress(), "gravatar", width, true);
+ }
+
+ public AvatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
+ this(id, person.getName(), person.getEmailAddress(), cssClass, width, identicon);
+ }
+
+ public AvatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
+ this(id, user.getDisplayName(), user.emailAddress, cssClass, width, identicon);
+ }
+
+ public AvatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
+ super(id);
+
+ String url = app().buildAvatarUrl(username, emailaddress, cssClass, width, identicon);
+ ExternalImage image = new ExternalImage("image", url);
+ if (cssClass != null) {
+ WicketUtils.setCssClass(image, cssClass);
+ }
+ add(image);
+ WicketUtils.setHtmlTooltip(image, username);
+ setVisible(app().settings().getBoolean(Keys.web.allowGravatar, true));
+ }
+
+ public void setTooltip(String tooltip) {
+ WicketUtils.setHtmlTooltip(get("image"), tooltip);
+ }
+}
\ No newline at end of file
add(new Label("commitid", c.getName()));\r
add(new Label("author", c.getAuthorIdent().getName()));\r
add(WicketUtils.createDateLabel("date", c.getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));\r
- add(new GravatarImage("authorAvatar", c.getAuthorIdent()));\r
+ add(new AvatarImage("authorAvatar", c.getAuthorIdent()));\r
}\r
}
\ No newline at end of file
final RepositoryCommit commit = commitItem.getModelObject();
// author gravatar
- commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
+ commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
// merge icon
if (commit.getParentCount() > 1) {
+++ /dev/null
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml" \r
- xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd" \r
- xml:lang="en" \r
- lang="en">\r
-<wicket:panel>\r
-<img wicket:id="image"></img>\r
-</wicket:panel>\r
-</html>
\ No newline at end of file
+++ /dev/null
-/*
- * 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.panels;
-
-import org.eclipse.jgit.lib.PersonIdent;
-
-import com.gitblit.Keys;
-import com.gitblit.models.UserModel;
-import com.gitblit.utils.ActivityUtils;
-import com.gitblit.wicket.ExternalImage;
-import com.gitblit.wicket.WicketUtils;
-
-/**
- * Represents a Gravatar image.
- *
- * @author James Moger
- *
- */
-public class GravatarImage extends BasePanel {
-
- private static final long serialVersionUID = 1L;
-
- public GravatarImage(String id, PersonIdent person) {
- this(id, person, 0);
- }
-
- public GravatarImage(String id, PersonIdent person, int width) {
- this(id, person.getName(), person.getEmailAddress(), "gravatar", width, true);
- }
-
- public GravatarImage(String id, PersonIdent person, String cssClass, int width, boolean identicon) {
- this(id, person.getName(), person.getEmailAddress(), cssClass, width, identicon);
- }
-
- public GravatarImage(String id, UserModel user, String cssClass, int width, boolean identicon) {
- this(id, user.getDisplayName(), user.emailAddress, cssClass, width, identicon);
- }
-
- public GravatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean identicon) {
- super(id);
-
- String email = emailaddress == null ? username.toLowerCase() : emailaddress.toLowerCase();
- String url;
- if (identicon) {
- url = ActivityUtils.getGravatarIdenticonUrl(email, width);
- } else {
- url = ActivityUtils.getGravatarThumbnailUrl(email, width);
- }
- ExternalImage image = new ExternalImage("image", url);
- if (cssClass != null) {
- WicketUtils.setCssClass(image, cssClass);
- }
- add(image);
- WicketUtils.setHtmlTooltip(image, username);
- setVisible(app().settings().getBoolean(Keys.web.allowGravatar, true));
- }
-
- public void setTooltip(String tooltip) {
- WicketUtils.setHtmlTooltip(get("image"), tooltip);
- }
-}
\ No newline at end of file
final RepositoryCommit commit = commitItem.getModelObject();
// author gravatar
- commitItem.add(new GravatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
+ commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
// merge icon
if (commit.getParentCount() > 1) {
}
Fragment userFragment = new Fragment("registrant", "userRegistrant", RegistrantPermissionsPanel.this);
- userFragment.add(new GravatarImage("userAvatar", ident, 20));
+ userFragment.add(new AvatarImage("userAvatar", ident, 20));
userFragment.add(new Label("userName", entry.registrant));
item.add(userFragment);
} else {
if (responsible == null) {
responsible = new UserModel(ticket.responsible);
}
- GravatarImage avatar = new GravatarImage("responsible", responsible.getDisplayName(),
+ AvatarImage avatar = new AvatarImage("responsible", responsible.getDisplayName(),
responsible.emailAddress, null, 16, true);
avatar.setTooltip(getString("gb.responsible") + ": " + responsible.getDisplayName());
item.add(avatar);
\r
public UserTitlePanel(String wicketId, UserModel user, String title) {\r
super(wicketId);\r
- add(new GravatarImage("userGravatar", user, "gravatar", 36, false));\r
+ add(new AvatarImage("userGravatar", user, "gravatar", 36, false));\r
add(new Label("userDisplayName", user.getDisplayName()));\r
add(new Label("userTitle", title));\r
}\r
--- /dev/null
+package com.gitblit.tests;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.gitblit.IStoredSettings;
+import com.gitblit.Keys;
+import com.gitblit.manager.AuthenticationManager;
+import com.gitblit.manager.FederationManager;
+import com.gitblit.manager.GitblitManager;
+import com.gitblit.manager.IAuthenticationManager;
+import com.gitblit.manager.IFederationManager;
+import com.gitblit.manager.IGitblit;
+import com.gitblit.manager.INotificationManager;
+import com.gitblit.manager.IPluginManager;
+import com.gitblit.manager.IProjectManager;
+import com.gitblit.manager.IRepositoryManager;
+import com.gitblit.manager.IRuntimeManager;
+import com.gitblit.manager.IServicesManager;
+import com.gitblit.manager.IUserManager;
+import com.gitblit.manager.NotificationManager;
+import com.gitblit.manager.PluginManager;
+import com.gitblit.manager.ProjectManager;
+import com.gitblit.manager.RepositoryManager;
+import com.gitblit.manager.RuntimeManager;
+import com.gitblit.manager.ServicesManager;
+import com.gitblit.manager.UserManager;
+import com.gitblit.tests.mock.MemorySettings;
+import com.gitblit.tickets.FileTicketService;
+import com.gitblit.tickets.ITicketService;
+import com.gitblit.transport.ssh.IPublicKeyManager;
+import com.gitblit.transport.ssh.MemoryKeyManager;
+import com.gitblit.utils.IdGenerator;
+import com.gitblit.utils.WorkQueue;
+import com.gitblit.utils.XssFilter;
+import com.gitblit.utils.XssFilter.AllowXssFilter;
+import com.gitblit.wicket.GitBlitWebApp;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class GravatarTest extends GitblitUnitTest {
+
+ public static class SomeModule extends AbstractModule {
+ private final IStoredSettings settings = new MemorySettings();
+ SomeModule() {
+ settings.overrideSetting(Keys.web.avatarClass, "com.gitblit.GravatarGenerator");
+ }
+ @Override
+ protected void configure() {
+ bind(IGitblit.class).to(GitblitManager.class);
+ bind(IAuthenticationManager.class).to(AuthenticationManager.class);
+ bind(IFederationManager.class).to(FederationManager.class);
+ bind(INotificationManager.class).to(NotificationManager.class);
+ bind(IPluginManager.class).to(PluginManager.class);
+ bind(IRepositoryManager.class).to(RepositoryManager.class);
+ bind(IProjectManager.class).to(ProjectManager.class);
+ bind(IRuntimeManager.class).to(RuntimeManager.class);
+ bind(IUserManager.class).to(UserManager.class);
+ bind(ITicketService.class).to(FileTicketService.class);
+ bind(XssFilter.class).to(AllowXssFilter.class);
+ bind(IStoredSettings.class).toInstance(settings);
+ bind(IPublicKeyManager.class).to(MemoryKeyManager.class);
+ bind(IServicesManager.class).to(ServicesManager.class);
+ bind(WorkQueue.class).toInstance(new WorkQueue(new IdGenerator(), 0));
+ }
+ }
+
+ @Test
+ public void oneTest() {
+ Injector injector = Guice.createInjector(new SomeModule());
+ GitBlitWebApp webapp = injector.getInstance(GitBlitWebApp.class);
+ webapp.init();
+ Assert.assertNotNull(webapp.buildAvatarUrl("username", "emailaddress", "cssClass", 10, true));
+ }
+
+}