]> source.dussan.org Git - gitblit.git/commitdiff
Integrate admin menu into user menu and add user menu extension
authorJames Moger <james.moger@gitblit.com>
Tue, 22 Apr 2014 20:08:52 +0000 (16:08 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 5 May 2014 15:19:31 +0000 (11:19 -0400)
12 files changed:
src/main/java/com/gitblit/extensions/UserMenuExtension.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/GitBlitWebApp.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
src/main/java/com/gitblit/wicket/PageRegistration.java
src/main/java/com/gitblit/wicket/pages/RootPage.html
src/main/java/com/gitblit/wicket/pages/RootPage.java
src/main/java/com/gitblit/wicket/pages/TeamsPage.html [new file with mode: 0644]
src/main/java/com/gitblit/wicket/pages/TeamsPage.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/pages/UsersPage.html
src/main/java/com/gitblit/wicket/pages/UsersPage.java
src/main/java/com/gitblit/wicket/panels/NavigationPanel.java
src/site/plugins_extensions.mkd

diff --git a/src/main/java/com/gitblit/extensions/UserMenuExtension.java b/src/main/java/com/gitblit/extensions/UserMenuExtension.java
new file mode 100644 (file)
index 0000000..078dbfd
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2014 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.extensions;
+
+import java.util.List;
+
+import ro.fortsoft.pf4j.ExtensionPoint;
+
+import com.gitblit.models.Menu.MenuItem;
+import com.gitblit.models.UserModel;
+
+/**
+ * Extension point to contribute user menu items.
+ *
+ * @author James Moger
+ * @since 1.6.0
+ *
+ */
+public abstract class UserMenuExtension implements ExtensionPoint {
+
+       /**
+        * @param user
+        * @since 1.6.0
+        * @return a list of menu items
+        */
+       public abstract List<MenuItem> getMenuItems(UserModel user);
+}
index dc79af26533f2d87490e81ed3ce490e9b2c832bd..3ca7d48fd89b69fced11d89cd2d0b0c58aa6dd7a 100644 (file)
@@ -77,6 +77,7 @@ import com.gitblit.wicket.pages.ReviewProposalPage;
 import com.gitblit.wicket.pages.SummaryPage;
 import com.gitblit.wicket.pages.TagPage;
 import com.gitblit.wicket.pages.TagsPage;
+import com.gitblit.wicket.pages.TeamsPage;
 import com.gitblit.wicket.pages.TicketsPage;
 import com.gitblit.wicket.pages.TreePage;
 import com.gitblit.wicket.pages.UserPage;
@@ -181,6 +182,7 @@ public class GitBlitWebApp extends WebApplication {
                mount("/metrics", MetricsPage.class, "r");
                mount("/blame", BlamePage.class, "r", "h", "f");
                mount("/users", UsersPage.class);
+               mount("/teams", TeamsPage.class);
                mount("/logout", LogoutPage.class);
 
                // setup ticket urls
index 2c83dd6c7be4a444d61a62305f948483a3d3bcb1..d0c2d48c67bbe93e8c2caf63cedd683a77e0cdcc 100644 (file)
@@ -680,4 +680,7 @@ gb.notifyChangedOpenTickets = send notification for changed open tickets
 gb.overdue = overdue
 gb.openMilestones = open milestones
 gb.closedMilestones = closed milestones
-gb.adminMenuItem = admin
+gb.administration = administration
+gb.plugins = plugins
+gb.extensions = extensions
+
index ff4a55b4414a8bb2b819289552548a400d58a8e7..9fd8f87072338429543ff9e8922495d1bcdb5758 100644 (file)
@@ -67,13 +67,13 @@ public class PageRegistration implements Serializable {
 \r
                public final String url;\r
 \r
-               public OtherPageLink(String translationKey, String url) {\r
-                       super(translationKey, null);\r
+               public OtherPageLink(String keyOrText, String url) {\r
+                       super(keyOrText, null);\r
                        this.url = url;\r
                }\r
 \r
-               public OtherPageLink(String translationKey, String url, boolean hiddenPhone) {\r
-                       super(translationKey, null, null, hiddenPhone);\r
+               public OtherPageLink(String keyOrText, String url, boolean hiddenPhone) {\r
+                       super(keyOrText, null, null, hiddenPhone);\r
                        this.url = url;\r
                }\r
        }\r
@@ -90,8 +90,8 @@ public class PageRegistration implements Serializable {
 \r
                public final List<MenuItem> menuItems;\r
 \r
-               public DropDownMenuRegistration(String translationKey, Class<? extends WebPage> pageClass) {\r
-                       super(translationKey, pageClass);\r
+               public DropDownMenuRegistration(String keyOrText, Class<? extends WebPage> pageClass) {\r
+                       super(keyOrText, pageClass);\r
                        menuItems = new ArrayList<MenuItem>();\r
                }\r
        }\r
index 11f7f38d0659dd324fe9c8c7180b5de2556e77a5..2ff305f2a76b9f4370d63b07316ec5b0dba28053 100644 (file)
                <li class="dropdown">\r
                        <a data-toggle="dropdown" class="dropdown-toggle" style="text-decoration: none;" href="#"><span wicket:id="username"></span> <b class="caret"></b></a>\r
                <ul class="dropdown-menu">\r
-                       <li style="color:#ccc;padding-left:15px;font-weight:bold;"><span wicket:id="displayName"></span></li>\r
-                       <li class="divider"></li>\r
-               <li><a wicket:id="newRepository"><wicket:message key="gb.newRepository"></wicket:message></a></li>\r
-               <li><a wicket:id="myProfile"><wicket:message key="gb.myProfile"></wicket:message></a></li>\r
-               <li><a wicket:id="changePassword"><wicket:message key="gb.changePassword"></wicket:message></a></li>\r
-               <li class="divider"></li>\r
+               <span wicket:id="standardMenu"></span>\r
+               <span wicket:id="adminMenu"></span>\r
+               <span wicket:id="extensionsMenu"></span>\r
                        <li><a wicket:id="logout"><wicket:message key="gb.logout"></wicket:message></a></li>\r
                        </ul>\r
                </li>\r
        </wicket:fragment>\r
+\r
+       <wicket:fragment wicket:id="submenuFragment">\r
+               <li style="color:#ccc;padding-left:15px;font-weight:bold;"><span wicket:id="submenuTitle"></span></li>\r
+               <li wicket:id="submenuItem"><span wicket:id="submenuLink"></span></li>\r
+       </wicket:fragment>\r
        \r
 </wicket:extend>\r
 </body>\r
index b9055c13711109da79fdc849c695e6fde8aeae51..3003c70ec013bf8c50ca799c420118056e19b674 100644 (file)
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.wicket.pages;\r
-\r
-import java.text.MessageFormat;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Calendar;\r
-import java.util.Collections;\r
-import java.util.Date;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.LinkedHashSet;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.TreeSet;\r
-import java.util.concurrent.atomic.AtomicInteger;\r
-import java.util.regex.Pattern;\r
-\r
-import org.apache.wicket.MarkupContainer;\r
-import org.apache.wicket.PageParameters;\r
-import org.apache.wicket.behavior.HeaderContributor;\r
-import org.apache.wicket.markup.html.IHeaderContributor;\r
-import org.apache.wicket.markup.html.IHeaderResponse;\r
-import org.apache.wicket.markup.html.basic.Label;\r
-import org.apache.wicket.markup.html.form.PasswordTextField;\r
-import org.apache.wicket.markup.html.form.TextField;\r
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;\r
-import org.apache.wicket.markup.html.panel.Fragment;\r
-import org.apache.wicket.model.IModel;\r
-import org.apache.wicket.model.Model;\r
-import org.apache.wicket.protocol.http.WebResponse;\r
-\r
-import com.gitblit.Constants;\r
-import com.gitblit.Keys;\r
-import com.gitblit.extensions.AdminMenuExtension;\r
-import com.gitblit.models.Menu.MenuDivider;\r
-import com.gitblit.models.Menu.MenuItem;\r
-import com.gitblit.models.Menu.PageLinkMenuItem;\r
-import com.gitblit.models.Menu.ParameterMenuItem;\r
-import com.gitblit.models.Menu.ToggleMenuItem;\r
-import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.TeamModel;\r
-import com.gitblit.models.UserModel;\r
-import com.gitblit.utils.ModelUtils;\r
-import com.gitblit.utils.StringUtils;\r
-import com.gitblit.wicket.GitBlitWebSession;\r
-import com.gitblit.wicket.PageRegistration;\r
-import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;\r
-import com.gitblit.wicket.SessionlessForm;\r
-import com.gitblit.wicket.WicketUtils;\r
-import com.gitblit.wicket.panels.GravatarImage;\r
-import com.gitblit.wicket.panels.NavigationPanel;\r
-\r
-/**\r
- * Root page is a topbar, navigable page like Repositories, Users, or\r
- * Federation.\r
- *\r
- * @author James Moger\r
- *\r
- */\r
-public abstract class RootPage extends BasePage {\r
-\r
-       boolean showAdmin;\r
-\r
-       IModel<String> username = new Model<String>("");\r
-       IModel<String> password = new Model<String>("");\r
-       List<RepositoryModel> repositoryModels = new ArrayList<RepositoryModel>();\r
-\r
-       public RootPage() {\r
-               super();\r
-       }\r
-\r
-       public RootPage(PageParameters params) {\r
-               super(params);\r
-       }\r
-\r
-       @Override\r
-       protected void setupPage(String repositoryName, String pageName) {\r
-\r
-               // CSS header overrides\r
-               add(new HeaderContributor(new IHeaderContributor() {\r
-                       private static final long serialVersionUID = 1L;\r
-\r
-                       @Override\r
-                       public void renderHead(IHeaderResponse response) {\r
-                               StringBuilder buffer = new StringBuilder();\r
-                               buffer.append("<style type=\"text/css\">\n");\r
-                               buffer.append(".navbar-inner {\n");\r
-                               final String headerBackground = app().settings().getString(Keys.web.headerBackgroundColor, null);\r
-                               if (!StringUtils.isEmpty(headerBackground)) {\r
-                                       buffer.append(MessageFormat.format("background-color: {0};\n", headerBackground));\r
-                               }\r
-                               final String headerBorder = app().settings().getString(Keys.web.headerBorderColor, null);\r
-                               if (!StringUtils.isEmpty(headerBorder)) {\r
-                                       buffer.append(MessageFormat.format("border-bottom: 1px solid {0} !important;\n", headerBorder));\r
-                               }\r
-                               buffer.append("}\n");\r
-                               final String headerBorderFocus = app().settings().getString(Keys.web.headerBorderFocusColor, null);\r
-                               if (!StringUtils.isEmpty(headerBorderFocus)) {\r
-                                       buffer.append(".navbar ul li:focus, .navbar .active {\n");\r
-                                       buffer.append(MessageFormat.format("border-bottom: 4px solid {0};\n", headerBorderFocus));\r
-                                       buffer.append("}\n");\r
-                               }\r
-                               final String headerForeground = app().settings().getString(Keys.web.headerForegroundColor, null);\r
-                               if (!StringUtils.isEmpty(headerForeground)) {\r
-                                       buffer.append(".navbar ul.nav li a {\n");\r
-                                       buffer.append(MessageFormat.format("color: {0};\n", headerForeground));\r
-                                       buffer.append("}\n");\r
-                                       buffer.append(".navbar ul.nav .active a {\n");\r
-                                       buffer.append(MessageFormat.format("color: {0};\n", headerForeground));\r
-                                       buffer.append("}\n");\r
-                               }\r
-                               final String headerHover = app().settings().getString(Keys.web.headerHoverColor, null);\r
-                               if (!StringUtils.isEmpty(headerHover)) {\r
-                                       buffer.append(".navbar ul.nav li a:hover {\n");\r
-                                       buffer.append(MessageFormat.format("color: {0} !important;\n", headerHover));\r
-                                       buffer.append("}\n");\r
-                               }\r
-                               buffer.append("</style>\n");\r
-                               response.renderString(buffer.toString());\r
-                               }\r
-                       }));\r
-\r
-               boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, false);\r
-               boolean authenticateAdmin = app().settings().getBoolean(Keys.web.authenticateAdminPages, true);\r
-               boolean allowAdmin = app().settings().getBoolean(Keys.web.allowAdministration, true);\r
-               boolean allowLucene = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);\r
-               boolean isLoggedIn = GitBlitWebSession.get().isLoggedIn();\r
-\r
-               if (authenticateAdmin) {\r
-                       showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();\r
-                       // authentication requires state and session\r
-                       setStatelessHint(false);\r
-               } else {\r
-                       showAdmin = allowAdmin;\r
-                       if (authenticateView) {\r
-                               // authentication requires state and session\r
-                               setStatelessHint(false);\r
-                       } else {\r
-                               // no authentication required, no state and no session required\r
-                               setStatelessHint(true);\r
-                       }\r
-               }\r
-\r
-               if (authenticateView || authenticateAdmin) {\r
-                       if (isLoggedIn) {\r
-                               UserMenu userFragment = new UserMenu("userPanel", "userMenuFragment", RootPage.this);\r
-                               add(userFragment);\r
-                       } else {\r
-                               LoginForm loginForm = new LoginForm("userPanel", "loginFormFragment", RootPage.this);\r
-                               add(loginForm);\r
-                       }\r
-               } else {\r
-                       add(new Label("userPanel").setVisible(false));\r
-               }\r
-\r
-               // navigation links\r
-               List<PageRegistration> pages = new ArrayList<PageRegistration>();\r
-               if (!authenticateView || (authenticateView && isLoggedIn)) {\r
-                       pages.add(new PageRegistration(isLoggedIn ? "gb.myDashboard" : "gb.dashboard", MyDashboardPage.class,\r
-                                       getRootPageParameters()));\r
-                       if (isLoggedIn && app().tickets().isReady()) {\r
-                               pages.add(new PageRegistration("gb.myTickets", MyTicketsPage.class));\r
-                       }\r
-                       pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class,\r
-                                       getRootPageParameters()));\r
-                       pages.add(new PageRegistration("gb.activity", ActivityPage.class, getRootPageParameters()));\r
-                       if (allowLucene) {\r
-                               pages.add(new PageRegistration("gb.search", LuceneSearchPage.class));\r
-                       }\r
-\r
-                       UserModel user = GitBlitWebSession.get().getUser();\r
-\r
-                       if (showAdmin) {\r
-                               // admin dropdown menu\r
-                               DropDownMenuRegistration adminMenu = new DropDownMenuRegistration("gb.adminMenuItem", MyDashboardPage.class);\r
-\r
-                               adminMenu.menuItems.add(new PageLinkMenuItem(getString("gb.users"), UsersPage.class));\r
-\r
-                               boolean showRegistrations = app().federation().canFederate()\r
-                                               && app().settings().getBoolean(Keys.web.showFederationRegistrations, false);\r
-                               if (showRegistrations) {\r
-                                       adminMenu.menuItems.add(new PageLinkMenuItem(getString("gb.federation"), FederationPage.class));\r
-                               }\r
-\r
-                               // allow plugins to contribute admin menu items\r
-                               List<AdminMenuExtension> extensions = app().plugins().getExtensions(AdminMenuExtension.class);\r
-                               for (AdminMenuExtension ext : extensions) {\r
-                                       adminMenu.menuItems.add(new MenuDivider());\r
-                                       adminMenu.menuItems.addAll(ext.getMenuItems(user));\r
-                               }\r
-\r
-                               pages.add(adminMenu);\r
-                       }\r
-\r
-                       if (!authenticateView || (authenticateView && isLoggedIn)) {\r
-                               addDropDownMenus(pages);\r
-                       }\r
-               }\r
-\r
-               NavigationPanel navPanel = new NavigationPanel("navPanel", getRootNavPageClass(), pages);\r
-               add(navPanel);\r
-\r
-               // display an error message cached from a redirect\r
-               String cachedMessage = GitBlitWebSession.get().clearErrorMessage();\r
-               if (!StringUtils.isEmpty(cachedMessage)) {\r
-                       error(cachedMessage);\r
-               } else if (showAdmin) {\r
-                       int pendingProposals = app().federation().getPendingFederationProposals().size();\r
-                       if (pendingProposals == 1) {\r
-                               info(getString("gb.OneProposalToReview"));\r
-                       } else if (pendingProposals > 1) {\r
-                               info(MessageFormat.format(getString("gb.nFederationProposalsToReview"),\r
-                                               pendingProposals));\r
-                       }\r
-               }\r
-\r
-               super.setupPage(repositoryName, pageName);\r
-       }\r
-\r
-       protected Class<? extends BasePage> getRootNavPageClass() {\r
-               return getClass();\r
-       }\r
-\r
-       private PageParameters getRootPageParameters() {\r
-               if (reusePageParameters()) {\r
-                       PageParameters pp = getPageParameters();\r
-                       if (pp != null) {\r
-                               PageParameters params = new PageParameters(pp);\r
-                               // remove named project parameter\r
-                               params.remove("p");\r
-\r
-                               // remove named repository parameter\r
-                               params.remove("r");\r
-\r
-                               // remove named user parameter\r
-                               params.remove("user");\r
-\r
-                               // remove days back parameter if it is the default value\r
-                               if (params.containsKey("db")\r
-                                               && params.getInt("db") == app().settings().getInteger(Keys.web.activityDuration, 7)) {\r
-                                       params.remove("db");\r
-                               }\r
-                               return params;\r
-                       }\r
-               }\r
-               return null;\r
-       }\r
-\r
-       protected boolean reusePageParameters() {\r
-               return false;\r
-       }\r
-\r
-       private void loginUser(UserModel user) {\r
-               if (user != null) {\r
-                       // Set the user into the session\r
-                       GitBlitWebSession session = GitBlitWebSession.get();\r
-                       // issue 62: fix session fixation vulnerability\r
-                       session.replaceSession();\r
-                       session.setUser(user);\r
-\r
-                       // Set Cookie\r
-                       if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) {\r
-                               WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
-                               app().authentication().setCookie(response.getHttpServletResponse(), user);\r
-                       }\r
-\r
-                       if (!session.continueRequest()) {\r
-                               PageParameters params = getPageParameters();\r
-                               if (params == null) {\r
-                                       // redirect to this page\r
-                                       setResponsePage(getClass());\r
-                               } else {\r
-                                       // Strip username and password and redirect to this page\r
-                                       params.remove("username");\r
-                                       params.remove("password");\r
-                                       setResponsePage(getClass(), params);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       protected List<RepositoryModel> getRepositoryModels() {\r
-               if (repositoryModels.isEmpty()) {\r
-                       final UserModel user = GitBlitWebSession.get().getUser();\r
-                       List<RepositoryModel> repositories = app().repositories().getRepositoryModels(user);\r
-                       repositoryModels.addAll(repositories);\r
-                       Collections.sort(repositoryModels);\r
-               }\r
-               return repositoryModels;\r
-       }\r
-\r
-       protected void addDropDownMenus(List<PageRegistration> pages) {\r
-\r
-       }\r
-\r
-       protected List<com.gitblit.models.Menu.MenuItem> getRepositoryFilterItems(PageParameters params) {\r
-               final UserModel user = GitBlitWebSession.get().getUser();\r
-               Set<MenuItem> filters = new LinkedHashSet<MenuItem>();\r
-               List<RepositoryModel> repositories = getRepositoryModels();\r
-\r
-               // accessible repositories by federation set\r
-               Map<String, AtomicInteger> setMap = new HashMap<String, AtomicInteger>();\r
-               for (RepositoryModel repository : repositories) {\r
-                       for (String set : repository.federationSets) {\r
-                               String key = set.toLowerCase();\r
-                               if (setMap.containsKey(key)) {\r
-                                       setMap.get(key).incrementAndGet();\r
-                               } else {\r
-                                       setMap.put(key, new AtomicInteger(1));\r
-                               }\r
-                       }\r
-               }\r
-               if (setMap.size() > 0) {\r
-                       List<String> sets = new ArrayList<String>(setMap.keySet());\r
-                       Collections.sort(sets);\r
-                       for (String set : sets) {\r
-                               filters.add(new ToggleMenuItem(MessageFormat.format("{0} ({1})", set,\r
-                                               setMap.get(set).get()), "set", set, params));\r
-                       }\r
-                       // divider\r
-                       filters.add(new MenuDivider());\r
-               }\r
-\r
-               // user's team memberships\r
-               if (user != null && user.teams.size() > 0) {\r
-                       List<TeamModel> teams = new ArrayList<TeamModel>(user.teams);\r
-                       Collections.sort(teams);\r
-                       for (TeamModel team : teams) {\r
-                               filters.add(new ToggleMenuItem(MessageFormat.format("{0} ({1})", team.name,\r
-                                               team.repositories.size()), "team", team.name, params));\r
-                       }\r
-                       // divider\r
-                       filters.add(new MenuDivider());\r
-               }\r
-\r
-               // custom filters\r
-               String customFilters = app().settings().getString(Keys.web.customFilters, null);\r
-               if (!StringUtils.isEmpty(customFilters)) {\r
-                       boolean addedExpression = false;\r
-                       List<String> expressions = StringUtils.getStringsFromValue(customFilters, "!!!");\r
-                       for (String expression : expressions) {\r
-                               if (!StringUtils.isEmpty(expression)) {\r
-                                       addedExpression = true;\r
-                                       filters.add(new ToggleMenuItem(null, "x", expression, params));\r
-                               }\r
-                       }\r
-                       // if we added any custom expressions, add a divider\r
-                       if (addedExpression) {\r
-                               filters.add(new MenuDivider());\r
-                       }\r
-               }\r
-               return new ArrayList<MenuItem>(filters);\r
-       }\r
-\r
-       protected List<MenuItem> getTimeFilterItems(PageParameters params) {\r
-               // days back choices - additive parameters\r
-               int daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);\r
-               int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);\r
-               if (daysBack < 1) {\r
-                       daysBack = 7;\r
-               }\r
-               if (daysBack > maxDaysBack) {\r
-                       daysBack = maxDaysBack;\r
-               }\r
-               PageParameters clonedParams;\r
-               if (params == null) {\r
-                       clonedParams = new PageParameters();\r
-               } else {\r
-                       clonedParams = new PageParameters(params);\r
-               }\r
-\r
-               if (!clonedParams.containsKey("db")) {\r
-                       clonedParams.put("db",  daysBack);\r
-               }\r
-\r
-               List<MenuItem> items = new ArrayList<MenuItem>();\r
-               Set<Integer> choicesSet = new TreeSet<Integer>(app().settings().getIntegers(Keys.web.activityDurationChoices));\r
-               if (choicesSet.isEmpty()) {\r
-                        choicesSet.addAll(Arrays.asList(1, 3, 7, 14, 21, 28));\r
-               }\r
-               List<Integer> choices = new ArrayList<Integer>(choicesSet);\r
-               Collections.sort(choices);\r
-               String lastDaysPattern = getString("gb.lastNDays");\r
-               for (Integer db : choices) {\r
-                       if (db == 1) {\r
-                               items.add(new ParameterMenuItem(getString("gb.time.today"), "db", db.toString(), clonedParams));\r
-                       } else {\r
-                               String txt = MessageFormat.format(lastDaysPattern, db);\r
-                               items.add(new ParameterMenuItem(txt, "db", db.toString(), clonedParams));\r
-                       }\r
-               }\r
-               items.add(new MenuDivider());\r
-               return items;\r
-       }\r
-\r
-       protected List<RepositoryModel> getRepositories(PageParameters params) {\r
-               if (params == null) {\r
-                       return getRepositoryModels();\r
-               }\r
-\r
-               boolean hasParameter = false;\r
-               String projectName = WicketUtils.getProjectName(params);\r
-               String userName = WicketUtils.getUsername(params);\r
-               if (StringUtils.isEmpty(projectName)) {\r
-                       if (!StringUtils.isEmpty(userName)) {\r
-                               projectName = ModelUtils.getPersonalPath(userName);\r
-                       }\r
-               }\r
-               String repositoryName = WicketUtils.getRepositoryName(params);\r
-               String set = WicketUtils.getSet(params);\r
-               String regex = WicketUtils.getRegEx(params);\r
-               String team = WicketUtils.getTeam(params);\r
-               int daysBack = params.getInt("db", 0);\r
-               int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);\r
-\r
-               List<RepositoryModel> availableModels = getRepositoryModels();\r
-               Set<RepositoryModel> models = new HashSet<RepositoryModel>();\r
-\r
-               if (!StringUtils.isEmpty(repositoryName)) {\r
-                       // try named repository\r
-                       hasParameter = true;\r
-                       for (RepositoryModel model : availableModels) {\r
-                               if (model.name.equalsIgnoreCase(repositoryName)) {\r
-                                       models.add(model);\r
-                                       break;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if (!StringUtils.isEmpty(projectName)) {\r
-                       // try named project\r
-                       hasParameter = true;\r
-                       if (projectName.equalsIgnoreCase(app().settings().getString(Keys.web.repositoryRootGroupName, "main"))) {\r
-                               // root project/group\r
-                               for (RepositoryModel model : availableModels) {\r
-                                       if (model.name.indexOf('/') == -1) {\r
-                                               models.add(model);\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               // named project/group\r
-                               String group = projectName.toLowerCase() + "/";\r
-                               for (RepositoryModel model : availableModels) {\r
-                                       if (model.name.toLowerCase().startsWith(group)) {\r
-                                               models.add(model);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if (!StringUtils.isEmpty(regex)) {\r
-                       // filter the repositories by the regex\r
-                       hasParameter = true;\r
-                       Pattern pattern = Pattern.compile(regex);\r
-                       for (RepositoryModel model : availableModels) {\r
-                               if (pattern.matcher(model.name).find()) {\r
-                                       models.add(model);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if (!StringUtils.isEmpty(set)) {\r
-                       // filter the repositories by the specified sets\r
-                       hasParameter = true;\r
-                       List<String> sets = StringUtils.getStringsFromValue(set, ",");\r
-                       for (RepositoryModel model : availableModels) {\r
-                               for (String curr : sets) {\r
-                                       if (model.federationSets.contains(curr)) {\r
-                                               models.add(model);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if (!StringUtils.isEmpty(team)) {\r
-                       // filter the repositories by the specified teams\r
-                       hasParameter = true;\r
-                       List<String> teams = StringUtils.getStringsFromValue(team, ",");\r
-\r
-                       // need TeamModels first\r
-                       List<TeamModel> teamModels = new ArrayList<TeamModel>();\r
-                       for (String name : teams) {\r
-                               TeamModel teamModel = app().users().getTeamModel(name);\r
-                               if (teamModel != null) {\r
-                                       teamModels.add(teamModel);\r
-                               }\r
-                       }\r
-\r
-                       // brute-force our way through finding the matching models\r
-                       for (RepositoryModel repositoryModel : availableModels) {\r
-                               for (TeamModel teamModel : teamModels) {\r
-                                       if (teamModel.hasRepositoryPermission(repositoryModel.name)) {\r
-                                               models.add(repositoryModel);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if (!hasParameter) {\r
-                       models.addAll(availableModels);\r
-               }\r
-\r
-               // time-filter the list\r
-               if (daysBack > 0) {\r
-                       if (maxDaysBack > 0 && daysBack > maxDaysBack) {\r
-                               daysBack = maxDaysBack;\r
-                       }\r
-                       Calendar cal = Calendar.getInstance();\r
-                       cal.set(Calendar.HOUR_OF_DAY, 0);\r
-                       cal.set(Calendar.MINUTE, 0);\r
-                       cal.set(Calendar.SECOND, 0);\r
-                       cal.set(Calendar.MILLISECOND, 0);\r
-                       cal.add(Calendar.DATE, -1 * daysBack);\r
-                       Date threshold = cal.getTime();\r
-                       Set<RepositoryModel> timeFiltered = new HashSet<RepositoryModel>();\r
-                       for (RepositoryModel model : models) {\r
-                               if (model.lastChange.after(threshold)) {\r
-                                       timeFiltered.add(model);\r
-                               }\r
-                       }\r
-                       models = timeFiltered;\r
-               }\r
-\r
-               List<RepositoryModel> list = new ArrayList<RepositoryModel>(models);\r
-               Collections.sort(list);\r
-               return list;\r
-       }\r
-\r
-       /**\r
-        * Inline login form.\r
-        */\r
-       private class LoginForm extends Fragment {\r
-               private static final long serialVersionUID = 1L;\r
-\r
-               public LoginForm(String id, String markupId, MarkupContainer markupProvider) {\r
-                       super(id, markupId, markupProvider);\r
-                       setRenderBodyOnly(true);\r
-\r
-                       SessionlessForm<Void> loginForm = new SessionlessForm<Void>("loginForm", RootPage.this.getClass(), getPageParameters()) {\r
-\r
-                               private static final long serialVersionUID = 1L;\r
-\r
-                               @Override\r
-                               public void onSubmit() {\r
-                                       String username = RootPage.this.username.getObject();\r
-                                       char[] password = RootPage.this.password.getObject().toCharArray();\r
-\r
-                                       UserModel user = app().authentication().authenticate(username, password);\r
-                                       if (user == null) {\r
-                                               error(getString("gb.invalidUsernameOrPassword"));\r
-                                       } else if (user.username.equals(Constants.FEDERATION_USER)) {\r
-                                               // disallow the federation user from logging in via the\r
-                                               // web ui\r
-                                               error(getString("gb.invalidUsernameOrPassword"));\r
-                                               user = null;\r
-                                       } else {\r
-                                               loginUser(user);\r
-                                       }\r
-                               }\r
-                       };\r
-                       TextField<String> unameField = new TextField<String>("username", username);\r
-                       WicketUtils.setInputPlaceholder(unameField, markupProvider.getString("gb.username"));\r
-                       loginForm.add(unameField);\r
-                       PasswordTextField pwField = new PasswordTextField("password", password);\r
-                       WicketUtils.setInputPlaceholder(pwField, markupProvider.getString("gb.password"));\r
-                       loginForm.add(pwField);\r
-                       add(loginForm);\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Menu for the authenticated user.\r
-        */\r
-       class UserMenu extends Fragment {\r
-\r
-               private static final long serialVersionUID = 1L;\r
-\r
-               public UserMenu(String id, String markupId, MarkupContainer markupProvider) {\r
-                       super(id, markupId, markupProvider);\r
-                       setRenderBodyOnly(true);\r
-\r
-                       GitBlitWebSession session = GitBlitWebSession.get();\r
-                       UserModel user = session.getUser();\r
-                       boolean editCredentials = app().authentication().supportsCredentialChanges(user);\r
-                       boolean standardLogin = session.authenticationType.isStandard();\r
-\r
-                       if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {\r
-                               add(new GravatarImage("username", user, "navbarGravatar", 20, false));\r
-                       } else {\r
-                               add(new Label("username", user.getDisplayName()));\r
-                       }\r
-\r
-                       add(new Label("displayName", user.getDisplayName()));\r
-\r
-                       add(new BookmarkablePageLink<Void>("newRepository",\r
-                                       EditRepositoryPage.class).setVisible(user.canAdmin() || user.canCreate()));\r
-\r
-                       add(new BookmarkablePageLink<Void>("myProfile",\r
-                                       UserPage.class, WicketUtils.newUsernameParameter(user.username)));\r
-\r
-                       add(new BookmarkablePageLink<Void>("changePassword",\r
-                                       ChangePasswordPage.class).setVisible(editCredentials));\r
-\r
-                       add(new BookmarkablePageLink<Void>("logout",\r
-                                       LogoutPage.class).setVisible(standardLogin));\r
-               }\r
-       }\r
-}\r
+/*
+ * 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.pages;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Pattern;
+
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.behavior.HeaderContributor;
+import org.apache.wicket.markup.html.IHeaderContributor;
+import org.apache.wicket.markup.html.IHeaderResponse;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.PasswordTextField;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+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.apache.wicket.protocol.http.WebResponse;
+
+import com.gitblit.Constants;
+import com.gitblit.Keys;
+import com.gitblit.extensions.UserMenuExtension;
+import com.gitblit.models.Menu.ExternalLinkMenuItem;
+import com.gitblit.models.Menu.MenuDivider;
+import com.gitblit.models.Menu.MenuItem;
+import com.gitblit.models.Menu.PageLinkMenuItem;
+import com.gitblit.models.Menu.ParameterMenuItem;
+import com.gitblit.models.Menu.ToggleMenuItem;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.TeamModel;
+import com.gitblit.models.UserModel;
+import com.gitblit.utils.ModelUtils;
+import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.GitBlitWebSession;
+import com.gitblit.wicket.PageRegistration;
+import com.gitblit.wicket.SessionlessForm;
+import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.panels.GravatarImage;
+import com.gitblit.wicket.panels.LinkPanel;
+import com.gitblit.wicket.panels.NavigationPanel;
+
+/**
+ * Root page is a topbar, navigable page like Repositories, Users, or
+ * Federation.
+ *
+ * @author James Moger
+ *
+ */
+public abstract class RootPage extends BasePage {
+
+       boolean showAdmin;
+
+       IModel<String> username = new Model<String>("");
+       IModel<String> password = new Model<String>("");
+       List<RepositoryModel> repositoryModels = new ArrayList<RepositoryModel>();
+
+       public RootPage() {
+               super();
+       }
+
+       public RootPage(PageParameters params) {
+               super(params);
+       }
+
+       @Override
+       protected void setupPage(String repositoryName, String pageName) {
+
+               // CSS header overrides
+               add(new HeaderContributor(new IHeaderContributor() {
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       public void renderHead(IHeaderResponse response) {
+                               StringBuilder buffer = new StringBuilder();
+                               buffer.append("<style type=\"text/css\">\n");
+                               buffer.append(".navbar-inner {\n");
+                               final String headerBackground = app().settings().getString(Keys.web.headerBackgroundColor, null);
+                               if (!StringUtils.isEmpty(headerBackground)) {
+                                       buffer.append(MessageFormat.format("background-color: {0};\n", headerBackground));
+                               }
+                               final String headerBorder = app().settings().getString(Keys.web.headerBorderColor, null);
+                               if (!StringUtils.isEmpty(headerBorder)) {
+                                       buffer.append(MessageFormat.format("border-bottom: 1px solid {0} !important;\n", headerBorder));
+                               }
+                               buffer.append("}\n");
+                               final String headerBorderFocus = app().settings().getString(Keys.web.headerBorderFocusColor, null);
+                               if (!StringUtils.isEmpty(headerBorderFocus)) {
+                                       buffer.append(".navbar ul li:focus, .navbar .active {\n");
+                                       buffer.append(MessageFormat.format("border-bottom: 4px solid {0};\n", headerBorderFocus));
+                                       buffer.append("}\n");
+                               }
+                               final String headerForeground = app().settings().getString(Keys.web.headerForegroundColor, null);
+                               if (!StringUtils.isEmpty(headerForeground)) {
+                                       buffer.append(".navbar ul.nav li a {\n");
+                                       buffer.append(MessageFormat.format("color: {0};\n", headerForeground));
+                                       buffer.append("}\n");
+                                       buffer.append(".navbar ul.nav .active a {\n");
+                                       buffer.append(MessageFormat.format("color: {0};\n", headerForeground));
+                                       buffer.append("}\n");
+                               }
+                               final String headerHover = app().settings().getString(Keys.web.headerHoverColor, null);
+                               if (!StringUtils.isEmpty(headerHover)) {
+                                       buffer.append(".navbar ul.nav li a:hover {\n");
+                                       buffer.append(MessageFormat.format("color: {0} !important;\n", headerHover));
+                                       buffer.append("}\n");
+                               }
+                               buffer.append("</style>\n");
+                               response.renderString(buffer.toString());
+                               }
+                       }));
+
+               boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, false);
+               boolean authenticateAdmin = app().settings().getBoolean(Keys.web.authenticateAdminPages, true);
+               boolean allowAdmin = app().settings().getBoolean(Keys.web.allowAdministration, true);
+               boolean allowLucene = app().settings().getBoolean(Keys.web.allowLuceneIndexing, true);
+               boolean isLoggedIn = GitBlitWebSession.get().isLoggedIn();
+
+               if (authenticateAdmin) {
+                       showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
+                       // authentication requires state and session
+                       setStatelessHint(false);
+               } else {
+                       showAdmin = allowAdmin;
+                       if (authenticateView) {
+                               // authentication requires state and session
+                               setStatelessHint(false);
+                       } else {
+                               // no authentication required, no state and no session required
+                               setStatelessHint(true);
+                       }
+               }
+
+               if (authenticateView || authenticateAdmin) {
+                       if (isLoggedIn) {
+                               UserMenu userFragment = new UserMenu("userPanel", "userMenuFragment", RootPage.this);
+                               add(userFragment);
+                       } else {
+                               LoginForm loginForm = new LoginForm("userPanel", "loginFormFragment", RootPage.this);
+                               add(loginForm);
+                       }
+               } else {
+                       add(new Label("userPanel").setVisible(false));
+               }
+
+               // navigation links
+               List<PageRegistration> pages = new ArrayList<PageRegistration>();
+               if (!authenticateView || (authenticateView && isLoggedIn)) {
+                       pages.add(new PageRegistration(isLoggedIn ? "gb.myDashboard" : "gb.dashboard", MyDashboardPage.class,
+                                       getRootPageParameters()));
+                       if (isLoggedIn && app().tickets().isReady()) {
+                               pages.add(new PageRegistration("gb.myTickets", MyTicketsPage.class));
+                       }
+                       pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class,
+                                       getRootPageParameters()));
+                       pages.add(new PageRegistration("gb.activity", ActivityPage.class, getRootPageParameters()));
+                       if (allowLucene) {
+                               pages.add(new PageRegistration("gb.search", LuceneSearchPage.class));
+                       }
+
+                       UserModel user = GitBlitWebSession.get().getUser();
+
+                       if (showAdmin) {
+                               // admin dropdown menu
+                               DropDownMenuRegistration adminMenu = new DropDownMenuRegistration("gb.adminMenuItem", MyDashboardPage.class);
+
+                               adminMenu.menuItems.add(new PageLinkMenuItem(getString("gb.users"), UsersPage.class));
+
+                               boolean showRegistrations = app().federation().canFederate()
+                                               && app().settings().getBoolean(Keys.web.showFederationRegistrations, false);
+                               if (showRegistrations) {
+                                       adminMenu.menuItems.add(new PageLinkMenuItem(getString("gb.federation"), FederationPage.class));
+                               }
+
+                               // allow plugins to contribute admin menu items
+                               List<AdminMenuExtension> extensions = app().plugins().getExtensions(AdminMenuExtension.class);
+                               for (AdminMenuExtension ext : extensions) {
+                                       adminMenu.menuItems.add(new MenuDivider());
+                                       adminMenu.menuItems.addAll(ext.getMenuItems(user));
+                               }
+
+                               pages.add(adminMenu);
+                       }
+
+                       if (!authenticateView || (authenticateView && isLoggedIn)) {
+                               addDropDownMenus(pages);
+                       }
+               }
+
+               NavigationPanel navPanel = new NavigationPanel("navPanel", getRootNavPageClass(), pages);
+               add(navPanel);
+
+               // display an error message cached from a redirect
+               String cachedMessage = GitBlitWebSession.get().clearErrorMessage();
+               if (!StringUtils.isEmpty(cachedMessage)) {
+                       error(cachedMessage);
+               } else if (showAdmin) {
+                       int pendingProposals = app().federation().getPendingFederationProposals().size();
+                       if (pendingProposals == 1) {
+                               info(getString("gb.OneProposalToReview"));
+                       } else if (pendingProposals > 1) {
+                               info(MessageFormat.format(getString("gb.nFederationProposalsToReview"),
+                                               pendingProposals));
+                       }
+               }
+
+               super.setupPage(repositoryName, pageName);
+       }
+
+       protected Class<? extends BasePage> getRootNavPageClass() {
+               return getClass();
+       }
+
+       private PageParameters getRootPageParameters() {
+               if (reusePageParameters()) {
+                       PageParameters pp = getPageParameters();
+                       if (pp != null) {
+                               PageParameters params = new PageParameters(pp);
+                               // remove named project parameter
+                               params.remove("p");
+
+                               // remove named repository parameter
+                               params.remove("r");
+
+                               // remove named user parameter
+                               params.remove("user");
+
+                               // remove days back parameter if it is the default value
+                               if (params.containsKey("db")
+                                               && params.getInt("db") == app().settings().getInteger(Keys.web.activityDuration, 7)) {
+                                       params.remove("db");
+                               }
+                               return params;
+                       }
+               }
+               return null;
+       }
+
+       protected boolean reusePageParameters() {
+               return false;
+       }
+
+       private void loginUser(UserModel user) {
+               if (user != null) {
+                       // Set the user into the session
+                       GitBlitWebSession session = GitBlitWebSession.get();
+                       // issue 62: fix session fixation vulnerability
+                       session.replaceSession();
+                       session.setUser(user);
+
+                       // Set Cookie
+                       if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) {
+                               WebResponse response = (WebResponse) getRequestCycle().getResponse();
+                               app().authentication().setCookie(response.getHttpServletResponse(), user);
+                       }
+
+                       if (!session.continueRequest()) {
+                               PageParameters params = getPageParameters();
+                               if (params == null) {
+                                       // redirect to this page
+                                       setResponsePage(getClass());
+                               } else {
+                                       // Strip username and password and redirect to this page
+                                       params.remove("username");
+                                       params.remove("password");
+                                       setResponsePage(getClass(), params);
+                               }
+                       }
+               }
+       }
+
+       protected List<RepositoryModel> getRepositoryModels() {
+               if (repositoryModels.isEmpty()) {
+                       final UserModel user = GitBlitWebSession.get().getUser();
+                       List<RepositoryModel> repositories = app().repositories().getRepositoryModels(user);
+                       repositoryModels.addAll(repositories);
+                       Collections.sort(repositoryModels);
+               }
+               return repositoryModels;
+       }
+
+       protected void addDropDownMenus(List<PageRegistration> pages) {
+
+       }
+
+       protected List<com.gitblit.models.Menu.MenuItem> getRepositoryFilterItems(PageParameters params) {
+               final UserModel user = GitBlitWebSession.get().getUser();
+               Set<MenuItem> filters = new LinkedHashSet<MenuItem>();
+               List<RepositoryModel> repositories = getRepositoryModels();
+
+               // accessible repositories by federation set
+               Map<String, AtomicInteger> setMap = new HashMap<String, AtomicInteger>();
+               for (RepositoryModel repository : repositories) {
+                       for (String set : repository.federationSets) {
+                               String key = set.toLowerCase();
+                               if (setMap.containsKey(key)) {
+                                       setMap.get(key).incrementAndGet();
+                               } else {
+                                       setMap.put(key, new AtomicInteger(1));
+                               }
+                       }
+               }
+               if (setMap.size() > 0) {
+                       List<String> sets = new ArrayList<String>(setMap.keySet());
+                       Collections.sort(sets);
+                       for (String set : sets) {
+                               filters.add(new ToggleMenuItem(MessageFormat.format("{0} ({1})", set,
+                                               setMap.get(set).get()), "set", set, params));
+                       }
+                       // divider
+                       filters.add(new MenuDivider());
+               }
+
+               // user's team memberships
+               if (user != null && user.teams.size() > 0) {
+                       List<TeamModel> teams = new ArrayList<TeamModel>(user.teams);
+                       Collections.sort(teams);
+                       for (TeamModel team : teams) {
+                               filters.add(new ToggleMenuItem(MessageFormat.format("{0} ({1})", team.name,
+                                               team.repositories.size()), "team", team.name, params));
+                       }
+                       // divider
+                       filters.add(new MenuDivider());
+               }
+
+               // custom filters
+               String customFilters = app().settings().getString(Keys.web.customFilters, null);
+               if (!StringUtils.isEmpty(customFilters)) {
+                       boolean addedExpression = false;
+                       List<String> expressions = StringUtils.getStringsFromValue(customFilters, "!!!");
+                       for (String expression : expressions) {
+                               if (!StringUtils.isEmpty(expression)) {
+                                       addedExpression = true;
+                                       filters.add(new ToggleMenuItem(null, "x", expression, params));
+                               }
+                       }
+                       // if we added any custom expressions, add a divider
+                       if (addedExpression) {
+                               filters.add(new MenuDivider());
+                       }
+               }
+               return new ArrayList<MenuItem>(filters);
+       }
+
+       protected List<MenuItem> getTimeFilterItems(PageParameters params) {
+               // days back choices - additive parameters
+               int daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
+               int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
+               if (daysBack < 1) {
+                       daysBack = 7;
+               }
+               if (daysBack > maxDaysBack) {
+                       daysBack = maxDaysBack;
+               }
+               PageParameters clonedParams;
+               if (params == null) {
+                       clonedParams = new PageParameters();
+               } else {
+                       clonedParams = new PageParameters(params);
+               }
+
+               if (!clonedParams.containsKey("db")) {
+                       clonedParams.put("db",  daysBack);
+               }
+
+               List<MenuItem> items = new ArrayList<MenuItem>();
+               Set<Integer> choicesSet = new TreeSet<Integer>(app().settings().getIntegers(Keys.web.activityDurationChoices));
+               if (choicesSet.isEmpty()) {
+                        choicesSet.addAll(Arrays.asList(1, 3, 7, 14, 21, 28));
+               }
+               List<Integer> choices = new ArrayList<Integer>(choicesSet);
+               Collections.sort(choices);
+               String lastDaysPattern = getString("gb.lastNDays");
+               for (Integer db : choices) {
+                       if (db == 1) {
+                               items.add(new ParameterMenuItem(getString("gb.time.today"), "db", db.toString(), clonedParams));
+                       } else {
+                               String txt = MessageFormat.format(lastDaysPattern, db);
+                               items.add(new ParameterMenuItem(txt, "db", db.toString(), clonedParams));
+                       }
+               }
+               items.add(new MenuDivider());
+               return items;
+       }
+
+       protected List<RepositoryModel> getRepositories(PageParameters params) {
+               if (params == null) {
+                       return getRepositoryModels();
+               }
+
+               boolean hasParameter = false;
+               String projectName = WicketUtils.getProjectName(params);
+               String userName = WicketUtils.getUsername(params);
+               if (StringUtils.isEmpty(projectName)) {
+                       if (!StringUtils.isEmpty(userName)) {
+                               projectName = ModelUtils.getPersonalPath(userName);
+                       }
+               }
+               String repositoryName = WicketUtils.getRepositoryName(params);
+               String set = WicketUtils.getSet(params);
+               String regex = WicketUtils.getRegEx(params);
+               String team = WicketUtils.getTeam(params);
+               int daysBack = params.getInt("db", 0);
+               int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
+
+               List<RepositoryModel> availableModels = getRepositoryModels();
+               Set<RepositoryModel> models = new HashSet<RepositoryModel>();
+
+               if (!StringUtils.isEmpty(repositoryName)) {
+                       // try named repository
+                       hasParameter = true;
+                       for (RepositoryModel model : availableModels) {
+                               if (model.name.equalsIgnoreCase(repositoryName)) {
+                                       models.add(model);
+                                       break;
+                               }
+                       }
+               }
+
+               if (!StringUtils.isEmpty(projectName)) {
+                       // try named project
+                       hasParameter = true;
+                       if (projectName.equalsIgnoreCase(app().settings().getString(Keys.web.repositoryRootGroupName, "main"))) {
+                               // root project/group
+                               for (RepositoryModel model : availableModels) {
+                                       if (model.name.indexOf('/') == -1) {
+                                               models.add(model);
+                                       }
+                               }
+                       } else {
+                               // named project/group
+                               String group = projectName.toLowerCase() + "/";
+                               for (RepositoryModel model : availableModels) {
+                                       if (model.name.toLowerCase().startsWith(group)) {
+                                               models.add(model);
+                                       }
+                               }
+                       }
+               }
+
+               if (!StringUtils.isEmpty(regex)) {
+                       // filter the repositories by the regex
+                       hasParameter = true;
+                       Pattern pattern = Pattern.compile(regex);
+                       for (RepositoryModel model : availableModels) {
+                               if (pattern.matcher(model.name).find()) {
+                                       models.add(model);
+                               }
+                       }
+               }
+
+               if (!StringUtils.isEmpty(set)) {
+                       // filter the repositories by the specified sets
+                       hasParameter = true;
+                       List<String> sets = StringUtils.getStringsFromValue(set, ",");
+                       for (RepositoryModel model : availableModels) {
+                               for (String curr : sets) {
+                                       if (model.federationSets.contains(curr)) {
+                                               models.add(model);
+                                       }
+                               }
+                       }
+               }
+
+               if (!StringUtils.isEmpty(team)) {
+                       // filter the repositories by the specified teams
+                       hasParameter = true;
+                       List<String> teams = StringUtils.getStringsFromValue(team, ",");
+
+                       // need TeamModels first
+                       List<TeamModel> teamModels = new ArrayList<TeamModel>();
+                       for (String name : teams) {
+                               TeamModel teamModel = app().users().getTeamModel(name);
+                               if (teamModel != null) {
+                                       teamModels.add(teamModel);
+                               }
+                       }
+
+                       // brute-force our way through finding the matching models
+                       for (RepositoryModel repositoryModel : availableModels) {
+                               for (TeamModel teamModel : teamModels) {
+                                       if (teamModel.hasRepositoryPermission(repositoryModel.name)) {
+                                               models.add(repositoryModel);
+                                       }
+                               }
+                       }
+               }
+
+               if (!hasParameter) {
+                       models.addAll(availableModels);
+               }
+
+               // time-filter the list
+               if (daysBack > 0) {
+                       if (maxDaysBack > 0 && daysBack > maxDaysBack) {
+                               daysBack = maxDaysBack;
+                       }
+                       Calendar cal = Calendar.getInstance();
+                       cal.set(Calendar.HOUR_OF_DAY, 0);
+                       cal.set(Calendar.MINUTE, 0);
+                       cal.set(Calendar.SECOND, 0);
+                       cal.set(Calendar.MILLISECOND, 0);
+                       cal.add(Calendar.DATE, -1 * daysBack);
+                       Date threshold = cal.getTime();
+                       Set<RepositoryModel> timeFiltered = new HashSet<RepositoryModel>();
+                       for (RepositoryModel model : models) {
+                               if (model.lastChange.after(threshold)) {
+                                       timeFiltered.add(model);
+                               }
+                       }
+                       models = timeFiltered;
+               }
+
+               List<RepositoryModel> list = new ArrayList<RepositoryModel>(models);
+               Collections.sort(list);
+               return list;
+       }
+
+       /**
+        * Inline login form.
+        */
+       private class LoginForm extends Fragment {
+               private static final long serialVersionUID = 1L;
+
+               public LoginForm(String id, String markupId, MarkupContainer markupProvider) {
+                       super(id, markupId, markupProvider);
+                       setRenderBodyOnly(true);
+
+                       SessionlessForm<Void> loginForm = new SessionlessForm<Void>("loginForm", RootPage.this.getClass(), getPageParameters()) {
+
+                               private static final long serialVersionUID = 1L;
+
+                               @Override
+                               public void onSubmit() {
+                                       String username = RootPage.this.username.getObject();
+                                       char[] password = RootPage.this.password.getObject().toCharArray();
+
+                                       UserModel user = app().authentication().authenticate(username, password);
+                                       if (user == null) {
+                                               error(getString("gb.invalidUsernameOrPassword"));
+                                       } else if (user.username.equals(Constants.FEDERATION_USER)) {
+                                               // disallow the federation user from logging in via the
+                                               // web ui
+                                               error(getString("gb.invalidUsernameOrPassword"));
+                                               user = null;
+                                       } else {
+                                               loginUser(user);
+                                       }
+                               }
+                       };
+                       TextField<String> unameField = new TextField<String>("username", username);
+                       WicketUtils.setInputPlaceholder(unameField, markupProvider.getString("gb.username"));
+                       loginForm.add(unameField);
+                       PasswordTextField pwField = new PasswordTextField("password", password);
+                       WicketUtils.setInputPlaceholder(pwField, markupProvider.getString("gb.password"));
+                       loginForm.add(pwField);
+                       add(loginForm);
+               }
+       }
+
+       /**
+        * Menu for the authenticated user.
+        */
+       class UserMenu extends Fragment {
+
+               private static final long serialVersionUID = 1L;
+
+               public UserMenu(String id, String markupId, MarkupContainer markupProvider) {
+                       super(id, markupId, markupProvider);
+                       setRenderBodyOnly(true);
+               }
+
+               @Override
+               protected void onInitialize() {
+                       super.onInitialize();
+
+                       GitBlitWebSession session = GitBlitWebSession.get();
+                       UserModel user = session.getUser();
+                       boolean editCredentials = app().authentication().supportsCredentialChanges(user);
+                       boolean standardLogin = session.authenticationType.isStandard();
+
+                       if (app().settings().getBoolean(Keys.web.allowGravatar, true)) {
+                               add(new GravatarImage("username", user, "navbarGravatar", 20, false));
+                       } else {
+                               add(new Label("username", user.getDisplayName()));
+                       }
+
+                       List<MenuItem> standardItems = new ArrayList<MenuItem>();
+                       standardItems.add(new MenuDivider());
+                       if (user.canAdmin() || user.canCreate()) {
+                               standardItems.add(new PageLinkMenuItem("gb.newRepository", EditRepositoryPage.class));
+                       }
+                       standardItems.add(new PageLinkMenuItem("gb.myProfile", UserPage.class,
+                                       WicketUtils.newUsernameParameter(user.username)));
+                       if (editCredentials) {
+                               standardItems.add(new PageLinkMenuItem("gb.changePassword", ChangePasswordPage.class));
+                       }
+                       standardItems.add(new MenuDivider());
+                       add(newSubmenu("standardMenu", user.getDisplayName(), standardItems));
+
+                       if (showAdmin) {
+                               // admin menu
+                               List<MenuItem> adminItems = new ArrayList<MenuItem>();
+                               adminItems.add(new MenuDivider());
+                               adminItems.add(new PageLinkMenuItem("gb.users", UsersPage.class));
+                               adminItems.add(new PageLinkMenuItem("gb.teams", TeamsPage.class));
+
+                               boolean showRegistrations = app().federation().canFederate()
+                                               && app().settings().getBoolean(Keys.web.showFederationRegistrations, false);
+                               if (showRegistrations) {
+                                       adminItems.add(new PageLinkMenuItem("gb.federation", FederationPage.class));
+                               }
+                               adminItems.add(new MenuDivider());
+
+                               add(newSubmenu("adminMenu", getString("gb.administration"), adminItems));
+                       } else {
+                               add(new Label("adminMenu").setVisible(false));
+                       }
+
+                       // plugin extension items
+                       List<MenuItem> extensionItems = new ArrayList<MenuItem>();
+                       List<UserMenuExtension> extensions = app().plugins().getExtensions(UserMenuExtension.class);
+                       for (UserMenuExtension ext : extensions) {
+                               List<MenuItem> items = ext.getMenuItems(user);
+                               extensionItems.addAll(items);
+                       }
+
+                       if (extensionItems.isEmpty()) {
+                               // no extension items
+                               add(new Label("extensionsMenu").setVisible(false));
+                       } else {
+                               // found extension items
+                               extensionItems.add(0, new MenuDivider());
+                               add(newSubmenu("extensionsMenu", getString("gb.extensions"), extensionItems));
+                               extensionItems.add(new MenuDivider());
+                       }
+
+                       add(new BookmarkablePageLink<Void>("logout",
+                                       LogoutPage.class).setVisible(standardLogin));
+               }
+
+               /**
+                * Creates a submenu.  This is not actually submenu because we're using
+                * an older Twitter Bootstrap which is pre-submenu.
+                *
+                * @param wicketId
+                * @param submenuTitle
+                * @param menuItems
+                * @return a submenu fragment
+                */
+               private Fragment newSubmenu(String wicketId, String submenuTitle, List<MenuItem> menuItems) {
+                       Fragment submenu = new Fragment(wicketId, "submenuFragment", this);
+                       submenu.add(new Label("submenuTitle", submenuTitle).setRenderBodyOnly(true));
+                       ListDataProvider<MenuItem> menuItemsDp = new ListDataProvider<MenuItem>(menuItems);
+                       DataView<MenuItem> submenuItems = new DataView<MenuItem>("submenuItem", menuItemsDp) {
+                               private static final long serialVersionUID = 1L;
+
+                               @Override
+                               public void populateItem(final Item<MenuItem> menuItem) {
+                                       final MenuItem item = menuItem.getModelObject();
+                                       String name = item.toString();
+                                       try {
+                                               // try to lookup translation
+                                               name = getString(name);
+                                       } catch (Exception e) {
+                                       }
+                                       if (item instanceof PageLinkMenuItem) {
+                                               // link to another Wicket page
+                                               PageLinkMenuItem pageLink = (PageLinkMenuItem) item;
+                                               menuItem.add(new LinkPanel("submenuLink", null, null, name, pageLink.getPageClass(),
+                                                               pageLink.getPageParameters(), false).setRenderBodyOnly(true));
+                                       } else if (item instanceof ExternalLinkMenuItem) {
+                                               // link to a specified href
+                                               ExternalLinkMenuItem extLink = (ExternalLinkMenuItem) item;
+                                               menuItem.add(new LinkPanel("submenuLink", null, name, extLink.getHref(),
+                                                               extLink.openInNewWindow()).setRenderBodyOnly(true));
+                                       } else if (item instanceof MenuDivider) {
+                                               // divider
+                                               menuItem.add(new Label("submenuLink").setRenderBodyOnly(true));
+                                               WicketUtils.setCssClass(menuItem, "divider");
+                                       }
+                               }
+                       };
+                       submenu.add(submenuItems);
+                       submenu.setRenderBodyOnly(true);
+                       return submenu;
+               }
+       }
+}
diff --git a/src/main/java/com/gitblit/wicket/pages/TeamsPage.html b/src/main/java/com/gitblit/wicket/pages/TeamsPage.html
new file mode 100644 (file)
index 0000000..981fe5b
--- /dev/null
@@ -0,0 +1,13 @@
+<!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
+<body>\r
+<wicket:extend>\r
+<div class="container">\r
+       <div wicket:id="teamsPanel">[teams panel]</div>\r
+</div>\r
+</wicket:extend>\r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/pages/TeamsPage.java b/src/main/java/com/gitblit/wicket/pages/TeamsPage.java
new file mode 100644 (file)
index 0000000..e0e7bf4
--- /dev/null
@@ -0,0 +1,30 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.wicket.pages;\r
+\r
+import com.gitblit.wicket.RequiresAdminRole;\r
+import com.gitblit.wicket.panels.TeamsPanel;\r
+\r
+@RequiresAdminRole\r
+public class TeamsPage extends RootPage {\r
+\r
+       public TeamsPage() {\r
+               super();\r
+               setupPage("", "");\r
+\r
+               add(new TeamsPanel("teamsPanel", showAdmin).setVisible(showAdmin));\r
+       }\r
+}\r
index 6eec358d9ee3deb027dea71714410adf052f0591..a9a3939796bb81598e44e4d4a42f5b7633946b72 100644 (file)
@@ -6,8 +6,6 @@
 <body>\r
 <wicket:extend>\r
 <div class="container">\r
-       <div wicket:id="teamsPanel">[teams panel]</div>\r
-\r
        <div wicket:id="usersPanel">[users panel]</div>\r
 </div>\r
 </wicket:extend>\r
index 652bdba68a80ff476b2d781a3daa11fd96bdf0fc..eab0b18d3cb7b65d74754f4ef182af1fc23ec12c 100644 (file)
@@ -16,7 +16,6 @@
 package com.gitblit.wicket.pages;\r
 \r
 import com.gitblit.wicket.RequiresAdminRole;\r
-import com.gitblit.wicket.panels.TeamsPanel;\r
 import com.gitblit.wicket.panels.UsersPanel;\r
 \r
 @RequiresAdminRole\r
@@ -26,8 +25,6 @@ public class UsersPage extends RootPage {
                super();\r
                setupPage("", "");\r
 \r
-               add(new TeamsPanel("teamsPanel", showAdmin).setVisible(showAdmin));\r
-\r
                add(new UsersPanel("usersPanel", showAdmin).setVisible(showAdmin));\r
        }\r
 }\r
index 393dd13962ac6d94d6fb8ea3eec9c5b1ac4376ab..7db29fa209ff069a0221f1b2d359ddc6c791c526 100644 (file)
@@ -45,25 +45,32 @@ public class NavigationPanel extends Panel {
                        @Override\r
                        public void populateItem(final Item<PageRegistration> item) {\r
                                PageRegistration entry = item.getModelObject();\r
+                               String linkText = entry.translationKey;\r
+                               try {\r
+                                       // try to lookup translation key\r
+                                       linkText = getString(entry.translationKey);\r
+                               } catch (Exception e) {\r
+                               }\r
+\r
                                if (entry.hiddenPhone) {\r
                                        WicketUtils.setCssClass(item, "hidden-phone");\r
                                }\r
                                if (entry instanceof OtherPageLink) {\r
                                        // other link\r
                                        OtherPageLink link = (OtherPageLink) entry;\r
-                                       Component c = new LinkPanel("link", null, getString(entry.translationKey), link.url);\r
+                                       Component c = new LinkPanel("link", null, linkText, link.url);\r
                                        c.setRenderBodyOnly(true);\r
                                        item.add(c);\r
                                } else if (entry instanceof DropDownMenuRegistration) {\r
                                        // drop down menu\r
                                        DropDownMenuRegistration reg = (DropDownMenuRegistration) entry;\r
-                                       Component c = new DropDownMenu("link", getString(entry.translationKey), reg);\r
+                                       Component c = new DropDownMenu("link", linkText, reg);\r
                                        c.setRenderBodyOnly(true);\r
                                        item.add(c);\r
                                        WicketUtils.setCssClass(item, "dropdown");\r
                                } else {\r
                                        // standard page link\r
-                                       Component c = new LinkPanel("link", null, getString(entry.translationKey),\r
+                                       Component c = new LinkPanel("link", null, linkText,\r
                                                        entry.pageClass, entry.params);\r
                                        c.setRenderBodyOnly(true);\r
                                        if (entry.pageClass.equals(pageClass)) {\r
index 684373e0f9b01fd7d6e7eb1d84ae933bd30bba78..18a7e325fd4bc4b593f5becfe3a0b4b9ece38a3f 100644 (file)
@@ -205,23 +205,23 @@ public class MyRequestFilter extends HttpRequestFilter {
 }
 ```
 
-### Admin Menu Items
+### User Menu Items
 
 *SINCE 1.6.0*
 
-You can provide your own admin menu items by subclassing the *AdminMenuExtension* class.
+You can provide your own user menu items by subclassing the *UserMenuExtension* class.
 
 ```java
 import java.util.Arrays;
 import java.util.List;
 import ro.fortsoft.pf4j.Extension;
-import com.gitblit.extensions.AdminMenuExtension;
+import com.gitblit.extensions.UserMenuExtension;
 import com.gitblit.models.Menu.ExternalLinkMenuItem;
 import com.gitblit.models.Menu.MenuItem;
 import com.gitblit.models.UserModel;
 
 @Extension
-public class MyAdminMenuContributor extends AdminMenuExtension {
+public class MyUserMenuContributor extends UserMenuExtension {
 
     @Override
     public List<MenuItem> getMenuItems(UserModel user) {
@@ -229,5 +229,3 @@ public class MyAdminMenuContributor extends AdminMenuExtension {
     }
 }
 ```
-
-