From 058ed1b58e54bf813754e72ca8c37296cf5f704d Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 04 Mar 2014 09:56:23 -0500
Subject: [PATCH] Update contributors list

---
 src/main/java/com/gitblit/wicket/pages/SummaryPage.java |   81 +++++++++++++---------------------------
 1 files changed, 26 insertions(+), 55 deletions(-)

diff --git a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
index 827e079..fdc5d01 100644
--- a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
@@ -40,18 +40,18 @@
 import org.wicketstuff.googlecharts.MarkerType;
 import org.wicketstuff.googlecharts.ShapeMarker;
 
-import com.gitblit.GitBlit;
 import com.gitblit.Keys;
 import com.gitblit.models.Metric;
-import com.gitblit.models.PathModel;
 import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.UserModel;
 import com.gitblit.utils.JGitUtils;
-import com.gitblit.utils.MarkdownUtils;
 import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.CacheControl;
 import com.gitblit.wicket.CacheControl.LastModified;
 import com.gitblit.wicket.GitBlitWebSession;
+import com.gitblit.wicket.MarkupProcessor;
+import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
+import com.gitblit.wicket.MarkupProcessor.MarkupSyntax;
 import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.charting.SecureChart;
 import com.gitblit.wicket.panels.BranchesPanel;
@@ -66,11 +66,11 @@
 	public SummaryPage(PageParameters params) {
 		super(params);
 
-		int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, 20);
+		int numberCommits = app().settings().getInteger(Keys.web.summaryCommitCount, 20);
 		if (numberCommits <= 0) {
 			numberCommits = 20;
 		}
-		int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);
+		int numberRefs = app().settings().getInteger(Keys.web.summaryRefsCount, 5);
 
 		Repository r = getRepository();
 		final RepositoryModel model = getRepositoryModel();
@@ -81,8 +81,8 @@
 
 		List<Metric> metrics = null;
 		Metric metricsTotal = null;
-		if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
-			metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r);
+		if (!model.skipSummaryMetrics && app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
+			metrics = app().repositories().getRepositoryDefaultMetrics(model, r);
 			metricsTotal = metrics.remove(0);
 		}
 
@@ -100,7 +100,7 @@
 			@Override
 			public void populateItem(final Item<String> item) {
 				String ownername = item.getModelObject();
-				UserModel ownerModel = GitBlit.self().getUserModel(ownername);
+				UserModel ownerModel = app().users().getUserModel(ownername);
 				if (ownerModel != null) {
 					item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,
 							WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));
@@ -137,56 +137,27 @@
 		add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
 		add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs, false).hideIfEmpty());
 
-		String htmlText = null;
-		String markdownText = null;
-		String readme = null;
-		boolean isMarkdown = false;
-		try {
+		if (app().settings().getBoolean(Keys.web.summaryShowReadme, false)) {
+			// show a readme on the summary page
+			MarkupDocument markupDoc = null;
 			RevCommit head = JGitUtils.getCommit(r, null);
-			List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
-			List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head);
-			for (PathModel path : paths) {
-				if (!path.isTree()) {
-					String name = path.name.toLowerCase();
-					if (name.equals("readme") || name.equals("readme.txt")) {
-						readme = path.name;
-						isMarkdown = false;
-					} else if (name.startsWith("readme")) {
-						if (name.indexOf('.') > -1) {
-							String ext = name.substring(name.lastIndexOf('.') + 1);
-							if (markdownExtensions.contains(ext)) {
-								readme = path.name;
-								isMarkdown = true;
-								break;
-							}
-						}
-					}
-				}
+			if (head != null) {
+				MarkupProcessor processor = new MarkupProcessor(app().settings());
+				markupDoc = processor.getReadme(r, repositoryName, getBestCommitId(head));
 			}
-			if (!StringUtils.isEmpty(readme)) {
-				String [] encodings = GitBlit.getEncodings();
-				markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);
-				if (isMarkdown) {
-					htmlText = MarkdownUtils.transformMarkdown(markdownText, getLinkRenderer());
-				} else {
-					htmlText = MarkdownUtils.transformPlainText(markdownText);
-				}
+			if (markupDoc == null || markupDoc.markup == null) {
+				add(new Label("readme").setVisible(false));
+			} else {
+				Fragment fragment = new Fragment("readme", MarkupSyntax.PLAIN.equals(markupDoc.syntax) ? "plaintextPanel" : "markdownPanel", this);
+				fragment.add(new Label("readmeFile", markupDoc.documentPath));
+				// Add the html to the page
+				Component content = new Label("readmeContent", markupDoc.html).setEscapeModelStrings(false);
+				fragment.add(content.setVisible(!StringUtils.isEmpty(markupDoc.html)));
+				add(fragment);
 			}
-		} catch (Exception e) {
-			logger.error("failed to transform markdown", e);
-			markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
-			htmlText = MarkdownUtils.transformPlainText(markdownText);
-		}
-
-		if (StringUtils.isEmpty(htmlText)) {
-			add(new Label("readme").setVisible(false));
 		} else {
-			Fragment fragment = new Fragment("readme", isMarkdown ? "markdownPanel" : "plaintextPanel", this);
-			fragment.add(new Label("readmeFile", readme));
-			// Add the html to the page
-			Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false);
-			fragment.add(content.setVisible(!StringUtils.isEmpty(htmlText)));
-			add(fragment);
+			// global, no readme on summary page
+			add(new Label("readme").setVisible(false));
 		}
 
 		// Display an activity line graph
@@ -200,7 +171,7 @@
 
 	private void insertActivityGraph(List<Metric> metrics) {
 		if ((metrics != null) && (metrics.size() > 0)
-				&& GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
+				&& app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {
 			IChartData data = WicketUtils.getChartData(metrics);
 
 			ChartProvider provider = new ChartProvider(new Dimension(290, 100), ChartType.LINE,

--
Gitblit v1.9.1