| | |
| | | */
|
| | | package com.gitblit.wicket.pages;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.HashMap;
|
| | | import java.util.LinkedHashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Map.Entry;
|
| | |
|
| | | import org.apache.wicket.Component;
|
| | | import org.apache.wicket.PageParameters;
|
| | |
| | | import org.apache.wicket.markup.html.form.DropDownChoice;
|
| | | import org.apache.wicket.markup.html.form.StatelessForm;
|
| | | import org.apache.wicket.markup.html.form.TextField;
|
| | | import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
| | | import org.apache.wicket.markup.html.link.ExternalLink;
|
| | | import org.apache.wicket.markup.html.panel.Fragment;
|
| | | import org.apache.wicket.markup.repeater.Item;
|
| | | import org.apache.wicket.markup.repeater.data.DataView;
|
| | | import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
| | | import org.apache.wicket.model.IModel;
|
| | | import org.apache.wicket.model.Model;
|
| | | import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
| | | import org.eclipse.jgit.lib.PersonIdent;
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.SyndicationServlet;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.JGitUtils.SearchType;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.utils.TicgitUtils;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.PageRegistration;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.LinkPanel;
|
| | | import com.gitblit.wicket.panels.NavigationPanel;
|
| | | import com.gitblit.wicket.panels.RefsPanel;
|
| | |
|
| | | public abstract class RepositoryPage extends BasePage {
|
| | |
| | |
|
| | | private RepositoryModel m;
|
| | |
|
| | | private final Logger logger = LoggerFactory.getLogger(RepositoryPage.class);
|
| | |
|
| | | private final Map<String, String> knownPages = new HashMap<String, String>() {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | {
|
| | | put("summary", "gb.summary");
|
| | | put("log", "gb.log");
|
| | | put("branches", "gb.branches");
|
| | | put("tags", "gb.tags");
|
| | | put("tree", "gb.tree");
|
| | | put("tickets", "gb.tickets");
|
| | | put("edit", "gb.edit");
|
| | | }
|
| | | };
|
| | | private final Map<String, PageRegistration> registeredPages;
|
| | |
|
| | | public RepositoryPage(PageParameters params) {
|
| | | super(params);
|
| | |
| | | error(MessageFormat.format("Repository not specified for {0}!", getPageName()), true);
|
| | | }
|
| | |
|
| | | Repository r = getRepository();
|
| | | RepositoryModel model = getRepositoryModel();
|
| | | if (!getRepositoryModel().hasCommits) {
|
| | | setResponsePage(EmptyRepositoryPage.class, params);
|
| | | }
|
| | |
|
| | | // register the available page links for this page and user
|
| | | registeredPages = registerPages();
|
| | |
|
| | | // standard page links
|
| | | add(new BookmarkablePageLink<Void>("summary", SummaryPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new BookmarkablePageLink<Void>("log", LogPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new BookmarkablePageLink<Void>("branches", BranchesPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new BookmarkablePageLink<Void>("tags", TagsPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new BookmarkablePageLink<Void>("tree", TreePage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | List<PageRegistration> pages = new ArrayList<PageRegistration>(registeredPages.values());
|
| | | NavigationPanel navigationPanel = new NavigationPanel("navPanel", getClass(), pages);
|
| | | add(navigationPanel);
|
| | |
|
| | | // per-repository extra page links
|
| | | List<String> extraPageLinks = new ArrayList<String>();
|
| | |
|
| | | // Conditionally add tickets link
|
| | | if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {
|
| | | extraPageLinks.add("tickets");
|
| | | }
|
| | |
|
| | | // Conditionally add docs link
|
| | | if (model.useDocs) {
|
| | | extraPageLinks.add("docs");
|
| | | }
|
| | |
|
| | | final boolean showAdmin;
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | | } else {
|
| | | showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | }
|
| | |
|
| | | // Conditionally add edit link
|
| | | if (showAdmin
|
| | | || GitBlitWebSession.get().isLoggedIn()
|
| | | && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()
|
| | | .getUser().username))) {
|
| | | extraPageLinks.add("edit");
|
| | | }
|
| | |
|
| | | ListDataProvider<String> extrasDp = new ListDataProvider<String>(extraPageLinks);
|
| | | DataView<String> extrasView = new DataView<String>("extra", extrasDp) {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public void populateItem(final Item<String> item) {
|
| | | String extra = item.getModelObject();
|
| | | if (extra.equals("tickets")) {
|
| | | item.add(new Label("extraSeparator", " | "));
|
| | | item.add(new LinkPanel("extraLink", null, getString("gb.tickets"),
|
| | | TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | } else if (extra.equals("docs")) {
|
| | | item.add(new Label("extraSeparator", " | "));
|
| | | item.add(new LinkPanel("extraLink", null, getString("gb.docs"), DocsPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | } else if (extra.equals("edit")) {
|
| | | item.add(new Label("extraSeparator", " | "));
|
| | | item.add(new LinkPanel("extraLink", null, getString("gb.edit"),
|
| | | EditRepositoryPage.class, WicketUtils
|
| | | .newRepositoryParameter(repositoryName)));
|
| | | }
|
| | | }
|
| | | };
|
| | | add(extrasView);
|
| | |
|
| | | // disable current page
|
| | | disablePageLink(getPageName());
|
| | | add(new ExternalLink("syndication", SyndicationServlet.asLink(getRequest()
|
| | | .getRelativePathPrefixToContextRoot(), repositoryName, null, 0)));
|
| | |
|
| | | // add floating search form
|
| | | SearchForm searchForm = new SearchForm("searchForm", repositoryName);
|
| | |
| | | setStatelessHint(true);
|
| | | }
|
| | |
|
| | | public void disablePageLink(String pageName) {
|
| | | for (String wicketId : knownPages.keySet()) {
|
| | | String key = knownPages.get(wicketId);
|
| | | String linkName = getString(key);
|
| | | if (linkName.equals(pageName)) {
|
| | | Component c = get(wicketId);
|
| | | if (c != null) {
|
| | | c.setEnabled(false);
|
| | | }
|
| | | break;
|
| | | }
|
| | | private Map<String, PageRegistration> registerPages() {
|
| | | PageParameters params = null;
|
| | | if (!StringUtils.isEmpty(repositoryName)) {
|
| | | params = WicketUtils.newRepositoryParameter(repositoryName);
|
| | | }
|
| | | Map<String, PageRegistration> pages = new LinkedHashMap<String, PageRegistration>();
|
| | |
|
| | | // standard links
|
| | | pages.put("repositories", new PageRegistration("gb.repositories", RepositoriesPage.class));
|
| | | pages.put("summary", new PageRegistration("gb.summary", SummaryPage.class, params));
|
| | | pages.put("log", new PageRegistration("gb.log", LogPage.class, params));
|
| | | pages.put("branches", new PageRegistration("gb.branches", BranchesPage.class, params));
|
| | | pages.put("tags", new PageRegistration("gb.tags", TagsPage.class, params));
|
| | | pages.put("tree", new PageRegistration("gb.tree", TreePage.class, params));
|
| | |
|
| | | // conditional links
|
| | | Repository r = getRepository();
|
| | | RepositoryModel model = getRepositoryModel();
|
| | |
|
| | | // per-repository extra page links
|
| | | if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {
|
| | | pages.put("tickets", new PageRegistration("gb.tickets", TicketsPage.class, params));
|
| | | }
|
| | | if (model.useDocs) {
|
| | | pages.put("docs", new PageRegistration("gb.docs", DocsPage.class, params));
|
| | | }
|
| | | // Conditionally add edit link
|
| | | final boolean showAdmin;
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | | } else {
|
| | | showAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | }
|
| | | if (showAdmin
|
| | | || GitBlitWebSession.get().isLoggedIn()
|
| | | && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()
|
| | | .getUser().username))) {
|
| | | pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));
|
| | | }
|
| | | return pages;
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | add(new LinkPanel("repositoryName", null, repositoryName, SummaryPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new Label("pageName", pageName));
|
| | |
|
| | | super.setupPage(repositoryName, pageName);
|
| | | }
|
| | |
|
| | | protected void addSyndicationDiscoveryLink() {
|
| | | add(WicketUtils.syndicationDiscoveryLink(SyndicationServlet.getTitle(repositoryName,
|
| | | objectId), SyndicationServlet.asLink(getRequest()
|
| | | .getRelativePathPrefixToContextRoot(), repositoryName, objectId, 0)));
|
| | | }
|
| | |
|
| | | protected Repository getRepository() {
|
| | |
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(
|
| | | GitBlitWebSession.get().getUser(), repositoryName);
|
| | | if (model == null) {
|
| | | error("Unauthorized access for repository " + repositoryName, true);
|
| | | authenticationError("Unauthorized access for repository " + repositoryName);
|
| | | return null;
|
| | | }
|
| | | m = model;
|
| | |
| | | protected void addFullText(String wicketId, String text, boolean substituteRegex) {
|
| | | String html;
|
| | | if (substituteRegex) {
|
| | | html = substituteText(text);
|
| | | html = GitBlit.self().processCommitMessage(repositoryName, text);
|
| | | } else {
|
| | | html = StringUtils.breakLinesForHtml(text);
|
| | | }
|
| | | add(new Label(wicketId, html).setEscapeModelStrings(false));
|
| | | }
|
| | |
|
| | | protected String substituteText(String text) {
|
| | | String html = StringUtils.breakLinesForHtml(text);
|
| | | Map<String, String> map = new HashMap<String, String>();
|
| | | // global regex keys
|
| | | if (GitBlit.getBoolean(Keys.regex.global, false)) {
|
| | | for (String key : GitBlit.getAllKeys(Keys.regex.global)) {
|
| | | if (!key.equals(Keys.regex.global)) {
|
| | | String subKey = key.substring(key.lastIndexOf('.') + 1);
|
| | | map.put(subKey, GitBlit.getString(key, ""));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // repository-specific regex keys
|
| | | List<String> keys = GitBlit.getAllKeys(Keys.regex._ROOT + "."
|
| | | + repositoryName.toLowerCase());
|
| | | for (String key : keys) {
|
| | | String subKey = key.substring(key.lastIndexOf('.') + 1);
|
| | | map.put(subKey, GitBlit.getString(key, ""));
|
| | | }
|
| | |
|
| | | for (Entry<String, String> entry : map.entrySet()) {
|
| | | String definition = entry.getValue().trim();
|
| | | String[] chunks = definition.split("!!!");
|
| | | if (chunks.length == 2) {
|
| | | html = html.replaceAll(chunks[0], chunks[1]);
|
| | | } else {
|
| | | logger.warn(entry.getKey()
|
| | | + " improperly formatted. Use !!! to separate match from replacement: "
|
| | | + definition);
|
| | | }
|
| | | }
|
| | | return html;
|
| | | }
|
| | |
|
| | | protected abstract String getPageName();
|
| | |
|
| | | protected Component createPersonPanel(String wicketId, PersonIdent identity,
|
| | | SearchType searchType) {
|
| | | Constants.SearchType searchType) {
|
| | | String name = identity == null ? "" : identity.getName();
|
| | | String address = identity == null ? "" : identity.getEmailAddress();
|
| | | boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false);
|
| | | if (!showEmail || StringUtils.isEmpty(identity.getName())
|
| | | || StringUtils.isEmpty(identity.getEmailAddress())) {
|
| | | String value = identity.getName();
|
| | | if (!showEmail || StringUtils.isEmpty(name) || StringUtils.isEmpty(address)) {
|
| | | String value = name;
|
| | | if (StringUtils.isEmpty(value)) {
|
| | | if (showEmail) {
|
| | | value = identity.getEmailAddress();
|
| | | value = address;
|
| | | } else {
|
| | | value = getString("gb.missingUsername");
|
| | | }
|
| | |
| | | return partial;
|
| | | } else {
|
| | | Fragment fullPerson = new Fragment(wicketId, "fullPersonIdent", this);
|
| | | LinkPanel nameLink = new LinkPanel("personName", "list", identity.getName(),
|
| | | SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
|
| | | identity.getName(), searchType));
|
| | | setPersonSearchTooltip(nameLink, identity.getName(), searchType);
|
| | | LinkPanel nameLink = new LinkPanel("personName", "list", name, SearchPage.class,
|
| | | WicketUtils.newSearchParameter(repositoryName, objectId, name, searchType));
|
| | | setPersonSearchTooltip(nameLink, name, searchType);
|
| | | fullPerson.add(nameLink);
|
| | |
|
| | | LinkPanel addressLink = new LinkPanel("personAddress", "list", "<"
|
| | | + identity.getEmailAddress() + ">", SearchPage.class,
|
| | | WicketUtils.newSearchParameter(repositoryName, objectId,
|
| | | identity.getEmailAddress(), searchType));
|
| | | setPersonSearchTooltip(addressLink, identity.getEmailAddress(), searchType);
|
| | | LinkPanel addressLink = new LinkPanel("personAddress", "list", "<" + address + ">",
|
| | | SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
|
| | | address, searchType));
|
| | | setPersonSearchTooltip(addressLink, address, searchType);
|
| | | fullPerson.add(addressLink);
|
| | | return fullPerson;
|
| | | }
|
| | | }
|
| | |
|
| | | protected void setPersonSearchTooltip(Component component, String value, SearchType searchType) {
|
| | | if (searchType.equals(SearchType.AUTHOR)) {
|
| | | protected void setPersonSearchTooltip(Component component, String value, Constants.SearchType searchType) {
|
| | | if (searchType.equals(Constants.SearchType.AUTHOR)) {
|
| | | WicketUtils.setHtmlTooltip(component, getString("gb.searchForAuthor") + " " + value);
|
| | | } else if (searchType.equals(SearchType.COMMITTER)) {
|
| | | } else if (searchType.equals(Constants.SearchType.COMMITTER)) {
|
| | | WicketUtils.setHtmlTooltip(component, getString("gb.searchForCommitter") + " " + value);
|
| | | }
|
| | | }
|
| | |
| | | return WicketUtils.newObjectParameter(repositoryName, commitId);
|
| | | }
|
| | |
|
| | | protected PageParameters newPathParameter(String path) {
|
| | | return WicketUtils.newPathParameter(repositoryName, objectId, path);
|
| | | }
|
| | |
|
| | | private static class SearchForm extends StatelessForm<Void> {
|
| | | private static class SearchForm extends StatelessForm<Void> implements Serializable {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | private final String repositoryName;
|
| | |
|
| | | private final IModel<String> searchBoxModel = new Model<String>("");
|
| | |
|
| | | private final IModel<SearchType> searchTypeModel = new Model<SearchType>(SearchType.COMMIT);
|
| | | private final IModel<Constants.SearchType> searchTypeModel = new Model<Constants.SearchType>(Constants.SearchType.COMMIT);
|
| | |
|
| | | public SearchForm(String id, String repositoryName) {
|
| | | super(id);
|
| | | this.repositoryName = repositoryName;
|
| | | DropDownChoice<SearchType> searchType = new DropDownChoice<SearchType>("searchType",
|
| | | Arrays.asList(SearchType.values()));
|
| | | DropDownChoice<Constants.SearchType> searchType = new DropDownChoice<Constants.SearchType>("searchType",
|
| | | Arrays.asList(Constants.SearchType.values()));
|
| | | searchType.setModel(searchTypeModel);
|
| | | add(searchType.setVisible(GitBlit.getBoolean(Keys.web.showSearchTypeSelection, false)));
|
| | | TextField<String> searchBox = new TextField<String>("searchBox", searchBoxModel);
|
| | |
| | |
|
| | | void setTranslatedAttributes() {
|
| | | WicketUtils.setHtmlTooltip(get("searchType"), getString("gb.searchTypeTooltip"));
|
| | | WicketUtils.setHtmlTooltip(get("searchBox"), getString("gb.searchTooltip"));
|
| | | WicketUtils.setHtmlTooltip(get("searchBox"),
|
| | | MessageFormat.format(getString("gb.searchTooltip"), repositoryName));
|
| | | WicketUtils.setInputPlaceholder(get("searchBox"), getString("gb.search"));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void onSubmit() {
|
| | | SearchType searchType = searchTypeModel.getObject();
|
| | | Constants.SearchType searchType = searchTypeModel.getObject();
|
| | | String searchString = searchBoxModel.getObject();
|
| | | for (SearchType type : SearchType.values()) {
|
| | | if (searchString == null) {
|
| | | // FIXME IE intermittently has no searchString. Wicket bug?
|
| | | return;
|
| | | }
|
| | | for (Constants.SearchType type : Constants.SearchType.values()) {
|
| | | if (searchString.toLowerCase().startsWith(type.name().toLowerCase() + ":")) {
|
| | | searchType = type;
|
| | | searchString = searchString.substring(type.name().toLowerCase().length() + 1)
|