public XDoc GetPage(DreamContext context, string pageid, int? redirects) { CheckResponseCache(context, false); PageBE page = PageBL_GetPage(pageid, redirects, true); page = PageBL.AuthorizePage(DekiContext.Current.User, Permissions.READ, page, false); var pageContentFilterSettings = new PageContentFilterSettings { ExcludeInboundLinks = context.GetParam("exclude", "").Contains("inbound"), ExcludeOutboundLinks = context.GetParam("exclude", "").Contains("outbound"), IncludeContents = context.GetParam("include", "").Contains("contents"), ContentsMode = ExtractParserMode(context.GetParam("mode", "view").ToLowerInvariant()), Revision = context.GetParam("revision", "HEAD"), Xhtml = context.GetParam("format", "html").EqualsInvariant("xhtml") }; // track page view count if((pageContentFilterSettings.ContentsMode == ParserMode.VIEW || pageContentFilterSettings.ContentsMode == ParserMode.VIEW_NO_EXECUTE) && pageContentFilterSettings.IncludeContents && DekiContext.Current.Instance.StatsPageHitCounter) { PageBL.IncrementViewCount(page); } return PageBL.GetPageXmlVerbose(page, null, pageContentFilterSettings); }
public static DreamMessage GetPage(Plug p, string path, PageContentFilterSettings pageContentFilter) { path = "=" + XUri.DoubleEncode(path); DreamMessage msg = null; var contentFilter = new List<string>(); if (pageContentFilter.ExcludeOutboundLinks) { contentFilter.Add("outbound"); } if (pageContentFilter.ExcludeInboundLinks) { contentFilter.Add("inbound"); } var pagesPlug = p.At("pages", path); if (contentFilter.Count > 0) { pagesPlug = pagesPlug.With("exclude", String.Join(",", contentFilter.ToArray())); } msg = pagesPlug.GetAsync().Wait(); Assert.IsTrue(msg.Status == DreamStatus.Ok || msg.Status == DreamStatus.NotFound, string.Format("Unexpected status: {0}", msg.Status)); return msg; }
public static XDoc GetPageXmlVerbose(PageBE page, string relation, PageContentFilterSettings contentFilterSettings) { XDoc pageXml = GetPageXml(page, relation, true); pageXml.Add(GetMetricsXml(page, true)); pageXml.Start("summary").Value(page.TIP).End(); //Pages that are not editable dont allow permission changes. If permission changes aren't allowed, don't display the security info. if(page.Title.IsEditable) { pageXml.Add(GetSecurityXml(page)); } // HACKHACKHACK (MaxM): Page Create timestamp and creator need to be tracked in the PageBE entity rather than queried DateTime? created = null; uint? creatorUserId = null; if(page.Revision == 1) { created = page.TimeStamp; creatorUserId = page.UserID; } else { var tailRev = GetOldRevisionForPage(page, 1); if(tailRev != null) { created = tailRev.TimeStamp; creatorUserId = tailRev.UserID; } } UserBE creator = null; if(creatorUserId != null) { creator = UserBL.GetUserById(creatorUserId.Value); } if(creator != null) { pageXml.Add(UserBL.GetUserXml(creator, "createdby", Utils.ShowPrivateUserInfo(creator))); } if(created != null) { pageXml.Start("date.created").Value(created.Value).End(); } pageXml.Start("date.edited").Value(page.TimeStamp).End(); pageXml.Start("date.modified").Value(page.Touched).End(); UserBE author; if(page.Revision == 1) { author = creator; } else { author = UserBL.GetUserById(page.UserID); } if(author != null) { pageXml.Add(UserBL.GetUserXml(author, "author", Utils.ShowPrivateUserInfo(author))); } pageXml.Start("description").Value(page.Comment).End(); pageXml.Elem("language", page.Language); pageXml.Add(BuildParentPageXmlTree(page, false)); // page redirection information pageXml.Start("page.redirectedfrom"); if(null != page.RedirectedFrom) { pageXml.Add(GetPageXml(page.RedirectedFrom, null, true)); } pageXml.End(); PageBE redirectedTo = GetTargetForRedirectPage(page); if(page.IsRedirect && redirectedTo != null) { pageXml.Add(GetPageXml(redirectedTo, "redirectedto", true)); } // Embed page rating RatingBL.AppendRatingXml(pageXml, page, DekiContext.Current.User); pageXml.Start("subpages").Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "subpages")).End(); // TODO (steveb): why is this commented out? //pageXml.Add(GetPageListXml("subpages", PageBL.GetChildren(this, true), DekiContext.Current.ApiUri.At("pages", ID.ToString(), "subpages"))); if(!contentFilterSettings.ExcludeOutboundLinks) { pageXml.Add(GetLinksXml(DbUtils.CurrentSession.Links_GetOutboundLinks(page.ID), "outbound")); } if(!contentFilterSettings.ExcludeInboundLinks) { pageXml.Add(GetLinksXml(DbUtils.CurrentSession.Links_GetInboundLinks(page.ID), "inbound")); } pageXml.Start("aliases") //TODO (Max): .Attr("count", ????) .Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "aliases")) .End(); pageXml.Start("revisions") .Attr("count", page.Revision) .Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "revisions")) .End(); // Emit archive revision info if(PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.ADMIN)) { pageXml.Start("revisions.archive") .Attr("count", DbUtils.CurrentSession.Archive_GetCountByTitle(page.Title)) .Attr("href", DekiContext.Current.ApiUri.At("archive", "pages", page.Title.AsApiParam(), "revisions")) .End(); } // Emit comment info pageXml.Start("comments") .Attr("count", DbUtils.CurrentSession.Comments_GetCountByPageId(page.ID).ToString()) .Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "comments")) .End(); //Embed properties for the attachment IList<ResourceBE> props = PropertyBL.Instance.GetPageProperties(page.ID); pageXml = PropertyBL.Instance.GetPropertyXml(props, GetUri(page), null, null, pageXml); //Backwards compatibility: return the language within properties pageXml["/page/properties"].Start("language").Attr("deprecated", true).Value(page.Language).End(); // Emit tags list XUri tagHref = DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "tags"); var tagBL = new TagBL(); pageXml.Add(tagBL.GetTagListXml(tagBL.GetTagsForPage(page), "tags", tagHref, false)); //Page file attachments pageXml.Add(AttachmentBL.Instance.GetFileXml(AttachmentBL.Instance.GetPageAttachments(page.ID), false, null, null, null)); if(contentFilterSettings.IncludeContents) { ParserResult parserResult; ResolvePageRev(page, contentFilterSettings.Revision); pageXml.Add(RetrievePageXDoc(page, (uint)page.ID, contentFilterSettings.ContentsMode, page.Language, false, -1, page.Title, contentFilterSettings.Xhtml, out parserResult)); // CESAR: finish } else { pageXml.Start("contents") .Attr("type", page.ContentType) .Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "contents")) .Attr("etag", page.Etag) .End(); if(DekiContext.Current.Deki.PrinceXmlPath != string.Empty) pageXml.Start("contents.alt").Attr("type", MimeType.PDF.FullType).Attr("href", DekiContext.Current.ApiUri.At("pages", page.ID.ToString(), "pdf")).End(); } return pageXml; }