@Override
  public String getRestoreLink(PortletRequest portletRequest, long classPK)
      throws PortalException, SystemException {

    String portletId = PortletKeys.WIKI;

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    long plid = PortalUtil.getPlidFromPortletId(page.getGroupId(), PortletKeys.WIKI);

    if (plid == LayoutConstants.DEFAULT_PLID) {
      plid = PortalUtil.getControlPanelPlid(portletRequest);

      portletId = PortletKeys.WIKI_ADMIN;
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);

    WikiNode node = page.getNode();

    portletURL.setParameter("struts_action", "/wiki/view");
    portletURL.setParameter("nodeName", node.getName());
    portletURL.setParameter("title", HtmlUtil.unescape(page.getTitle()));

    return portletURL.toString();
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect) {

    try {
      ThemeDisplay themeDisplay =
          (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      User user = themeDisplay.getUser();

      long portletPlid =
          PortalUtil.getPlidFromPortletId(user.getGroupId(), true, PortletKeys.TASKS);

      PortletURL portletURL =
          PortletURLFactoryUtil.create(
              liferayPortletRequest, PortletKeys.TASKS, portletPlid, PortletRequest.RENDER_PHASE);

      portletURL.setParameter("mvcPath", "/tasks/view.jsp");

      return portletURL.toString();
    } catch (Exception e) {
    }

    return null;
  }
  protected PortletURL getRestoreURL(
      PortletRequest portletRequest, long classPK, boolean isContainerModel)
      throws PortalException, SystemException {

    String portletId = PortletKeys.MESSAGE_BOARDS;

    MBThread thread = MBThreadLocalServiceUtil.getThread(classPK);

    long plid = PortalUtil.getPlidFromPortletId(thread.getGroupId(), PortletKeys.MESSAGE_BOARDS);

    if (plid == LayoutConstants.DEFAULT_PLID) {
      portletId = PortletKeys.MESSAGE_BOARDS_ADMIN;

      plid = PortalUtil.getControlPanelPlid(portletRequest);
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);

    if (isContainerModel) {
      if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
        portletURL.setParameter("struts_action", "/message_boards/view");
      } else {
        portletURL.setParameter("struts_action", "/message_boards_admin/view");
      }
    } else {
      if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
        portletURL.setParameter("struts_action", "/message_boards/view_message");
      } else {
        portletURL.setParameter("struts_action", "/message_boards_admin/view_message");
      }
    }

    return portletURL;
  }
  protected String getLoginURL(String key, ThemeDisplay themeDisplay) throws Exception {

    Group group = groupLocalService.getGroup(themeDisplay.getCompanyId(), GroupConstants.GUEST);

    long plid = PortalUtil.getPlidFromPortletId(group.getGroupId(), PortletKeys.LOGIN);

    Layout layout = layoutLocalService.getLayout(plid);

    return PortalUtil.getLayoutFullURL(layout, themeDisplay, false) + "?key=" + key;
  }
  protected String getPortletId(long plid) throws Exception {
    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    long selPlid =
        PortalUtil.getPlidFromPortletId(layout.getGroupId(), PortletKeys.KNOWLEDGE_BASE_DISPLAY);

    if (selPlid != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
      return PortletKeys.KNOWLEDGE_BASE_DISPLAY;
    }

    return PortletKeys.KNOWLEDGE_BASE_ARTICLE_DEFAULT_INSTANCE;
  }
  protected String getThreadURL(User user, long threadId, ThemeDisplay themeDisplay)
      throws Exception {

    Group group = user.getGroup();

    long plid =
        PortalUtil.getPlidFromPortletId(group.getGroupId(), true, PortletKeys.PRIVATE_MESSAGING);

    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    String privateMessageURL = PortalUtil.getLayoutFullURL(layout, themeDisplay, false);

    return privateMessageURL + "/-/private_messaging/thread/" + threadId;
  }
  public static String getAssetURLViewInContext(
      ThemeDisplay themeDisplay, String className, long classPK)
      throws PortalException, SystemException {

    if (className.equals(BlogsEntry.class.getName())) {
      return PortalUtil.getLayoutFullURL(classPK, PortletKeys.BLOGS);
    }

    if (className.equals(Layout.class.getName())) {
      return PortalUtil.getLayoutFullURL(LayoutLocalServiceUtil.getLayout(classPK), themeDisplay);
    }

    if (className.equals(MBCategory.class.getName())) {
      return PortalUtil.getLayoutFullURL(classPK, PortletKeys.MESSAGE_BOARDS);
    }

    if (className.equals(WikiNode.class.getName())) {
      long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), PortletKeys.WIKI);

      if (plid == 0) {
        return null;
      }

      StringBundler sb = new StringBundler(5);

      Layout layout = LayoutLocalServiceUtil.getLayout(plid);

      String layoutFullURL = PortalUtil.getLayoutFullURL(layout, themeDisplay);

      sb.append(layoutFullURL);

      sb.append(Portal.FRIENDLY_URL_SEPARATOR);
      sb.append("wiki/");
      sb.append(classPK);
      sb.append("/all_pages");

      return sb.toString();
    }

    return null;
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect) {

    try {
      ThemeDisplay themeDisplay =
          (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      User user = themeDisplay.getUser();

      long portletPlid =
          PortalUtil.getPlidFromPortletId(user.getGroupId(), true, "1_WAR_microblogsportlet");

      PortletURL portletURL =
          PortletURLFactoryUtil.create(
              liferayPortletRequest,
              "1_WAR_microblogsportlet",
              portletPlid,
              PortletRequest.RENDER_PHASE);

      portletURL.setParameter("mvcPath", "/microblogs/view.jsp");

      long microblogsEntryId = _entry.getMicroblogsEntryId();

      if (_entry.getReceiverMicroblogsEntryId() > 0) {
        microblogsEntryId = _entry.getReceiverMicroblogsEntryId();
      }

      portletURL.setParameter("receiverMicroblogsEntryId", String.valueOf(microblogsEntryId));

      return portletURL.toString();
    } catch (Exception e) {
    }

    return null;
  }
  @Override
  public String getRestoreLink(PortletRequest portletRequest, long classPK)
      throws PortalException, SystemException {

    String portletId = PortletKeys.MESSAGE_BOARDS;

    MBThread thread = MBThreadLocalServiceUtil.getThread(classPK);

    long plid = PortalUtil.getPlidFromPortletId(thread.getGroupId(), PortletKeys.MESSAGE_BOARDS);

    if (plid == LayoutConstants.DEFAULT_PLID) {
      portletId = PortletKeys.MESSAGE_BOARDS_ADMIN;

      plid = PortalUtil.getControlPanelPlid(portletRequest);
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);

    portletURL.setParameter("struts_action", "/message_boards_admin/view");
    portletURL.setParameter("mbCategoryId", String.valueOf(thread.getCategoryId()));

    return portletURL.toString();
  }
  public void markNotSpamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "notSpamWikiPageIds");

    List<String> wikiPageLinks = new ArrayList<>();

    for (long wikiPageId : wikiPageIds) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId);

      WikiPage latestVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), false);

      String latestContent = null;

      if (latestVersionWikiPage != null) {
        latestContent = latestVersionWikiPage.getContent();
      }

      WikiPage previousVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), true);

      String previousContent = null;

      if (previousVersionWikiPage != null) {
        previousContent = previousVersionWikiPage.getContent();
      }

      // Selected version

      wikiPage.setStatus(WorkflowConstants.STATUS_APPROVED);
      wikiPage.setSummary(StringPool.BLANK);

      wikiPage = WikiPageLocalServiceUtil.updateWikiPage(wikiPage);

      // Latest version

      if ((latestContent != null)
          && ((previousContent == null) || latestContent.equals(previousContent))) {

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        WikiPageLocalServiceUtil.revertPage(
            themeDisplay.getUserId(),
            wikiPage.getNodeId(),
            wikiPage.getTitle(),
            wikiPage.getVersion(),
            serviceContext);
      } else {
        StringBundler sb = new StringBundler(5);

        sb.append("<a href=\"");

        long plid = PortalUtil.getPlidFromPortletId(wikiPage.getGroupId(), WikiPortletKeys.WIKI);

        LiferayPortletURL liferayPortletURL =
            PortletURLFactoryUtil.create(
                actionRequest, WikiPortletKeys.WIKI, plid, PortletRequest.RENDER_PHASE);

        WikiNode wikiNode = wikiPage.getNode();

        liferayPortletURL.setParameter("struts_action", "/wiki/view");
        liferayPortletURL.setParameter("nodeName", wikiNode.getName());
        liferayPortletURL.setParameter("title", wikiPage.getTitle());
        liferayPortletURL.setParameter("version", String.valueOf(wikiPage.getVersion()));

        sb.append(liferayPortletURL.toString());
        sb.append("\" target=\"_blank\">");
        sb.append(HtmlUtil.escape(wikiPage.getTitle()));
        sb.append("</a>");

        wikiPageLinks.add(sb.toString());
      }

      // Akismet

      if (AkismetUtil.isWikiEnabled(wikiPage.getCompanyId())) {
        AkismetUtil.submitHam(wikiPage);
      }
    }

    if (!wikiPageLinks.isEmpty()) {
      SessionMessages.add(
          actionRequest,
          "anotherUserHasMadeChangesToThesePages",
          StringUtil.merge(wikiPageLinks, "<br />"));

      addSuccessMessage(actionRequest, actionResponse);

      super.sendRedirect(actionRequest, actionResponse);
    }
  }