Exemplo n.º 1
0
 private void view(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   if (Utilities.currentUser(request) != null) {
     next.addObject("newuser", Utilities.currentUser(request));
   }
   pageInfo.setSpecial(true);
   pageInfo.setAction(WikiPageInfo.ACTION_REGISTER);
   pageInfo.setPageTitle(new WikiMessage("register.title"));
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 private ModelAndView loginRequired(HttpServletRequest request) throws Exception {
   String topicName = JAMWikiServlet.getTopicFromRequest(request);
   String virtualWiki = JAMWikiServlet.getVirtualWikiFromURI(request);
   if (!StringUtils.hasText(topicName) || !StringUtils.hasText(virtualWiki)) {
     return null;
   }
   if (Environment.getBooleanValue(Environment.PROP_TOPIC_FORCE_USERNAME)
       && Utilities.currentUser(request) == null) {
     WikiMessage errorMessage = new WikiMessage("edit.exception.login");
     return viewLogin(request, JAMWikiServlet.getTopicFromURI(request), errorMessage);
   }
   Topic topic = WikiBase.getHandler().lookupTopic(virtualWiki, topicName);
   if (topic != null && topic.getAdminOnly() && !Utilities.isAdmin(request)) {
     WikiMessage errorMessage = new WikiMessage("edit.exception.loginadmin", topicName);
     return viewLogin(request, JAMWikiServlet.getTopicFromURI(request), errorMessage);
   }
   return null;
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 protected void writeTopic(HttpServletRequest request, String editComment) throws Exception {
   String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
   String topicName =
       NamespaceHandler.NAMESPACE_JAMWIKI
           + NamespaceHandler.NAMESPACE_SEPARATOR
           + Utilities.decodeFromRequest(filename(request));
   String contents =
       "<pre><nowiki>\n" + Utilities.readFile(filename(request)) + "\n</nowiki></pre>";
   Topic topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false, null);
   if (topic == null) {
     topic = new Topic();
     topic.setVirtualWiki(virtualWiki);
     topic.setName(topicName);
   }
   topic.setTopicContent(contents);
   topic.setReadOnly(true);
   topic.setTopicType(Topic.TYPE_SYSTEM_FILE);
   WikiUser user = Utilities.currentUser();
   TopicVersion topicVersion =
       new TopicVersion(user, request.getRemoteAddr(), editComment, contents);
   WikiBase.getDataHandler().writeTopic(topic, topicVersion, null, true, null);
 }
Exemplo n.º 6
0
 private void addVirtualWiki(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   WikiUser user = Utilities.currentUser(request);
   try {
     VirtualWiki virtualWiki = new VirtualWiki();
     if (StringUtils.hasText(request.getParameter("virtualWikiId"))) {
       virtualWiki.setVirtualWikiId(new Integer(request.getParameter("virtualWikiId")).intValue());
     }
     virtualWiki.setName(request.getParameter("name"));
     virtualWiki.setDefaultTopicName(
         Utilities.encodeForURL(request.getParameter("defaultTopicName")));
     WikiBase.getDataHandler().writeVirtualWiki(virtualWiki, null);
     if (!StringUtils.hasText(request.getParameter("virtualWikiId"))) {
       WikiBase.getDataHandler().setupSpecialPages(request.getLocale(), user, virtualWiki, null);
     }
     next.addObject("message", new WikiMessage("admin.message.virtualwikiadded"));
   } catch (Exception e) {
     logger.severe("Failure while adding virtual wiki", e);
     next.addObject("message", new WikiMessage("admin.message.virtualwikifail", e.getMessage()));
   }
   view(request, next, pageInfo, null);
 }
Exemplo n.º 7
0
 /**
  * Action used when viewing a topic.
  *
  * @param request The servlet request object.
  * @param next The Spring ModelAndView object.
  * @param topicName The topic being viewed. This value must be a valid topic that can be loaded as
  *     a org.jamwiki.model.Topic object.
  */
 protected void viewTopic(
     HttpServletRequest request,
     ModelAndView next,
     WikiMessage pageTitle,
     Topic topic,
     boolean sectionEdit)
     throws Exception {
   // FIXME - what should the default be for topics that don't exist?
   String contents = "";
   if (topic == null) {
     throw new WikiException(new WikiMessage("common.exception.notopic"));
   }
   String virtualWiki = topic.getVirtualWiki();
   String topicName = topic.getName();
   String displayName = request.getRemoteAddr();
   WikiUser user = Utilities.currentUser(request);
   ParserInfo parserInfo = new ParserInfo(request.getContextPath(), request.getLocale());
   parserInfo.setWikiUser(user);
   parserInfo.setTopicName(topicName);
   parserInfo.setUserIpAddress(request.getRemoteAddr());
   parserInfo.setVirtualWiki(virtualWiki);
   parserInfo.setAllowSectionEdit(sectionEdit);
   contents = Utilities.parse(parserInfo, topic.getTopicContent(), topicName);
   if (StringUtils.hasText(request.getParameter("highlight"))) {
     // search servlet highlights search terms, so add that here
     contents = AbstractSearchEngine.highlightHTML(contents, request.getParameter("highlight"));
   }
   topic.setTopicContent(contents);
   if (topic.getTopicType() == Topic.TYPE_IMAGE) {
     List fileVersions =
         WikiBase.getHandler().getAllWikiFileVersions(virtualWiki, topicName, true);
     next.addObject("fileVersions", fileVersions);
   }
   this.pageInfo.setSpecial(false);
   this.pageInfo.setTopicName(topicName);
   next.addObject(JAMWikiServlet.PARAMETER_TOPIC_OBJECT, topic);
   this.pageInfo.setPageTitle(pageTitle);
 }
Exemplo n.º 8
0
 /**
  * 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;
 }
Exemplo n.º 9
0
 protected void loadDefaults(
     HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) {
   // load cached top area, nav bar, etc.
   try {
     this.buildLayout(request, next);
   } catch (Exception e) {
     logger.error("Unable to build default page layout", e);
   }
   // add link to user page and comments page
   WikiUser user = Utilities.currentUser(request);
   if (user != null) {
     next.addObject("userpage", WikiBase.NAMESPACE_USER + user.getLogin());
     next.addObject("usercomments", WikiBase.NAMESPACE_USER_COMMENTS + user.getLogin());
     next.addObject("adminUser", new Boolean(user.getAdmin()));
   }
   if (!this.pageInfo.getSpecial()) {
     // FIXME - this is really ugly
     String article = this.pageInfo.getTopicName();
     String comments = WikiBase.NAMESPACE_COMMENTS + article;
     if (article != null && article.startsWith(WikiBase.NAMESPACE_COMMENTS)) {
       int pos = WikiBase.NAMESPACE_COMMENTS.length();
       article = article.substring(pos);
       comments = WikiBase.NAMESPACE_COMMENTS + article;
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_SPECIAL)) {
       int pos = WikiBase.NAMESPACE_SPECIAL.length();
       article = article.substring(pos);
       comments = WikiBase.NAMESPACE_COMMENTS + article;
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_USER_COMMENTS)) {
       int pos = WikiBase.NAMESPACE_USER_COMMENTS.length();
       comments = article;
       article = WikiBase.NAMESPACE_USER + article.substring(pos);
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_USER)) {
       int pos = WikiBase.NAMESPACE_USER.length();
       comments = WikiBase.NAMESPACE_USER_COMMENTS + article.substring(pos);
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_IMAGE_COMMENTS)) {
       int pos = WikiBase.NAMESPACE_IMAGE_COMMENTS.length();
       comments = article;
       article = WikiBase.NAMESPACE_IMAGE + article.substring(pos);
     } else if (article != null && article.startsWith(WikiBase.NAMESPACE_IMAGE)) {
       int pos = WikiBase.NAMESPACE_IMAGE.length();
       comments = WikiBase.NAMESPACE_IMAGE_COMMENTS + article.substring(pos);
     }
     next.addObject("article", article);
     next.addObject("comments", comments);
     String editLink = "Special:Edit?topic=" + Utilities.encodeURL(this.pageInfo.getTopicName());
     if (StringUtils.hasText(request.getParameter("topicVersionId"))) {
       editLink += "&topicVersionId=" + request.getParameter("topicVersionId");
     }
     next.addObject("edit", editLink);
   }
   next.addObject(JAMWikiServlet.PARAMETER_TOPIC, this.pageInfo.getTopicName());
   if (!StringUtils.hasText(this.pageInfo.getTopicName())) {
     try {
       next.addObject(JAMWikiServlet.PARAMETER_TOPIC, JAMWikiServlet.getTopicFromURI(request));
     } catch (Exception e) {
       logger.error("Unable to load topic value in JAMWikiServlet", e);
     }
   }
   next.addObject(JAMWikiServlet.PARAMETER_ADMIN, new Boolean(this.pageInfo.getAdmin()));
   next.addObject(JAMWikiServlet.PARAMETER_SPECIAL, new Boolean(this.pageInfo.getSpecial()));
   next.addObject(JAMWikiServlet.PARAMETER_TITLE, this.pageInfo.getPageTitle());
   next.addObject(JAMWikiServlet.PARAMETER_ACTION, this.pageInfo.getPageAction());
   // reset pageInfo object - seems not to reset with each servlet call
   this.pageInfo = new WikiPageInfo();
 }
Exemplo n.º 10
0
 private void properties(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   Properties props = new Properties();
   try {
     setProperty(props, request, Environment.PROP_BASE_DEFAULT_TOPIC);
     setProperty(props, request, Environment.PROP_BASE_LOGO_IMAGE);
     setProperty(props, request, Environment.PROP_BASE_META_DESCRIPTION);
     setBooleanProperty(props, request, Environment.PROP_TOPIC_NON_ADMIN_TOPIC_MOVE);
     setBooleanProperty(props, request, Environment.PROP_TOPIC_FORCE_USERNAME);
     setBooleanProperty(props, request, Environment.PROP_TOPIC_WYSIWYG);
     setProperty(props, request, Environment.PROP_IMAGE_RESIZE_INCREMENT);
     setProperty(props, request, Environment.PROP_RECENT_CHANGES_NUM);
     setBooleanProperty(props, request, Environment.PROP_TOPIC_SPAM_FILTER);
     setBooleanProperty(props, request, Environment.PROP_TOPIC_USE_PREVIEW);
     setBooleanProperty(props, request, Environment.PROP_PRINT_NEW_WINDOW);
     setProperty(props, request, Environment.PROP_PARSER_CLASS);
     setBooleanProperty(props, request, Environment.PROP_PARSER_TOC);
     setProperty(props, request, Environment.PROP_PARSER_TOC_DEPTH);
     setBooleanProperty(props, request, Environment.PROP_PARSER_ALLOW_HTML);
     setBooleanProperty(props, request, Environment.PROP_PARSER_ALLOW_JAVASCRIPT);
     setBooleanProperty(props, request, Environment.PROP_PARSER_ALLOW_TEMPLATES);
     setProperty(props, request, Environment.PROP_PARSER_SIGNATURE_USER_PATTERN);
     setProperty(props, request, Environment.PROP_PARSER_SIGNATURE_DATE_PATTERN);
     setProperty(props, request, Environment.PROP_BASE_FILE_DIR);
     setProperty(props, request, Environment.PROP_BASE_PERSISTENCE_TYPE);
     if (props
         .getProperty(Environment.PROP_BASE_PERSISTENCE_TYPE)
         .equals(WikiBase.PERSISTENCE_EXTERNAL)) {
       setProperty(props, request, Environment.PROP_DB_DRIVER);
       setProperty(props, request, Environment.PROP_DB_TYPE);
       setProperty(props, request, Environment.PROP_DB_URL);
       setProperty(props, request, Environment.PROP_DB_USERNAME);
       setPassword(props, request, next, Environment.PROP_DB_PASSWORD, "dbPassword");
     } else {
       WikiDatabase.setupDefaultDatabase(props);
     }
     setProperty(props, request, Environment.PROP_DBCP_MAX_ACTIVE);
     setProperty(props, request, Environment.PROP_DBCP_MAX_IDLE);
     setBooleanProperty(props, request, Environment.PROP_DBCP_TEST_ON_BORROW);
     setBooleanProperty(props, request, Environment.PROP_DBCP_TEST_ON_RETURN);
     setBooleanProperty(props, request, Environment.PROP_DBCP_TEST_WHILE_IDLE);
     setProperty(props, request, Environment.PROP_DBCP_MIN_EVICTABLE_IDLE_TIME);
     setProperty(props, request, Environment.PROP_DBCP_TIME_BETWEEN_EVICTION_RUNS);
     setProperty(props, request, Environment.PROP_DBCP_NUM_TESTS_PER_EVICTION_RUN);
     setProperty(props, request, Environment.PROP_DBCP_WHEN_EXHAUSTED_ACTION);
     setBooleanProperty(props, request, Environment.PROP_DBCP_REMOVE_ABANDONED);
     setProperty(props, request, Environment.PROP_DBCP_REMOVE_ABANDONED_TIMEOUT);
     int maxFileSizeInKB =
         Integer.parseInt(request.getParameter(Environment.PROP_FILE_MAX_FILE_SIZE));
     props.setProperty(
         Environment.PROP_FILE_MAX_FILE_SIZE, Integer.toString(maxFileSizeInKB * 1000));
     setProperty(props, request, Environment.PROP_FILE_DIR_FULL_PATH);
     setProperty(props, request, Environment.PROP_FILE_DIR_RELATIVE_PATH);
     /*
     setProperty(props, request, Environment.PROP_EMAIL_SMTP_HOST);
     setProperty(props, request, Environment.PROP_EMAIL_SMTP_USERNAME);
     setPassword(props, request, next, Environment.PROP_EMAIL_SMTP_PASSWORD, "smtpPassword");
     setProperty(props, request, Environment.PROP_EMAIL_REPLY_ADDRESS);
     */
     setProperty(props, request, Environment.PROP_LDAP_CONTEXT);
     setProperty(props, request, Environment.PROP_LDAP_FACTORY_CLASS);
     setProperty(props, request, Environment.PROP_LDAP_FIELD_EMAIL);
     setProperty(props, request, Environment.PROP_LDAP_FIELD_FIRST_NAME);
     setProperty(props, request, Environment.PROP_LDAP_FIELD_LAST_NAME);
     setProperty(props, request, Environment.PROP_LDAP_FIELD_USERID);
     setProperty(props, request, Environment.PROP_BASE_USER_HANDLER);
     setProperty(props, request, Environment.PROP_LDAP_LOGIN);
     setPassword(props, request, next, Environment.PROP_LDAP_PASSWORD, "ldapPassword");
     setProperty(props, request, Environment.PROP_LDAP_SECURITY_AUTHENTICATION);
     setProperty(props, request, Environment.PROP_LDAP_URL);
     setProperty(props, request, Environment.PROP_CACHE_INDIVIDUAL_SIZE);
     setProperty(props, request, Environment.PROP_CACHE_MAX_AGE);
     setProperty(props, request, Environment.PROP_CACHE_MAX_IDLE_AGE);
     setProperty(props, request, Environment.PROP_CACHE_TOTAL_SIZE);
     setBooleanProperty(props, request, Environment.PROP_RSS_ALLOWED);
     setProperty(props, request, Environment.PROP_RSS_TITLE);
     Vector errors = Utilities.validateSystemSettings(props);
     if (errors.size() > 0) {
       next.addObject("errors", errors);
       next.addObject("message", new WikiMessage("admin.message.changesnotsaved"));
     } else {
       // all is well, save the properties
       Iterator iterator = props.keySet().iterator();
       while (iterator.hasNext()) {
         String key = (String) iterator.next();
         String value = props.getProperty(key);
         Environment.setValue(key, value);
       }
       Environment.saveProperties();
       // re-initialize to reset database settings (if needed)
       WikiBase.reset(request.getLocale(), Utilities.currentUser(request));
       next.addObject("message", new WikiMessage("admin.message.changessaved"));
     }
   } catch (Exception e) {
     logger.severe("Failure while processing property values", e);
     next.addObject("message", new WikiMessage("admin.message.propertyfailure", e.getMessage()));
   }
   view(request, next, pageInfo, props);
 }
Exemplo n.º 11
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);
   }
 }
Exemplo n.º 12
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;
 }
Exemplo n.º 13
0
 private void save(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo)
     throws Exception {
   String topicName = JAMWikiServlet.getTopicFromRequest(request);
   String virtualWiki = JAMWikiServlet.getVirtualWikiFromURI(request);
   Topic topic = loadTopic(virtualWiki, topicName);
   TopicVersion lastTopicVersion =
       WikiBase.getHandler().lookupLastTopicVersion(virtualWiki, topicName);
   if (lastTopicVersion != null
       && lastTopicVersion.getTopicVersionId()
           != retrieveLastTopicVersionId(request, virtualWiki, topicName)) {
     // someone else has edited the topic more recently
     resolve(request, next, pageInfo);
     return;
   }
   String contents = request.getParameter("contents");
   if (StringUtils.hasText(request.getParameter("section"))) {
     // load section of topic
     int section = (new Integer(request.getParameter("section"))).intValue();
     ParserDocument parserDocument =
         Utilities.parseSplice(request, virtualWiki, topicName, section, contents);
     contents = parserDocument.getContent();
   }
   if (contents == null) {
     logger.warning("The topic " + topicName + " has no content");
     throw new WikiException(new WikiMessage("edit.exception.nocontent", topicName));
   }
   if (lastTopicVersion != null && lastTopicVersion.getVersionContent().equals(contents)) {
     viewTopic(request, next, pageInfo, topicName);
     return;
   }
   // parse for signatures and other syntax that should not be saved in raw form
   WikiUser user = Utilities.currentUser(request);
   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);
   ParserDocument parserDocument = Utilities.parseSave(parserInput, contents);
   contents = parserDocument.getContent();
   topic.setTopicContent(contents);
   if (StringUtils.hasText(parserDocument.getRedirect())) {
     // set up a redirect
     topic.setRedirectTo(parserDocument.getRedirect());
     topic.setTopicType(Topic.TYPE_REDIRECT);
   } else if (topic.getTopicType() == Topic.TYPE_REDIRECT) {
     // no longer a redirect
     topic.setRedirectTo(null);
     topic.setTopicType(Topic.TYPE_ARTICLE);
   }
   TopicVersion topicVersion =
       new TopicVersion(
           user, request.getRemoteAddr(), request.getParameter("editComment"), contents);
   if (request.getParameter("minorEdit") != null) {
     topicVersion.setEditType(TopicVersion.EDIT_MINOR);
   }
   WikiBase.getHandler().writeTopic(topic, topicVersion, parserDocument);
   // a save request has been made
   JAMWikiServlet.removeCachedContents();
   viewTopic(request, next, pageInfo, topicName);
 }