@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 ContainerModel getParentContainerModel(long classPK)
      throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    return page.getNode();
  }
  public static boolean contains(
      PermissionChecker permissionChecker, WikiPage page, String actionId) {

    Boolean hasPermission =
        StagingPermissionUtil.hasPermission(
            permissionChecker,
            page.getGroupId(),
            WikiPage.class.getName(),
            page.getPageId(),
            PortletKeys.WIKI,
            actionId);

    if (hasPermission != null) {
      return hasPermission.booleanValue();
    }

    if (page.isDraft()) {
      if (actionId.equals(ActionKeys.VIEW)
          && !contains(permissionChecker, page, ActionKeys.UPDATE)) {

        return false;
      }

      if (actionId.equals(ActionKeys.DELETE)
          && (page.getStatusByUserId() == permissionChecker.getUserId())) {

        return true;
      }
    } else if (page.isPending()) {
      hasPermission =
          WorkflowPermissionUtil.hasPermission(
              permissionChecker,
              page.getGroupId(),
              WikiPage.class.getName(),
              page.getResourcePrimKey(),
              actionId);

      if ((hasPermission != null) && hasPermission.booleanValue()) {
        return true;
      }
    } else if (page.isScheduled()) {
      if (actionId.equals(ActionKeys.VIEW)
          && !contains(permissionChecker, page, ActionKeys.UPDATE)) {

        return false;
      }
    }

    if (actionId.equals(ActionKeys.VIEW)) {
      WikiPage redirectPage = page.fetchRedirectPage();

      if (redirectPage != null) {
        page = redirectPage;
      }

      if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
        WikiNode node = page.getNode();

        if (!WikiNodePermission.contains(permissionChecker, node, actionId)) {

          return false;
        }

        while (page != null) {
          if (!_hasPermission(permissionChecker, page, actionId)) {
            return false;
          }

          page = page.fetchParentPage();
        }

        return true;
      }
    }

    return _hasPermission(permissionChecker, page, actionId);
  }
Exemplo n.º 4
0
  protected void compareVersions(RenderRequest renderRequest, RenderResponse renderResponse)
      throws Exception {

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

    long nodeId = ParamUtil.getLong(renderRequest, "nodeId");

    String title = ParamUtil.getString(renderRequest, "title");

    double sourceVersion = ParamUtil.getDouble(renderRequest, "sourceVersion");
    double targetVersion = ParamUtil.getDouble(renderRequest, "targetVersion");
    String type = ParamUtil.getString(renderRequest, "type", "escape");

    WikiPage sourcePage = WikiPageServiceUtil.getPage(nodeId, title, sourceVersion);
    WikiPage targetPage = WikiPageServiceUtil.getPage(nodeId, title, targetVersion);

    if (type.equals("html")) {
      WikiNode sourceNode = sourcePage.getNode();

      PortletURL viewPageURL = renderResponse.createRenderURL();

      viewPageURL.setParameter("struts_action", "/wiki/view");
      viewPageURL.setParameter("nodeName", sourceNode.getName());

      PortletURL editPageURL = renderResponse.createRenderURL();

      editPageURL.setParameter("struts_action", "/wiki/edit_page");
      editPageURL.setParameter("nodeId", String.valueOf(nodeId));
      editPageURL.setParameter("title", title);

      String attachmentURLPrefix =
          WikiUtil.getAttachmentURLPrefix(
              themeDisplay.getPathMain(), themeDisplay.getPlid(), nodeId, title);

      String htmlDiffResult =
          WikiUtil.diffHtml(sourcePage, targetPage, viewPageURL, editPageURL, attachmentURLPrefix);

      renderRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, htmlDiffResult);
    } else {
      String sourceContent = sourcePage.getContent();
      String targetContent = targetPage.getContent();

      sourceContent = WikiUtil.processContent(sourceContent);
      targetContent = WikiUtil.processContent(targetContent);

      if (type.equals("strip")) {
        sourceContent = HtmlUtil.extractText(sourceContent);
        targetContent = HtmlUtil.extractText(targetContent);
      } else {
        sourceContent = HtmlUtil.escape(sourceContent);
        targetContent = HtmlUtil.escape(targetContent);
      }

      List<DiffResult>[] diffResults =
          DiffUtil.diff(
              new UnsyncStringReader(sourceContent), new UnsyncStringReader(targetContent));

      renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);
    }

    renderRequest.setAttribute(WebKeys.WIKI_NODE_ID, nodeId);
    renderRequest.setAttribute(WebKeys.TITLE, title);
    renderRequest.setAttribute(WebKeys.SOURCE_VERSION, sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_VERSION, targetVersion);
  }
  public void markNotSpamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    checkWikiPagePermission(themeDisplay.getScopeGroupId());

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

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

    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(), PortletKeys.WIKI);

        LiferayPortletURL liferayPortletURL =
            PortletURLFactoryUtil.create(
                actionRequest, PortletKeys.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, "requestProcessed");

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

      super.sendRedirect(actionRequest, actionResponse);
    }
  }