| | |
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.PagesServlet;
|
| | | import com.gitblit.SyndicationServlet;
|
| | | import com.gitblit.models.ProjectModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.SubmoduleModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
| | | 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);
|
| | | if (repositoryName.indexOf('/') > -1) {
|
| | | projectName = repositoryName.substring(0, repositoryName.indexOf('/'));
|
| | | } else {
|
| | | String root =StringUtils.getFirstPathElement(repositoryName);
|
| | | if (StringUtils.isEmpty(root)) {
|
| | | projectName = GitBlit.getString(Keys.web.repositoryRootGroupName, "main");
|
| | | } else {
|
| | | projectName = root;
|
| | | }
|
| | | objectId = WicketUtils.getObject(params);
|
| | |
|
| | |
| | |
|
| | | // standard links
|
| | | pages.put("repositories", new PageRegistration("gb.repositories", RepositoriesPage.class));
|
| | | pages.put("project", new PageRegistration("gb.project", ProjectPage.class, WicketUtils.newProjectParameter(projectName)));
|
| | | 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));
|
| | | pages.put("forks", new PageRegistration("gb.forks", ForksPage.class, params));
|
| | |
|
| | | // conditional links
|
| | | Repository r = getRepository();
|
| | |
| | | }
|
| | |
|
| | | // Conditionally add edit link
|
| | | final boolean showAdmin;
|
| | | showAdmin = false;
|
| | | 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()
|
| | | isOwner = GitBlitWebSession.get().isLoggedIn()
|
| | | && (model.owner != null && model.owner.equalsIgnoreCase(GitBlitWebSession.get()
|
| | | .getUsername()))) {
|
| | | .getUsername()));
|
| | | if (showAdmin || isOwner) {
|
| | | pages.put("edit", new PageRegistration("gb.edit", EditRepositoryPage.class, params));
|
| | | }
|
| | | return pages;
|
| | | }
|
| | | |
| | | protected boolean allowForkControls() {
|
| | | return true;
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | add(new LinkPanel("repositoryName", null, StringUtils.stripDotGit(repositoryName),
|
| | | SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryName)));
|
| | | add(new Label("pageName", pageName).setRenderBodyOnly(true));
|
| | | if (getRepositoryModel().isBare) {
|
| | | add(new Label("workingCopy").setVisible(false));
|
| | | String projectName = StringUtils.getFirstPathElement(repositoryName);
|
| | | ProjectModel project = GitBlit.self().getProjectModel(projectName);
|
| | | if (project.isUserProject()) {
|
| | | // user-as-project
|
| | | add(new LinkPanel("projectTitle", null, project.getDisplayName(),
|
| | | UserPage.class, WicketUtils.newUsernameParameter(project.name.substring(1))));
|
| | | } else {
|
| | | Fragment fragment = new Fragment("workingCopy", "workingCopyFragment", this);
|
| | | Label lbl = new Label("workingCopy", getString("gb.workingCopy"));
|
| | | WicketUtils.setHtmlTooltip(lbl, getString("gb.workingCopyWarning"));
|
| | | fragment.add(lbl);
|
| | | add(fragment);
|
| | | // project
|
| | | 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);
|
| | | }
|
| | | 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;
|
| | | }
|
| | |
|
| | | // indicate origin repository
|
| | | RepositoryModel model = getRepositoryModel();
|
| | | if (StringUtils.isEmpty(model.originRepository)) {
|
| | | add(new Label("originRepository").setVisible(false));
|
| | | } else {
|
| | | RepositoryModel origin = GitBlit.self().getRepositoryModel(model.originRepository);
|
| | | if (origin == null) {
|
| | | // no origin repository
|
| | | add(new Label("originRepository").setVisible(false));
|
| | | } else if (!user.canViewRepository(origin)) {
|
| | | // show origin repository without link
|
| | | Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
|
| | | forkFrag.add(new Label("originRepository", StringUtils.stripDotGit(model.originRepository)));
|
| | | add(forkFrag);
|
| | | } else {
|
| | | // link to origin repository
|
| | | Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
|
| | | forkFrag.add(new LinkPanel("originRepository", null, StringUtils.stripDotGit(model.originRepository), |
| | | SummaryPage.class, WicketUtils.newRepositoryParameter(model.originRepository)));
|
| | | add(forkFrag);
|
| | | }
|
| | | }
|
| | | |
| | | if (getRepositoryModel().isBare) {
|
| | | add(new Label("workingCopyIndicator").setVisible(false));
|
| | | } else {
|
| | | Fragment wc = new Fragment("workingCopyIndicator", "workingCopyFragment", this);
|
| | | Label lbl = new Label("workingCopy", getString("gb.workingCopy"));
|
| | | WicketUtils.setHtmlTooltip(lbl, getString("gb.workingCopyWarning"));
|
| | | wc.add(lbl);
|
| | | add(wc);
|
| | | }
|
| | |
|
| | | // fork controls
|
| | | if (!allowForkControls() || user == null || !user.isAuthenticated) {
|
| | | // must be logged-in to fork, hide all fork controls
|
| | | add(new ExternalLink("forkLink", "").setVisible(false));
|
| | | add(new ExternalLink("myForkLink", "").setVisible(false));
|
| | | add(new Label("forksProhibitedIndicator").setVisible(false));
|
| | | } else {
|
| | | String fork = GitBlit.self().getFork(user.username, model.name);
|
| | | boolean hasFork = fork != null;
|
| | | boolean canFork = user.canForkRepository(model);
|
| | |
|
| | | if (hasFork || !canFork) {
|
| | | // user not allowed to fork or fork already exists or repo forbids forking
|
| | | add(new ExternalLink("forkLink", "").setVisible(false));
|
| | | |
| | | if (user.canFork && !model.allowForks) {
|
| | | // show forks prohibited indicator
|
| | | Fragment wc = new Fragment("forksProhibitedIndicator", "forksProhibitedFragment", this);
|
| | | Label lbl = new Label("forksProhibited", getString("gb.forksProhibited"));
|
| | | WicketUtils.setHtmlTooltip(lbl, getString("gb.forksProhibitedWarning"));
|
| | | wc.add(lbl);
|
| | | add(wc);
|
| | | } else {
|
| | | // can not fork, no need for forks prohibited indicator
|
| | | add(new Label("forksProhibitedIndicator").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();
|
| | | add(new ExternalLink("myForkLink", url));
|
| | | } else {
|
| | | // no fork, hide view my fork link
|
| | | add(new ExternalLink("myForkLink", "").setVisible(false));
|
| | | }
|
| | | } else if (canFork) {
|
| | | // can fork and we do not have one
|
| | | add(new Label("forksProhibitedIndicator").setVisible(false));
|
| | | add(new ExternalLink("myForkLink", "").setVisible(false));
|
| | | String url = getRequestCycle().urlFor(ForkPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
|
| | | add(new ExternalLink("forkLink", url));
|
| | | }
|
| | | }
|
| | | |
| | | super.setupPage(repositoryName, pageName);
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | protected void addRefs(Repository r, RevCommit c) {
|
| | | add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r)));
|
| | | add(new RefsPanel("refsPanel", repositoryName, c, JGitUtils.getAllRefs(r, getRepositoryModel().showRemoteBranches)));
|
| | | }
|
| | |
|
| | | protected void addFullText(String wicketId, String text, boolean substituteRegex) {
|
| | |
| | | return WicketUtils.newObjectParameter(repositoryName, commitId);
|
| | | }
|
| | |
|
| | | public boolean isShowAdmin() {
|
| | | return showAdmin;
|
| | | }
|
| | | |
| | | public boolean isOwner() {
|
| | | return isOwner;
|
| | | }
|
| | | |
| | | private class SearchForm extends SessionlessForm<Void> implements Serializable {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | |
| | | getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
|
| | | }
|
| | | }
|
| | | }
|
| | | } |