* Build a map of links and the corresponding link text to be used as the user
* menu links for the WikiPageInfo object.
*/
private LinkedHashMap buildUserMenu(WikiPageInfo pageInfo) {
LinkedHashMap<String, WikiMessage> links = new LinkedHashMap<String, WikiMessage>();
WikiUserDetails userDetails = ServletUtil.currentUserDetails();
if (userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS)
&& !userDetails.hasRole(RoleImpl.ROLE_EMBEDDED)) {
// include the current page in the login link
String loginLink = "Special:Login";
if (!StringUtils.startsWith(pageInfo.getTopicName(), "Special:Login")) {
loginLink += LinkUtil.appendQueryParam("", PARAM_LOGIN_SUCCESS_TARGET,
pageInfo.getTopicName());
}
links.put(loginLink, new WikiMessage("common.login"));
links.put("Special:Account", new WikiMessage("usermenu.register"));
}
if (!userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS)) {
WikiUser user = ServletUtil.currentWikiUser();
String userPage = NamespaceHandler.NAMESPACE_USER
+ NamespaceHandler.NAMESPACE_SEPARATOR + user.getUsername();
String userCommentsPage = NamespaceHandler.NAMESPACE_USER_COMMENTS
+ NamespaceHandler.NAMESPACE_SEPARATOR + user.getUsername();
String username = user.getUsername();
if (!StringUtils.isBlank(user.getDisplayName())) {
username = user.getDisplayName();
}
// user name will be escaped by the jamwiki:link tag
WikiMessage userMenuMessage = new WikiMessage("usermenu.user");
userMenuMessage.setParamsWithoutEscaping(new String[] { username });
links.put(userPage, userMenuMessage);
links.put(userCommentsPage, new WikiMessage("usermenu.usercomments"));
links.put("Special:Watchlist", new WikiMessage("usermenu.watchlist"));
}
if (!userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS)
&& !userDetails.hasRole(RoleImpl.ROLE_NO_ACCOUNT)) {
links.put("Special:Account", new WikiMessage("usermenu.account"));
}
if (!userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS)
&& !userDetails.hasRole(RoleImpl.ROLE_EMBEDDED)) {
links.put("Special:Logout", new WikiMessage("common.logout"));
}
if (userDetails.hasRole(RoleImpl.ROLE_SYSADMIN)) {
links.put("Special:Admin", new WikiMessage("usermenu.admin"));
} else if (userDetails.hasRole(RoleImpl.ROLE_TRANSLATE)) {
links.put("Special:Translation",
new WikiMessage("tab.admin.translations"));
}
return links;
}