public static boolean contains( PermissionChecker permissionChecker, WikiPage page, String actionId) { if (actionId.equals(ActionKeys.VIEW)) { WikiPage redirectPage = page.getRedirectPage(); if (redirectPage != null) { page = redirectPage; } } if (page.isPending()) { Boolean hasPermission = WorkflowPermissionUtil.hasPermission( permissionChecker, page.getGroupId(), WikiPage.class.getName(), page.getResourcePrimKey(), actionId); if (hasPermission != null) { return hasPermission.booleanValue(); } } if (page.isDraft() && actionId.equals(ActionKeys.DELETE) && (page.getStatusByUserId() == permissionChecker.getUserId())) { return true; } if (permissionChecker.hasOwnerPermission( page.getCompanyId(), WikiPage.class.getName(), page.getResourcePrimKey(), page.getUserId(), actionId)) { return true; } if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) { WikiPage parentPage = page.getParentPage(); if ((parentPage != null) && !contains(permissionChecker, parentPage, ActionKeys.VIEW)) { return false; } } return permissionChecker.hasPermission( page.getGroupId(), WikiPage.class.getName(), page.getResourcePrimKey(), actionId); }
private static boolean _hasPermission( PermissionChecker permissionChecker, WikiPage page, String actionId) { if (permissionChecker.hasOwnerPermission( page.getCompanyId(), WikiPage.class.getName(), page.getResourcePrimKey(), page.getUserId(), actionId) || permissionChecker.hasPermission( page.getGroupId(), WikiPage.class.getName(), page.getResourcePrimKey(), actionId)) { return true; } return false; }
protected void migrateWiki() throws Exception { int count = WikiPageLocalServiceUtil.getWikiPagesCount(); int pages = count / Indexer.DEFAULT_INTERVAL; MaintenanceUtil.appendStatus("Migrating wiki page attachments in " + count + " pages"); for (int i = 0; i <= pages; i++) { int start = (i * Indexer.DEFAULT_INTERVAL); int end = start + Indexer.DEFAULT_INTERVAL; List<WikiPage> wikiPages = WikiPageLocalServiceUtil.getWikiPages(start, end); for (WikiPage wikiPage : wikiPages) { if (!wikiPage.isHead()) { continue; } migrateFiles( wikiPage.getCompanyId(), wikiPage.getAttachmentsDir(), wikiPage.getAttachmentsFiles()); } } }
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); } }