private static XDoc GetArchivePageXml(XDoc doc, ArchiveBE archivedPage, UserBE user, DateTime ts) { XDoc ret = doc; bool singlePage = false; if (ret == null || ret.IsEmpty) { ret = new XDoc("page.archive"); singlePage = true; } else { ret = ret.Start("page.archive"); } ret = ret.Attr("id", archivedPage.LastPageId).Attr("href", DekiContext.Current.ApiUri.At("archive", "pages", archivedPage.LastPageId.ToString(), "info")) .Start("title").Value(archivedPage.Title.AsUserFriendlyName()).End() .Start("path").Value(archivedPage.Title.AsPrefixedDbPath()).End() .Start("contents").Attr("type", archivedPage.ContentType).Attr("href", DekiContext.Current.ApiUri.At("archive", "pages", archivedPage.LastPageId.ToString(), "contents")).End(); if (user != null) { ret.Add(UserBL.GetUserXml(user, "deleted", false)); } if (ts != DateTime.MinValue) { ret.Elem("date.deleted", ts); } if (!singlePage) { ret.End(); } return(ret); }
private static XDoc AppendBanXml(XDoc doc, BanBE ban) { UserBE createdBy = UserBL.GetUserById(ban.ByUserId); doc.Attr("id", ban.Id); doc.Attr("href", DekiContext.Current.ApiUri.At("site", "bans", ban.Id.ToString())); if (createdBy != null) { doc.Add(UserBL.GetUserXml(createdBy, "createdby", Utils.ShowPrivateUserInfo(createdBy))); } doc.Elem("date.modified", ban.LastEdit); doc.Elem("description", ban.Reason); doc.Elem("date.expires", ban.Expires); doc.Add(PermissionsBL.GetPermissionXml(ban.RevokeMask, "revoked")); doc.Start("ban.addresses"); if (ban.BanAddresses != null) { foreach (string address in ban.BanAddresses) { doc.Elem("address", address); } } doc.End(); doc.Start("ban.users"); if (ban.BanUserIds != null) { var banUsers = DbUtils.CurrentSession.Users_GetByIds(ban.BanUserIds); foreach (UserBE u in banUsers) { doc.Add(UserBL.GetUserXml(u, null, Utils.ShowPrivateUserInfo(createdBy))); } } doc.End(); return(doc); }
private XDoc AppendFileXml(XDoc doc, ResourceBE file, string fileSuffix, bool?explicitRevisionInfo, UserBE updatedByUser, PageBE parentPage) { bool requiresEnd = false; string fileElement = string.IsNullOrEmpty(fileSuffix) ? "file" : "file." + fileSuffix; if (doc == null || doc.IsEmpty) { doc = new XDoc(fileElement); } else { doc.Start(fileElement); requiresEnd = true; } doc.Attr("id", file.MetaXml.FileId ?? 0); doc.Attr("revision", file.Revision); doc.Attr("res-id", file.ResourceId); if (file.IsHidden) { doc.Attr("hidden", true); } doc.Attr("href", GetUriInfo(file, explicitRevisionInfo)); doc.Start("filename").Value(file.Name).End(); //Description comes from a property string description = string.Empty; if (!ArrayUtil.IsNullOrEmpty(file.ChildResources)) { ResourceBE descProp = Array.Find(file.ChildResources, p => p != null && p.ResourceType == ResourceBE.Type.PROPERTY && p.Name.EqualsInvariantIgnoreCase(PropertyBL.PROP_DESC)); if (descProp != null) { description = descProp.Content.ToText(); } } doc.Start("description").Value(description).End(); doc.Start("contents") .Attr("type", file.MimeType == null ? null : file.MimeType.ToString()) .Attr("size", file.Size); if ((file.MetaXml.ImageHeight ?? 0) > 0 && (file.MetaXml.ImageWidth ?? 0) > 0) { doc.Attr("width", file.MetaXml.ImageWidth.Value); doc.Attr("height", file.MetaXml.ImageHeight.Value); } doc.Attr("href", GetUriContent(file, explicitRevisionInfo)); doc.End(); //contents if ((file.MetaXml.ImageWidth ?? 0) > 0 && (file.MetaXml.ImageHeight ?? 0) > 0) { string previewMime = AttachmentPreviewBL.ResolvePreviewMime(file.MimeType).ToString(); doc.Start("contents.preview") .Attr("rel", "thumb") .Attr("type", previewMime) .Attr("maxwidth", _dekiContext.Instance.ImageThumbPixels) .Attr("maxheight", _dekiContext.Instance.ImageThumbPixels) .Attr("href", GetUriContent(file, explicitRevisionInfo).With("size", "thumb")); if (!file.IsHeadRevision() || (explicitRevisionInfo ?? false)) { doc.Attr("revision", file.Revision); } doc.End(); //contents.preview: thumb doc.Start("contents.preview") .Attr("rel", "webview") .Attr("type", previewMime) .Attr("maxwidth", _dekiContext.Instance.ImageWebviewPixels) .Attr("maxheight", _dekiContext.Instance.ImageWebviewPixels) .Attr("href", GetUriContent(file, explicitRevisionInfo).With("size", "webview")); if (!file.IsHeadRevision() || (explicitRevisionInfo ?? false)) { doc.Attr("revision", file.Revision); } doc.End(); //contents.preview: webview } doc.Start("date.created").Value(file.Timestamp).End(); if (updatedByUser != null) { doc.Add(UserBL.GetUserXml(updatedByUser, "createdby", Utils.ShowPrivateUserInfo(updatedByUser))); } if (file.ResourceIsDeleted && ((file.ChangeMask & ResourceBE.ChangeOperations.DELETEFLAG) == ResourceBE.ChangeOperations.DELETEFLAG)) { if (updatedByUser != null) { doc.Add(UserBL.GetUserXml(updatedByUser, "deletedby", Utils.ShowPrivateUserInfo(updatedByUser))); } doc.Start("date.deleted").Value(file.Timestamp).End(); } if (file.IsHeadRevision() && !(explicitRevisionInfo ?? false) && !file.ResourceIsDeleted) { uint filteredCount = _session.Resources_GetRevisionCount(file.ResourceId, DEFAULT_REVISION_FILTER); doc.Start("revisions"); doc.Attr("count", filteredCount); doc.Attr("totalcount", file.Revision); doc.Attr("href", GetUri(file).At("revisions")); doc.End(); } else { if (file.ChangeMask != ResourceBE.ChangeOperations.UNDEFINED) { doc.Start("user-action").Attr("type", file.ChangeMask.ToString().ToLowerInvariant()).End(); } } //parent page is passed in for verbose output only if (parentPage != null) { doc.Add(PageBL.GetPageXml(parentPage, "parent")); } if (file.ChildResources != null) { List <ResourceBE> properties = new List <ResourceBE>(); foreach (ResourceBE p in file.ChildResources) { properties.Add(p); } doc = PropertyBL.Instance.GetPropertyXml(properties.ToArray(), GetUri(file), null, null, doc); } if (file.IsHidden) { uint?userIdHiddenBy = file.MetaXml.RevisionHiddenUserId; if (userIdHiddenBy != null) { UserBE userHiddenBy = UserBL.GetUserById(userIdHiddenBy.Value); if (userHiddenBy != null) { doc.Add(UserBL.GetUserXml(userHiddenBy, "hiddenby", Utils.ShowPrivateUserInfo(userHiddenBy))); } } doc.Elem("date.hidden", file.MetaXml.RevisionHiddenTimestamp ?? DateTime.MinValue); doc.Elem("description.hidden", file.MetaXml.RevisionHiddenComment ?? string.Empty); } if (requiresEnd) { doc.End(); //file } return(doc); }
private static XDoc AppendCommentXml(XDoc doc, CommentBE comment, string suffix, bool?includeParentInfo) { bool requiresEnd = false; string commentElement = string.IsNullOrEmpty(suffix) ? "comment" : "comment." + suffix; if (doc == null || doc.IsEmpty) { doc = new XDoc(commentElement); } else { doc.Start(commentElement); requiresEnd = true; } doc.Attr("id", comment.Id).Attr("href", CommentBL.GetUri(comment)); //include parentinfo by default if the parent page is populated PageBE page = PageBL.GetPageById(comment.PageId); if (page != null && (includeParentInfo ?? true)) { doc.Add(PageBL.GetPageXml(page, "parent")); } UserBE posterUser = UserBL.GetUserById(comment.PosterUserId); if (posterUser != null) { doc.Add(UserBL.GetUserXml(posterUser, "createdby", Utils.ShowPrivateUserInfo(posterUser))); } doc.Start("date.posted").Value(comment.CreateDate).End(); doc.Start("title").Value(comment.Title).End(); doc.Start("number").Value(comment.Number).End(); //Note (MaxM): Replytoid/replies not yet exposed //if (ReplyToId.HasValue) { // doc.Start("comment.replyto") // .Attr("number", ReplyToId.Value.ToString()) // .Attr("href", DekiContext.Current.ApiUri.At("pages", PageId.ToString(), "comments", ReplyToId.Value.ToString())).End(); //} bool displayContent = true; //Only display content for nondeleted comments or for admins if (comment.IsCommentMarkedAsDeleted) { displayContent = PermissionsBL.IsUserAllowed(DekiContext.Current.User, Permissions.ADMIN); } if (displayContent) { doc.Start("content") .Attr("type", comment.ContentMimeType) .Attr("href", CommentBL.GetUri(comment).At("content")) .Value(comment.Content).End(); } if (comment.LastEditUserId.HasValue) { UserBE lastEditUser = UserBL.GetUserById(comment.LastEditUserId.Value); if (null != lastEditUser) { doc.Add(UserBL.GetUserXml(lastEditUser, "editedby", Utils.ShowPrivateUserInfo(lastEditUser))); doc.Start("date.edited").Value(comment.LastEditDate).End(); } } if (comment.IsCommentMarkedAsDeleted && comment.DeleterUserId.HasValue) { UserBE deleteUser = UserBL.GetUserById(comment.DeleterUserId.Value); if (null != deleteUser) { doc.Add(UserBL.GetUserXml(deleteUser, "deletedby", Utils.ShowPrivateUserInfo(deleteUser))); doc.Start("date.deleted").Value(comment.DeleteDate).End(); } } if (requiresEnd) { doc.End(); //comment } return(doc); }
private XDoc AppendPropertyXml(XDoc doc, ResourceBE property, XUri parentResourceUri, string propSuffix, bool?explicitRevisionInfo, uint?contentCutoff, Dictionary <uint, UserBE> usersById) { bool requiresEnd = false; explicitRevisionInfo = explicitRevisionInfo ?? false; string propElement = string.IsNullOrEmpty(propSuffix) ? "property" : "property." + propSuffix; if (doc == null || doc.IsEmpty) { doc = new XDoc(propElement); } else { doc.Start(propElement); requiresEnd = true; } //Build the base uri to the property bool includeContents = property.Size <= (contentCutoff ?? DEFAULT_CONTENT_CUTOFF) && (property.MimeType.Match(MimeType.ANY_TEXT) ); //TODO: contents null check doc.Attr("name", property.Name) .Attr("href", /*explicitRevisionInfo.Value ? property.PropertyInfoUri(parentResourceUri, true) : */ property.PropertyInfoUri(parentResourceUri)); if (property.IsHeadRevision()) { doc.Attr("etag", property.ETag()); } /* PROPERTY REVISIONS: if(!property.IsHeadRevision() || explicitRevisionInfo.Value) { * revisions not currently exposed. * doc.Attr("revision", property.Revision); * } */ /* PROPERTY REVISIONS: doc.Start("revisions") * .Attr("count", property.ResourceHeadRevision) * .Attr("href", property.UriRevisions()) * .End(); */ string content = null; if (includeContents) { content = property.Content.ToText(); } doc.Start("contents") .Attr("type", property.MimeType.ToString()) .Attr("size", property.Size) .Attr("href", /*PROPERTY REVISIONS: explicitRevisionInfo.Value ? property.PropertyContentUri(true) : */ property.PropertyContentUri(parentResourceUri)) .Value(content) .End(); doc.Elem("date.modified", property.Timestamp); UserBE userModified; usersById.TryGetValue(property.UserId, out userModified); if (userModified != null) { doc.Add(UserBL.GetUserXml(userModified, "modified", Utils.ShowPrivateUserInfo(userModified))); } doc.Elem("change-description", property.ChangeDescription); if (property.Deleted) { UserBE userDeleted; usersById.TryGetValue(property.UserId, out userDeleted); if (userDeleted != null) { doc.Add(UserBL.GetUserXml(userDeleted, "deleted", Utils.ShowPrivateUserInfo(userDeleted))); } doc.Elem("date.deleted", property.Timestamp); } if (requiresEnd) { doc.End(); //property } return(doc); }