public void spamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "spamWikiPageIds"); for (long wikiPageId : wikiPageIds) { WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId); wikiPage.setSummary(AkismetConstants.WIKI_PAGE_MARKED_AS_SPAM); WikiPageLocalServiceUtil.updateWikiPage(wikiPage); } }
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); } }