From e9dac2e9ead1decb8abb1bf9df3cd638a2f5eb04 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 15 Oct 2013 08:13:04 -0400
Subject: [PATCH] Merge pull request #118 from Mrbytes/master

---
 src/main/java/com/gitblit/wicket/pages/RepositoryPage.java |  111 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 69 insertions(+), 42 deletions(-)

diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
index 774604f..e5ce22a 100644
--- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
@@ -19,6 +19,7 @@
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -62,7 +63,7 @@
 import com.gitblit.utils.JGitUtils;
 import com.gitblit.utils.RefLogUtils;
 import com.gitblit.utils.StringUtils;
-import com.gitblit.utils.TicgitUtils;
+import com.gitblit.wicket.CacheControl;
 import com.gitblit.wicket.GitBlitWebSession;
 import com.gitblit.wicket.PageRegistration;
 import com.gitblit.wicket.PageRegistration.OtherPageLink;
@@ -73,25 +74,25 @@
 import com.gitblit.wicket.panels.RefsPanel;
 
 public abstract class RepositoryPage extends RootPage {
-	
+
 	private final Logger logger = LoggerFactory.getLogger(getClass());
 
 	private final String PARAM_STAR = "star";
-	
+
 	protected final String projectName;
 	protected final String repositoryName;
 	protected final String objectId;
-	
+
 	private transient Repository r;
 
 	private RepositoryModel m;
 
 	private Map<String, SubmoduleModel> submodules;
-	
+
 	private final Map<String, PageRegistration> registeredPages;
 	private boolean showAdmin;
 	private boolean isOwner;
-	
+
 	public RepositoryPage(PageParameters params) {
 		super(params);
 		repositoryName = WicketUtils.getRepositoryName(params);
@@ -102,7 +103,7 @@
 			projectName = root;
 		}
 		objectId = WicketUtils.getObject(params);
-		
+
 		if (StringUtils.isEmpty(repositoryName)) {
 			error(MessageFormat.format(getString("gb.repositoryNotSpecifiedFor"), getPageName()), true);
 		}
@@ -110,11 +111,11 @@
 		if (!getRepositoryModel().hasCommits) {
 			setResponsePage(EmptyRepositoryPage.class, params);
 		}
-		
+
 		if (getRepositoryModel().isCollectingGarbage) {
 			error(MessageFormat.format(getString("gb.busyCollectingGarbage"), getRepositoryModel().name), true);
 		}
-		
+
 		if (objectId != null) {
 			RefModel branch = null;
 			if ((branch = JGitUtils.getBranch(getRepository(), objectId)) != null) {
@@ -130,7 +131,7 @@
 				}
 			}
 		}
-		
+
 		if (params.containsKey(PARAM_STAR)) {
 			// set starred state
 			boolean star = params.getBoolean(PARAM_STAR);
@@ -166,7 +167,7 @@
 		// set stateless page preference
 		setStatelessHint(true);
 	}
-	
+
 	@Override
 	protected Class<? extends BasePage> getRootNavPageClass() {
 		return RepositoriesPage.class;
@@ -175,7 +176,7 @@
 	protected Class<? extends BasePage> getRepoNavPageClass() {
 		return getClass();
 	}
-	
+
 	private Map<String, PageRegistration> registerPages() {
 		PageParameters params = null;
 		if (!StringUtils.isEmpty(repositoryName)) {
@@ -193,7 +194,7 @@
 			pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
 //			pages.put("overview", new PageRegistration("gb.overview", OverviewPage.class, params));
 			pages.put("reflog", new PageRegistration("gb.reflog", ReflogPage.class, params));
-		}		
+		}
 		pages.put("commits", new PageRegistration("gb.commits", LogPage.class, params));
 		pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));
 		pages.put("compare", new PageRegistration("gb.compare", ComparePage.class, params, true));
@@ -203,9 +204,6 @@
 
 		// conditional links
 		// per-repository extra page links
-		if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {
-			pages.put("tickets", new PageRegistration("gb.tickets", TicketsPage.class, params, true));
-		}
 		if (model.showReadme || model.useDocs) {
 			pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params, true));
 		}
@@ -228,7 +226,7 @@
 						.getUsername()));
 		return pages;
 	}
-	
+
 	protected boolean allowForkControls() {
 		return GitBlit.getBoolean(Keys.web.allowForking, true);
 	}
@@ -246,7 +244,7 @@
 			add(new LinkPanel("projectTitle", null, project.name,
 					ProjectPage.class, WicketUtils.newProjectParameter(project.name)));
 		}
-		
+
 		String name = StringUtils.stripDotGit(repositoryName);
 		if (!StringUtils.isEmpty(projectName) && name.startsWith(projectName)) {
 			name = name.substring(projectName.length() + 1);
@@ -254,7 +252,7 @@
 		add(new LinkPanel("repositoryName", null, name, SummaryPage.class,
 				WicketUtils.newRepositoryParameter(repositoryName)));
 		add(new Label("pageName", pageName).setRenderBodyOnly(true));
-		
+
 		UserModel user = GitBlitWebSession.get().getUser();
 		if (user == null) {
 			user = UserModel.ANONYMOUS;
@@ -277,12 +275,12 @@
 			} else {
 				// link to origin repository
 				Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
-				forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(model.originRepository), 
+				forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(model.originRepository),
 						SummaryPage.class, WicketUtils.newRepositoryParameter(model.originRepository)));
 				add(forkFrag);
 			}
 		}
-		
+
 		// (un)star link allows a user to star a repository
 		if (user.isAuthenticated) {
 			PageParameters starParams = DeepCopier.copy(getPageParameters());
@@ -316,7 +314,7 @@
 			if (hasFork || !canFork) {
 				// user not allowed to fork or fork already exists or repo forbids forking
 				add(new ExternalLink("forkLink", "").setVisible(false));
-				
+
 				if (hasFork && !fork.equals(model.name)) {
 					// user has fork, view my fork link
 					String url = getRequestCycle().urlFor(SummaryPage.class, WicketUtils.newRepositoryParameter(fork)).toString();
@@ -332,17 +330,17 @@
 				add(new ExternalLink("forkLink", url));
 			}
 		}
-		
+
 		if (showAdmin || isOwner) {
 			String url = getRequestCycle().urlFor(EditRepositoryPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
-			add(new ExternalLink("editLink", url)); 
+			add(new ExternalLink("editLink", url));
 		} else {
 			add(new Label("editLink").setVisible(false));
 		}
-		
+
 		super.setupPage(repositoryName, pageName);
 	}
-	
+
 	protected void addToolbarButton(String wicketId, String iconClass, String label, String url) {
 		Fragment button = new Fragment(wicketId, "toolbarLinkFragment", this);
 		Label icon = new Label("icon");
@@ -400,8 +398,8 @@
 		getSubmodules(commit);
 		return commit;
 	}
-	
-	protected Map<String, SubmoduleModel> getSubmodules(RevCommit commit) {	
+
+	protected Map<String, SubmoduleModel> getSubmodules(RevCommit commit) {
 		if (submodules == null) {
 			submodules = new HashMap<String, SubmoduleModel>();
 			for (SubmoduleModel model : JGitUtils.getSubmodules(r, commit.getTree())) {
@@ -410,7 +408,7 @@
 		}
 		return submodules;
 	}
-	
+
 	protected SubmoduleModel getSubmodule(String path) {
 		SubmoduleModel model = null;
 		if (submodules != null) {
@@ -426,7 +424,7 @@
 			// extract the repository name from the clone url
 			List<String> patterns = GitBlit.getStrings(Keys.git.submoduleUrlPatterns);
 			String submoduleName = StringUtils.extractRepositoryPath(model.url, patterns.toArray(new String[0]));
-			
+
 			// determine the current path for constructing paths relative
 			// to the current repository
 			String currentPath = "";
@@ -446,7 +444,7 @@
 			if (submoduleName.lastIndexOf('/') > -1) {
 				String name = submoduleName.substring(submoduleName.lastIndexOf('/') + 1);
 				candidates.add(currentPath + StringUtils.stripDotGit(name));
-				candidates.add(currentPath + candidates.get(candidates.size() - 1) + ".git");
+				candidates.add(candidates.get(candidates.size() - 1) + ".git");
 			}
 
 			// absolute
@@ -469,11 +467,11 @@
 					return model;
 				}
 			}
-			
+
 			// we do not have a copy of the submodule, but we need a path
 			model.gitblitPath = candidates.get(0);
 			return model;
-		}		
+		}
 	}
 
 	protected String getShortObjectId(String objectId) {
@@ -484,12 +482,17 @@
 		add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r, getRepositoryModel().showRemoteBranches)));
 	}
 
-	protected void addFullText(String wicketId, String text, boolean substituteRegex) {
-		String html = StringUtils.escapeForHtml(text, false);
-		if (substituteRegex) {
-			html = GitBlit.self().processCommitMessage(repositoryName, html);
-		} else {
-			html = StringUtils.breakLinesForHtml(html);
+	protected void addFullText(String wicketId, String text) {
+		RepositoryModel model = getRepositoryModel();
+		String content = GitBlit.self().processCommitMessage(model, text);
+		String html;
+		switch (model.commitMessageRenderer) {
+		case MARKDOWN:
+			html = MessageFormat.format("<div class='commit_message'>{0}</div>", content);
+			break;
+		default:
+			html = MessageFormat.format("<pre class='commit_message'>{0}</pre>", content);
+			break;
 		}
 		add(new Label(wicketId, html).setEscapeModelStrings(false));
 	}
@@ -573,6 +576,30 @@
 		super.onBeforeRender();
 	}
 
+	@Override
+	protected void setLastModified() {
+		if (getClass().isAnnotationPresent(CacheControl.class)) {
+			CacheControl cacheControl = getClass().getAnnotation(CacheControl.class);
+			switch (cacheControl.value()) {
+			case REPOSITORY:
+				RepositoryModel repository = getRepositoryModel();
+				if (repository != null) {
+					setLastModified(repository.lastChange);
+				}
+				break;
+			case COMMIT:
+				RevCommit commit = getCommit();
+				if (commit != null) {
+					Date commitDate = JGitUtils.getCommitDate(commit);
+					setLastModified(commitDate);
+				}
+				break;
+			default:
+				super.setLastModified();
+			}
+		}
+	}
+
 	protected PageParameters newRepositoryParameter() {
 		return WicketUtils.newRepositoryParameter(repositoryName);
 	}
@@ -588,11 +615,11 @@
 	public boolean isShowAdmin() {
 		return showAdmin;
 	}
-	
+
 	public boolean isOwner() {
 		return isOwner;
 	}
-	
+
 	private class SearchForm extends SessionlessForm<Void> implements Serializable {
 		private static final long serialVersionUID = 1L;
 
@@ -626,7 +653,7 @@
 			Constants.SearchType searchType = searchTypeModel.getObject();
 			String searchString = searchBoxModel.getObject();
 			if (StringUtils.isEmpty(searchString)) {
-				// redirect to self to avoid wicket page update bug 
+				// redirect to self to avoid wicket page update bug
 				PageParameters params = RepositoryPage.this.getPageParameters();
 				String relativeUrl = urlFor(RepositoryPage.this.getClass(), params).toString();
 				String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);

--
Gitblit v1.9.1