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); } }
@Override protected StagedModel getStagedModel(String uuid, Group group) { try { return WikiPageLocalServiceUtil.getWikiPageByUuidAndGroupId(uuid, group.getGroupId()); } catch (Exception e) { return null; } }
@Test public void testDeleteAttachmentsWhenDeletingWikiPage() throws Exception { int initialFileEntriesCount = DLFileEntryLocalServiceUtil.getFileEntriesCount(); addWikiPageAttachment(); Assert.assertEquals( initialFileEntriesCount + 1, DLFileEntryLocalServiceUtil.getFileEntriesCount()); WikiPageLocalServiceUtil.deletePage(_page.getNodeId(), _page.getTitle()); Assert.assertEquals(initialFileEntriesCount, DLFileEntryLocalServiceUtil.getFileEntriesCount()); }
@Test public void testFoldersCountWhenDeletingWikiPageWithoutAttachments() throws Exception { int initialFoldersCount = DLFolderLocalServiceUtil.getDLFoldersCount(); addWikiPage(); Assert.assertEquals(initialFoldersCount, DLFolderLocalServiceUtil.getDLFoldersCount()); WikiPageLocalServiceUtil.deletePage(_page.getNodeId(), _page.getTitle()); Assert.assertEquals(initialFoldersCount, DLFolderLocalServiceUtil.getDLFoldersCount()); }
private void _trashWikiAttachments(boolean restore) throws Exception { int initialNotInTrashCount = _page.getAttachmentsFileEntriesCount(); int initialTrashEntriesCount = _page.getDeletedAttachmentsFileEntriesCount(); String fileName = RandomTestUtil.randomString() + ".docx"; WikiTestUtil.addWikiAttachment( TestPropsValues.getUserId(), _node.getNodeId(), _page.getTitle(), fileName, getClass()); Assert.assertEquals(initialNotInTrashCount + 1, _page.getAttachmentsFileEntriesCount()); Assert.assertEquals(initialTrashEntriesCount, _page.getDeletedAttachmentsFileEntriesCount()); FileEntry fileEntry = WikiPageLocalServiceUtil.movePageAttachmentToTrash( TestPropsValues.getUserId(), _page.getNodeId(), _page.getTitle(), fileName); Assert.assertEquals(initialNotInTrashCount, _page.getAttachmentsFileEntriesCount()); Assert.assertEquals( initialTrashEntriesCount + 1, _page.getDeletedAttachmentsFileEntriesCount()); if (restore) { TrashEntryServiceUtil.restoreEntry( DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId()); Assert.assertEquals(initialNotInTrashCount + 1, _page.getAttachmentsFileEntriesCount()); Assert.assertEquals(initialTrashEntriesCount, _page.getDeletedAttachmentsFileEntriesCount()); WikiPageLocalServiceUtil.deletePageAttachment(_page.getNodeId(), _page.getTitle(), fileName); } else { WikiPageLocalServiceUtil.deletePageAttachment( _page.getNodeId(), _page.getTitle(), fileEntry.getTitle()); Assert.assertEquals(initialNotInTrashCount, _page.getAttachmentsFileEntriesCount()); Assert.assertEquals(initialTrashEntriesCount, _page.getDeletedAttachmentsFileEntriesCount()); } }
public static String getURL( HttpServletRequest request, ThemeDisplay themeDisplay, AssetRendererFactory assetRendererFactory, AssetRenderer assetRenderer) throws Exception { long classPK = assetRenderer.getClassPK(); String className = assetRendererFactory.getClassName(); String portletId = PortletProviderUtil.getPortletId(className, PortletProvider.Action.VIEW); PortletURL portletURL = null; if (className.equals(BlogsEntry.class.getName())) { portletURL = PortletURLFactoryUtil.create( request, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcRenderCommandName", "/blogs/view_entry"); portletURL.setParameter("entryId", String.valueOf(classPK)); } else if (className.equals(JournalArticle.class.getName())) { JournalArticle journalArticle = JournalArticleLocalServiceUtil.getLatestArticle(classPK); portletURL = PortletURLFactoryUtil.create( request, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("struts_action", "/journal_content/view"); portletURL.setParameter("groupId", String.valueOf(journalArticle.getGroupId())); portletURL.setParameter("articleId", journalArticle.getArticleId()); } else if (className.equals(KBArticle.class.getName())) { portletURL = PortletURLFactoryUtil.create( request, PortletKeys.KNOWLEDGE_BASE_ARTICLE_DEFAULT_INSTANCE, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcPath", "/article/view_article.jsp"); portletURL.setParameter("resourcePrimKey", String.valueOf(classPK)); } else if (className.equals(MBMessage.class.getName())) { portletURL = PortletURLFactoryUtil.create( request, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("struts_action", "/message_boards/view_message"); portletURL.setParameter("messageId", String.valueOf(classPK)); } else if (className.equals(WikiPage.class.getName())) { WikiPage wikiPage = WikiPageLocalServiceUtil.getPage(classPK); portletURL = PortletURLFactoryUtil.create( request, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setParameter("struts_action", "/wiki/view"); portletURL.setParameter("nodeId", String.valueOf(wikiPage.getNodeId())); portletURL.setParameter("title", wikiPage.getTitle()); } String currentURL = PortalUtil.getCurrentURL(request); if (portletURL == null) { return currentURL; } portletURL.setWindowState(WindowState.MAXIMIZED); portletURL.setPortletMode(PortletMode.VIEW); portletURL.setParameter("returnToFullPageURL", currentURL); return portletURL.toString(); }
@Override protected void updateBaseModel(long baseModelId) throws Exception { WikiPage page = WikiPageLocalServiceUtil.getPage(baseModelId); WikiTestUtil.updatePage(page); }
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); } }
@Override protected void addSubscriptionBaseModel(long baseModelId) throws Exception { WikiPage page = WikiPageLocalServiceUtil.getPage(baseModelId); WikiPageLocalServiceUtil.subscribePage(user.getUserId(), page.getNodeId(), page.getTitle()); }