コード例 #1
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * Determine if a user has permission to move a topic.
  *
  * @param virtualWiki The virtual wiki name for the topic in question.
  * @param topicName The name of the topic in question.
  * @param user The current Wiki user, or <code>null</code> if there is no current user.
  * @return <code>true</code> if the user is allowed to move the topic, <code>false</code>
  *     otherwise.
  */
 protected static boolean isMoveable(String virtualWiki, String topicName, WikiUser user)
     throws Exception {
   if (user == null || !user.hasRole(Role.ROLE_MOVE)) {
     // no permission granted to move pages
     return false;
   }
   Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (topic == null) {
     // cannot move a topic that doesn't exist
     return false;
   }
   if (topic.getReadOnly()) {
     return false;
   }
   if (topic.getAdminOnly() && (user == null || !user.hasRole(Role.ROLE_ADMIN))) {
     return false;
   }
   return true;
 }
コード例 #2
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * Determine if a user has permission to edit a topic.
  *
  * @param virtualWiki The virtual wiki name for the topic in question.
  * @param topicName The name of the topic in question.
  * @param user The current Wiki user, or <code>null</code> if there is no current user.
  * @return <code>true</code> if the user is allowed to edit the topic, <code>false</code>
  *     otherwise.
  */
 protected static boolean isEditable(String virtualWiki, String topicName, WikiUser user)
     throws Exception {
   if (user == null || !user.hasRole(Role.ROLE_EDIT_EXISTING)) {
     // user does not have appropriate permissions
     return false;
   }
   if (!user.hasRole(Role.ROLE_EDIT_NEW)
       && WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null) == null) {
     // user does not have appropriate permissions
     return false;
   }
   Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (topic == null) {
     // new topic, edit away...
     return true;
   }
   if (topic.getAdminOnly() && (user == null || !user.hasRole(Role.ROLE_ADMIN))) {
     return false;
   }
   if (topic.getReadOnly()) {
     return false;
   }
   return true;
 }
コード例 #3
0
ファイル: WatchlistServlet.java プロジェクト: Eljah/jamwiki
 private void view(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String virtualWiki = Utilities.getVirtualWikiFromURI(request);
   Pagination pagination = Utilities.buildPagination(request, next);
   WikiUser user = Utilities.currentUser();
   if (!user.hasRole(Role.ROLE_USER)) {
     throw new WikiException(new WikiMessage("watchlist.error.loginrequired"));
   }
   Collection changes =
       WikiBase.getDataHandler().getWatchlist(virtualWiki, user.getUserId(), pagination);
   next.addObject("numChanges", new Integer(changes.size()));
   next.addObject("changes", changes);
   pageInfo.setPageTitle(new WikiMessage("watchlist.title"));
   pageInfo.setContentJsp(JSP_WATCHLIST);
   pageInfo.setSpecial(true);
 }
コード例 #4
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * Build a map of links and the corresponding link text to be used as the user menu links for the
  * WikiPageInfo object.
  */
 private static LinkedHashMap buildUserMenu() {
   LinkedHashMap links = new LinkedHashMap();
   WikiUser user = Utilities.currentUser();
   if (user.hasRole(Role.ROLE_ANONYMOUS) && !user.hasRole(Role.ROLE_EMBEDDED)) {
     links.put("Special:Login", new WikiMessage("common.login"));
     links.put("Special:Account", new WikiMessage("usermenu.register"));
   }
   if (user.hasRole(Role.ROLE_USER)) {
     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.hasText(user.getDisplayName())) {
       username = user.getDisplayName();
     }
     links.put(userPage, new WikiMessage("usermenu.user", username));
     links.put(userCommentsPage, new WikiMessage("usermenu.usercomments"));
     links.put("Special:Watchlist", new WikiMessage("usermenu.watchlist"));
   }
   if (user.hasRole(Role.ROLE_USER) && !user.hasRole(Role.ROLE_NO_ACCOUNT)) {
     links.put("Special:Account", new WikiMessage("usermenu.account"));
   }
   if (user.hasRole(Role.ROLE_USER) && !user.hasRole(Role.ROLE_EMBEDDED)) {
     links.put("Special:Logout", new WikiMessage("common.logout"));
   }
   if (user.hasRole(Role.ROLE_SYSADMIN)) {
     links.put("Special:Admin", new WikiMessage("usermenu.admin"));
   } else if (user.hasRole(Role.ROLE_TRANSLATE)) {
     links.put("Special:Translation", new WikiMessage("tab.admin.translations"));
   }
   return links;
 }
コード例 #5
0
ファイル: WatchlistServlet.java プロジェクト: Eljah/jamwiki
 private void update(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   WikiUser user = Utilities.currentUser();
   if (!user.hasRole(Role.ROLE_USER)) {
     throw new WikiException(new WikiMessage("watchlist.error.loginrequired"));
   }
   String topicName = Utilities.getTopicFromRequest(request);
   String virtualWiki = Utilities.getVirtualWikiFromURI(request);
   Watchlist watchlist = Utilities.currentWatchlist(request, virtualWiki);
   WikiBase.getDataHandler()
       .writeWatchlistEntry(watchlist, virtualWiki, topicName, user.getUserId(), null);
   String article = Utilities.extractTopicLink(topicName);
   if (watchlist.containsTopic(topicName)) {
     // added to watchlist
     next.addObject("message", new WikiMessage("watchlist.caption.added", article));
   } else {
     // removed from watchlist
     next.addObject("message", new WikiMessage("watchlist.caption.removed", article));
   }
   this.view(request, next, pageInfo);
 }
コード例 #6
0
ファイル: ServletUtil.java プロジェクト: Eljah/jamwiki
 /**
  * Build a map of links and the corresponding link text to be used as the tab menu links for the
  * WikiPageInfo object.
  */
 private static LinkedHashMap buildTabMenu(HttpServletRequest request, WikiPageInfo pageInfo) {
   LinkedHashMap links = new LinkedHashMap();
   WikiUser user = Utilities.currentUser();
   String pageName = pageInfo.getTopicName();
   String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
   try {
     if (pageInfo.getAdmin()) {
       if (user.hasRole(Role.ROLE_SYSADMIN)) {
         links.put("Special:Admin", new WikiMessage("tab.admin.configuration"));
         links.put("Special:Maintenance", new WikiMessage("tab.admin.maintenance"));
         links.put("Special:Roles", new WikiMessage("tab.admin.roles"));
       }
       if (user.hasRole(Role.ROLE_TRANSLATE)) {
         links.put("Special:Translation", new WikiMessage("tab.admin.translations"));
       }
     } else if (pageInfo.getSpecial()) {
       links.put(pageName, new WikiMessage("tab.common.special"));
     } else {
       String article = Utilities.extractTopicLink(pageName);
       String comments = Utilities.extractCommentsLink(pageName);
       links.put(article, new WikiMessage("tab.common.article"));
       links.put(comments, new WikiMessage("tab.common.comments"));
       if (ServletUtil.isEditable(virtualWiki, pageName, user)) {
         String editLink = "Special:Edit?topic=" + Utilities.encodeForURL(pageName);
         if (StringUtils.hasText(request.getParameter("topicVersionId"))) {
           editLink += "&topicVersionId=" + request.getParameter("topicVersionId");
         }
         links.put(editLink, new WikiMessage("tab.common.edit"));
       }
       String historyLink = "Special:History?topic=" + Utilities.encodeForURL(pageName);
       links.put(historyLink, new WikiMessage("tab.common.history"));
       if (ServletUtil.isMoveable(virtualWiki, pageName, user)) {
         String moveLink = "Special:Move?topic=" + Utilities.encodeForURL(pageName);
         links.put(moveLink, new WikiMessage("tab.common.move"));
       }
       if (user.hasRole(Role.ROLE_USER)) {
         Watchlist watchlist = WikiUtil.currentWatchlist(request, virtualWiki);
         boolean watched = (watchlist.containsTopic(pageName));
         String watchlistLabel = (watched) ? "tab.common.unwatch" : "tab.common.watch";
         String watchlistLink = "Special:Watchlist?topic=" + Utilities.encodeForURL(pageName);
         links.put(watchlistLink, new WikiMessage(watchlistLabel));
       }
       if (pageInfo.isUserPage()) {
         WikiLink wikiLink = LinkUtil.parseWikiLink(pageName);
         String contributionsLink =
             "Special:Contributions?contributor=" + Utilities.encodeForURL(wikiLink.getArticle());
         links.put(contributionsLink, new WikiMessage("tab.common.contributions"));
       }
       String linkToLink = "Special:LinkTo?topic=" + Utilities.encodeForURL(pageName);
       links.put(linkToLink, new WikiMessage("tab.common.links"));
       if (user.hasRole(Role.ROLE_ADMIN)) {
         String manageLink = "Special:Manage?topic=" + Utilities.encodeForURL(pageName);
         links.put(manageLink, new WikiMessage("tab.common.manage"));
       }
       String printLink = "Special:Print?topic=" + Utilities.encodeForURL(pageName);
       links.put(printLink, new WikiMessage("tab.common.print"));
     }
   } catch (Exception e) {
     logger.severe("Unable to build tabbed menu links", e);
   }
   return links;
 }