Exemple #1
0
 private void loadEdit(
     HttpServletRequest request,
     ModelAndView next,
     WikiPageInfo pageInfo,
     String contents,
     String virtualWiki,
     String topicName,
     boolean useSection)
     throws Exception {
   pageInfo.setPageTitle(new WikiMessage("edit.title", topicName));
   pageInfo.setTopicName(topicName);
   WikiLink wikiLink = LinkUtil.parseWikiLink(virtualWiki, topicName);
   if (wikiLink.getNamespace().getId().equals(Namespace.CATEGORY_ID)) {
     ServletUtil.loadCategoryContent(next, virtualWiki, topicName);
   }
   if (request.getParameter("editComment") != null) {
     next.addObject("editComment", request.getParameter("editComment"));
   }
   if (useSection && request.getParameter("section") != null) {
     next.addObject("section", request.getParameter("section"));
   }
   next.addObject("minorEdit", (request.getParameter("minorEdit") != null));
   Watchlist watchlist = ServletUtil.currentWatchlist(request, virtualWiki);
   if (request.getParameter("watchTopic") != null
       || (watchlist.containsTopic(topicName) && !isPreview(request))) {
     next.addObject("watchTopic", true);
   }
   pageInfo.setContentJsp(JSP_EDIT);
   WikiUser user = ServletUtil.currentWikiUser();
   String editor = user.getEditor();
   next.addObject("editor", editor);
   next.addObject("contents", contents);
 }
Exemple #2
0
 private WikiUser setAdminUser(HttpServletRequest request) throws Exception {
   String username = request.getParameter("username");
   WikiUser user = new WikiUser(username);
   user.setCreateIpAddress(ServletUtil.getIpAddress(request));
   user.setLastLoginIpAddress(ServletUtil.getIpAddress(request));
   return user;
 }
Exemple #3
0
 private void view(
     HttpServletRequest request,
     HttpServletResponse response,
     ModelAndView next,
     WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromURI(request);
   if (StringUtils.isBlank(topicName)) {
     String virtualWikiName = pageInfo.getVirtualWikiName();
     VirtualWiki virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName);
     topicName = virtualWiki.getRootTopicName();
   }
   String virtualWiki = pageInfo.getVirtualWikiName();
   if (StringUtils.isBlank(virtualWiki)) {
     virtualWiki = VirtualWiki.defaultVirtualWiki().getName();
   }
   Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName);
   if (topic.getTopicId() <= 0) {
     // topic does not exist, return 404 and display empty page
     response.setStatus(HttpServletResponse.SC_NOT_FOUND);
     WikiMessage wikiMessage = new WikiMessage("topic.notcreated");
     // topic name is escaped from WikiUtil.getTopicFromURI, so do not double-escape
     wikiMessage.setParamsWithoutEscaping(new String[] {topicName});
     next.addObject("notopic", wikiMessage);
   }
   WikiMessage pageTitle = new WikiMessage("topic.title", topicName);
   ServletUtil.viewTopic(request, next, pageInfo, pageTitle, topic, true, true);
 }
Exemple #4
0
 /**
  * This method handles the request after its parent class receives control.
  *
  * @param request - Standard HttpServletRequest object.
  * @param response - Standard HttpServletResponse object.
  * @return A <code>ModelAndView</code> object to be handled by the rest of the Spring framework.
  */
 protected ModelAndView handleJAMWikiRequest(
     HttpServletRequest request,
     HttpServletResponse response,
     ModelAndView next,
     WikiPageInfo pageInfo)
     throws Exception {
   if (!Utilities.isAdmin(request)) {
     WikiMessage errorMessage = new WikiMessage("admin.message.loginrequired");
     return ServletUtil.viewLogin(request, pageInfo, "Special:Admin", errorMessage);
   }
   String function = request.getParameter("function");
   if (!StringUtils.hasText(function)) {
     view(request, next, pageInfo, null);
   } else if (function.equals("refreshIndex")) {
     refreshIndex(request, next, pageInfo);
   } else if (function.equals("properties")) {
     properties(request, next, pageInfo);
   } else if (function.equals("addVirtualWiki")) {
     addVirtualWiki(request, next, pageInfo);
   } else if (function.equals("recentChanges")) {
     recentChanges(request, next, pageInfo);
   } else if (function.equals("spamFilter")) {
     spamFilter(request, next, pageInfo);
   }
   return next;
 }
Exemple #5
0
 private String processAuthenticationRequiredException(HttpServletRequest request)
     throws JspException {
   String key =
       (String)
           request
               .getSession()
               .getAttribute(JAMWikiAuthenticationConstants.JAMWIKI_AUTHENTICATION_REQUIRED_KEY);
   String uri =
       (String)
           request
               .getSession()
               .getAttribute(
                   JAMWikiAuthenticationConstants.JAMWIKI_AUTHENTICATION_REQUIRED_URI_KEY);
   if (key == null) {
     return null;
   }
   Object[] params = {uri};
   String message = Utilities.formatMessage(key, ServletUtil.retrieveUserLocale(request), params);
   request
       .getSession()
       .removeAttribute(JAMWikiAuthenticationConstants.JAMWIKI_AUTHENTICATION_REQUIRED_KEY);
   request
       .getSession()
       .removeAttribute(JAMWikiAuthenticationConstants.JAMWIKI_AUTHENTICATION_REQUIRED_URI_KEY);
   return formatMessage(message);
 }
Exemple #6
0
 /**
  * This method ensures that values required for rendering a JSP page have been loaded into the
  * ModelAndView object. Examples of values that may be handled by this method include topic name,
  * username, etc.
  *
  * @param request The current servlet request object.
  * @param next The current ModelAndView object.
  * @param pageInfo The current WikiPageInfo object, containing basic page rendering information.
  */
 protected static void loadDefaults(
     HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception {
   if (next.getViewName() != null
       && next.getViewName().startsWith(ServletUtil.SPRING_REDIRECT_PREFIX)) {
     // if this is a redirect, no need to load anything
     return;
   }
   // load cached top area, nav bar, etc.
   ServletUtil.buildLayout(request, next);
   if (!StringUtils.hasText(pageInfo.getTopicName())) {
     pageInfo.setTopicName(WikiUtil.getTopicFromURI(request));
   }
   pageInfo.setUserMenu(ServletUtil.buildUserMenu());
   pageInfo.setTabMenu(ServletUtil.buildTabMenu(request, pageInfo));
   next.addObject(ServletUtil.PARAMETER_PAGE_INFO, pageInfo);
 }
Exemple #7
0
 /**
  * Initialize topic values for the topic being edited. If a topic with the specified name already
  * exists then it will be initialized, otherwise a new topic is created.
  */
 private Topic loadTopic(String virtualWiki, String topicName) throws Exception {
   Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName);
   if (topic.getReadOnly()) {
     throw new WikiException(new WikiMessage("error.readonly"));
   }
   return topic;
 }
Exemple #8
0
 private String processAuthorizationException(HttpServletRequest request) throws JspException {
   String key = (String) request.getParameter("message");
   if (key == null) {
     return null;
   }
   String message = Utilities.formatMessage(key, ServletUtil.retrieveUserLocale(request));
   return formatMessage(message);
 }
Exemple #9
0
 /** Functionality to handle the "Preview" button being clicked. */
 private void preview(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromRequest(request);
   String virtualWiki = pageInfo.getVirtualWikiName();
   String contents = (String) request.getParameter("contents");
   Topic previewTopic = new Topic(virtualWiki, topicName);
   previewTopic.setTopicContent(contents);
   next.addObject("editPreview", "true");
   ServletUtil.viewTopic(request, next, pageInfo, null, previewTopic, false, false);
 }
Exemple #10
0
 private void jumpTo(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
   String topic = request.getParameter("text");
   if (WikiBase.exists(virtualWiki, topic)) {
     ServletUtil.redirect(next, virtualWiki, topic);
   } else {
     next.addObject("notopic", new WikiMessage("topic.notcreated", topic));
     this.search(request, next, pageInfo);
   }
 }
Exemple #11
0
 private String processLegacyLogin(HttpServletRequest request) throws JspException {
   WikiMessage messageObject = (WikiMessage) request.getAttribute("messageObject");
   if (messageObject == null) {
     return null;
   }
   String message =
       Utilities.formatMessage(
           messageObject.getKey(),
           ServletUtil.retrieveUserLocale(request),
           messageObject.getParams());
   return formatMessage(message);
 }
Exemple #12
0
 /**
  * This method ensures that the left menu, logo, and other required values have been loaded into
  * the session object.
  *
  * @param request The servlet request object.
  * @param next A ModelAndView object corresponding to the page being constructed.
  */
 private static void buildLayout(HttpServletRequest request, ModelAndView next) {
   String virtualWikiName = WikiUtil.getVirtualWikiFromURI(request);
   if (virtualWikiName == null) {
     logger.severe("No virtual wiki available for page request " + request.getRequestURI());
     virtualWikiName = WikiBase.DEFAULT_VWIKI;
   }
   VirtualWiki virtualWiki = retrieveVirtualWiki(virtualWikiName);
   // build the layout contents
   String leftMenu =
       ServletUtil.cachedContent(
           request.getContextPath(),
           request.getLocale(),
           virtualWikiName,
           WikiBase.SPECIAL_PAGE_LEFT_MENU,
           true);
   next.addObject("leftMenu", leftMenu);
   next.addObject("defaultTopic", virtualWiki.getDefaultTopicName());
   next.addObject("virtualWiki", virtualWiki.getName());
   next.addObject("logo", Environment.getValue(Environment.PROP_BASE_LOGO_IMAGE));
   String bottomArea =
       ServletUtil.cachedContent(
           request.getContextPath(),
           request.getLocale(),
           virtualWiki.getName(),
           WikiBase.SPECIAL_PAGE_BOTTOM_AREA,
           true);
   next.addObject("bottomArea", bottomArea);
   next.addObject(ServletUtil.PARAMETER_VIRTUAL_WIKI, virtualWiki.getName());
   Integer cssRevision = new Integer(0);
   try {
     cssRevision =
         WikiBase.getDataHandler()
             .lookupTopic(virtualWiki.getName(), WikiBase.SPECIAL_PAGE_STYLESHEET, false, null)
             .getCurrentVersionId();
   } catch (Exception e) {
   }
   next.addObject("cssRevision", cssRevision);
 }
Exemple #13
0
 /**
  * Utility method used when viewing a topic.
  *
  * @param request The current servlet request object.
  * @param next The current Spring ModelAndView object.
  * @param pageInfo The current WikiPageInfo object, which contains information needed for
  *     rendering the final JSP page.
  * @param topicName The topic being viewed. This value must be a valid topic that can be loaded as
  *     a org.jamwiki.model.Topic object.
  * @throws Exception Thrown if any error occurs during processing.
  */
 protected static void viewTopic(
     HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, String topicName)
     throws Exception {
   String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
   if (!StringUtils.hasText(virtualWiki)) {
     virtualWiki = WikiBase.DEFAULT_VWIKI;
   }
   Topic topic = ServletUtil.initializeTopic(virtualWiki, topicName);
   if (topic.getTopicId() <= 0) {
     // topic does not exist, display empty page
     next.addObject("notopic", new WikiMessage("topic.notcreated", topicName));
   }
   WikiMessage pageTitle = new WikiMessage("topic.title", topicName);
   viewTopic(request, next, pageInfo, pageTitle, topic, true);
 }
Exemple #14
0
 private ModelAndView loginRequired(HttpServletRequest request, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromRequest(request);
   String virtualWiki = pageInfo.getVirtualWikiName();
   WikiUserDetailsImpl user = ServletUtil.currentUserDetails();
   if (ServletUtil.isEditable(virtualWiki, topicName, user)) {
     return null;
   }
   if (!user.hasRole(Role.ROLE_EDIT_EXISTING)) {
     WikiMessage messageObject = new WikiMessage("login.message.edit");
     return ServletUtil.viewLogin(
         request, pageInfo, WikiUtil.getTopicFromURI(request), messageObject);
   }
   if (!user.hasRole(Role.ROLE_EDIT_NEW)
       && WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null) == null) {
     WikiMessage messageObject = new WikiMessage("login.message.editnew");
     return ServletUtil.viewLogin(
         request, pageInfo, WikiUtil.getTopicFromURI(request), messageObject);
   }
   Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (topic == null) {
     // this should never trigger, but better safe than sorry...
     return null;
   }
   if (topic.getAdminOnly()) {
     WikiMessage messageObject = new WikiMessage("login.message.editadmin", topicName);
     return ServletUtil.viewLogin(
         request, pageInfo, WikiUtil.getTopicFromURI(request), messageObject);
   }
   if (topic.getReadOnly()) {
     throw new WikiException(new WikiMessage("error.readonly"));
   }
   // it should be impossible to get here...
   throw new WikiException(
       new WikiMessage("error.unknown", "Unable to determine topic editing permissions"));
 }
Exemple #15
0
 private List<WikiMessage> validate(HttpServletRequest request, WikiUser user) throws Exception {
   List<WikiMessage> errors = ServletUtil.validateSystemSettings(Environment.getInstance());
   if (StringUtils.isBlank(user.getUsername())) {
     errors.add(new WikiMessage("error.loginempty"));
   }
   String newPassword = request.getParameter("newPassword");
   String confirmPassword = request.getParameter("confirmPassword");
   if (newPassword != null || confirmPassword != null) {
     if (newPassword == null) {
       errors.add(new WikiMessage("error.newpasswordempty"));
     } else if (confirmPassword == null) {
       errors.add(new WikiMessage("error.passwordconfirm"));
     } else if (!newPassword.equals(confirmPassword)) {
       errors.add(new WikiMessage("admin.message.passwordsnomatch"));
     }
   }
   return errors;
 }
Exemple #16
0
 /**
  * Utility method used when redirecting to an error page.
  *
  * @param request The servlet request object.
  * @param t The exception that is the source of the error.
  * @return Returns a ModelAndView object corresponding to the error page display.
  */
 protected static ModelAndView viewError(HttpServletRequest request, Throwable t) {
   if (!(t instanceof WikiException)) {
     logger.severe("Servlet error", t);
   }
   ModelAndView next = new ModelAndView("wiki");
   WikiPageInfo pageInfo = new WikiPageInfo();
   pageInfo.setPageTitle(new WikiMessage("error.title"));
   pageInfo.setContentJsp(JSP_ERROR);
   pageInfo.setSpecial(true);
   if (t instanceof WikiException) {
     WikiException we = (WikiException) t;
     next.addObject("messageObject", we.getWikiMessage());
   } else {
     next.addObject("messageObject", new WikiMessage("error.unknown", t.toString()));
   }
   try {
     ServletUtil.loadDefaults(request, next, pageInfo);
   } catch (Exception err) {
     logger.severe("Unable to load default layout", err);
   }
   return next;
 }
Exemple #17
0
 /**
  * This method handles the request after its parent class receives control.
  *
  * @param request - Standard HttpServletRequest object.
  * @param response - Standard HttpServletResponse object.
  * @return A <code>ModelAndView</code> object to be handled by the rest of the Spring framework.
  */
 protected ModelAndView handleJAMWikiRequest(
     HttpServletRequest request,
     HttpServletResponse response,
     ModelAndView next,
     WikiPageInfo pageInfo)
     throws Exception {
   if (!WikiUtil.isFirstUse()) {
     throw new WikiException(new WikiMessage("setup.error.notrequired"));
   }
   String function =
       (request.getParameter("function") == null)
           ? request.getParameter("override")
           : request.getParameter("function");
   if (function == null) {
     function = "";
   }
   try {
     if (!SystemUtils.isJavaVersionAtLeast(MINIMUM_JDK_VERSION)) {
       throw new WikiException(
           new WikiMessage(
               "setup.error.jdk",
               Integer.valueOf(MINIMUM_JDK_VERSION).toString(),
               System.getProperty("java.version")));
     }
     if (!StringUtils.isBlank(function) && initialize(request, next, pageInfo)) {
       ServletUtil.redirect(
           next,
           WikiBase.DEFAULT_VWIKI,
           Environment.getValue(Environment.PROP_BASE_DEFAULT_TOPIC));
     } else {
       view(request, next, pageInfo);
     }
   } catch (Exception e) {
     handleSetupError(request, next, pageInfo, e);
   }
   return next;
 }
Exemple #18
0
 /**
  * Utility method used when viewing a topic.
  *
  * @param request The current servlet request object.
  * @param next The current Spring ModelAndView object.
  * @param pageInfo The current WikiPageInfo object, which contains information needed for
  *     rendering the final JSP page.
  * @param pageTitle The title of the page being rendered.
  * @param topic The Topic object for the topic being displayed.
  * @param sectionEdit Set to <code>true</code> if edit links should be displayed for each section
  *     of the topic.
  * @throws Exception Thrown if any error occurs during processing.
  */
 protected static void viewTopic(
     HttpServletRequest request,
     ModelAndView next,
     WikiPageInfo pageInfo,
     WikiMessage pageTitle,
     Topic topic,
     boolean sectionEdit)
     throws Exception {
   // FIXME - what should the default be for topics that don't exist?
   if (topic == null) {
     throw new WikiException(new WikiMessage("common.exception.notopic"));
   }
   WikiUtil.validateTopicName(topic.getName());
   if (topic.getTopicType() == Topic.TYPE_REDIRECT
       && (request.getParameter("redirect") == null
           || !request.getParameter("redirect").equalsIgnoreCase("no"))) {
     Topic child = Utilities.findRedirectedTopic(topic, 0);
     if (!child.getName().equals(topic.getName())) {
       pageInfo.setRedirectName(topic.getName());
       pageTitle = new WikiMessage("topic.title", child.getName());
       topic = child;
     }
   }
   String virtualWiki = topic.getVirtualWiki();
   String topicName = topic.getName();
   WikiUser user = Utilities.currentUser();
   if (sectionEdit && !ServletUtil.isEditable(virtualWiki, topicName, user)) {
     sectionEdit = false;
   }
   ParserInput parserInput = new ParserInput();
   parserInput.setContext(request.getContextPath());
   parserInput.setLocale(request.getLocale());
   parserInput.setWikiUser(user);
   parserInput.setTopicName(topicName);
   parserInput.setUserIpAddress(request.getRemoteAddr());
   parserInput.setVirtualWiki(virtualWiki);
   parserInput.setAllowSectionEdit(sectionEdit);
   ParserDocument parserDocument = new ParserDocument();
   String content = Utilities.parse(parserInput, parserDocument, topic.getTopicContent());
   // FIXME - the null check should be unnecessary
   if (parserDocument != null && parserDocument.getCategories().size() > 0) {
     LinkedHashMap categories = new LinkedHashMap();
     for (Iterator iterator = parserDocument.getCategories().keySet().iterator();
         iterator.hasNext(); ) {
       String key = (String) iterator.next();
       String value =
           key.substring(
               NamespaceHandler.NAMESPACE_CATEGORY.length()
                   + NamespaceHandler.NAMESPACE_SEPARATOR.length());
       categories.put(key, value);
     }
     next.addObject("categories", categories);
   }
   topic.setTopicContent(content);
   if (topic.getTopicType() == Topic.TYPE_CATEGORY) {
     loadCategoryContent(next, virtualWiki, topic.getName());
   }
   if (topic.getTopicType() == Topic.TYPE_IMAGE || topic.getTopicType() == Topic.TYPE_FILE) {
     Collection fileVersions =
         WikiBase.getDataHandler().getAllWikiFileVersions(virtualWiki, topicName, true);
     for (Iterator iterator = fileVersions.iterator(); iterator.hasNext(); ) {
       // update version urls to include web root path
       WikiFileVersion fileVersion = (WikiFileVersion) iterator.next();
       String url =
           FilenameUtils.normalize(
               Environment.getValue(Environment.PROP_FILE_DIR_RELATIVE_PATH)
                   + "/"
                   + fileVersion.getUrl());
       url = FilenameUtils.separatorsToUnix(url);
       fileVersion.setUrl(url);
     }
     next.addObject("fileVersions", fileVersions);
     if (topic.getTopicType() == Topic.TYPE_IMAGE) {
       next.addObject("topicImage", new Boolean(true));
     } else {
       next.addObject("topicFile", new Boolean(true));
     }
   }
   pageInfo.setSpecial(false);
   pageInfo.setTopicName(topicName);
   next.addObject(ServletUtil.PARAMETER_TOPIC_OBJECT, topic);
   if (pageTitle != null) {
     pageInfo.setPageTitle(pageTitle);
   }
 }
Exemple #19
0
 /** Functionality to handle the "Save" button being clicked. */
 private void save(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = WikiUtil.getTopicFromRequest(request);
   String virtualWiki = pageInfo.getVirtualWikiName();
   Topic topic = loadTopic(virtualWiki, topicName);
   Topic lastTopic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (lastTopic != null
       && !lastTopic.getCurrentVersionId().equals(retrieveLastTopicVersionId(request, topic))) {
     // someone else has edited the topic more recently
     resolve(request, next, pageInfo);
     return;
   }
   String contents = request.getParameter("contents");
   String sectionName = "";
   if (!StringUtils.isBlank(request.getParameter("section"))) {
     // load section of topic
     int section = Integer.valueOf(request.getParameter("section"));
     ParserOutput parserOutput = new ParserOutput();
     String[] spliceResult =
         ParserUtil.parseSplice(
             parserOutput,
             request.getContextPath(),
             request.getLocale(),
             virtualWiki,
             topicName,
             section,
             contents);
     contents = spliceResult[1];
     sectionName = parserOutput.getSectionName();
   }
   if (contents == null) {
     logger.warning("The topic " + topicName + " has no content");
     throw new WikiException(new WikiMessage("edit.exception.nocontent", topicName));
   }
   // strip line feeds
   contents = StringUtils.remove(contents, '\r');
   String lastTopicContent =
       (lastTopic != null) ? StringUtils.remove(lastTopic.getTopicContent(), '\r') : "";
   if (lastTopic != null && StringUtils.equals(lastTopicContent, contents)) {
     // topic hasn't changed. redirect to prevent user from refreshing and re-submitting
     ServletUtil.redirect(next, virtualWiki, topic.getName());
     return;
   }
   String editComment = request.getParameter("editComment");
   if (handleSpam(request, next, topicName, contents, editComment)) {
     this.loadEdit(request, next, pageInfo, contents, virtualWiki, topicName, false);
     return;
   }
   // parse for signatures and other syntax that should not be saved in raw form
   WikiUser user = ServletUtil.currentWikiUser();
   ParserInput parserInput = new ParserInput();
   parserInput.setContext(request.getContextPath());
   parserInput.setLocale(request.getLocale());
   parserInput.setWikiUser(user);
   parserInput.setTopicName(topicName);
   parserInput.setUserDisplay(ServletUtil.getIpAddress(request));
   parserInput.setVirtualWiki(virtualWiki);
   ParserOutput parserOutput = ParserUtil.parseMetadata(parserInput, contents);
   // parse signatures and other values that need to be updated prior to saving
   contents = ParserUtil.parseMinimal(parserInput, contents);
   topic.setTopicContent(contents);
   if (!StringUtils.isBlank(parserOutput.getRedirect())) {
     // set up a redirect
     topic.setRedirectTo(parserOutput.getRedirect());
     topic.setTopicType(TopicType.REDIRECT);
   } else if (topic.getTopicType() == TopicType.REDIRECT) {
     // no longer a redirect
     topic.setRedirectTo(null);
     topic.setTopicType(TopicType.ARTICLE);
   }
   int charactersChanged = StringUtils.length(contents) - StringUtils.length(lastTopicContent);
   TopicVersion topicVersion =
       new TopicVersion(
           user, ServletUtil.getIpAddress(request), editComment, contents, charactersChanged);
   if (request.getParameter("minorEdit") != null) {
     topicVersion.setEditType(TopicVersion.EDIT_MINOR);
   }
   WikiBase.getDataHandler()
       .writeTopic(topic, topicVersion, parserOutput.getCategories(), parserOutput.getLinks());
   // update watchlist
   WikiUserDetailsImpl userDetails = ServletUtil.currentUserDetails();
   if (!userDetails.hasRole(Role.ROLE_ANONYMOUS)) {
     Watchlist watchlist = ServletUtil.currentWatchlist(request, virtualWiki);
     boolean watchTopic = (request.getParameter("watchTopic") != null);
     if (watchlist.containsTopic(topicName) != watchTopic) {
       WikiBase.getDataHandler()
           .writeWatchlistEntry(watchlist, virtualWiki, topicName, user.getUserId());
     }
   }
   // redirect to prevent user from refreshing and re-submitting
   String target = topic.getName();
   if (!StringUtils.isBlank(sectionName)) {
     target += "#" + sectionName;
   }
   ServletUtil.redirect(next, virtualWiki, target);
 }
Exemple #20
0
 /**
  * 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;
 }