public static CommentBE PostNewComment(PageBE page, DreamMessage request, DreamContext context) { ValidateCommentText(request.ContentType, request.AsText()); CommentBE comment = new CommentBE(); comment.Title = context.GetParam("title", string.Empty); comment.PageId = page.ID; comment.Content = request.AsText(); comment.ContentMimeType = request.ContentType.ToString(); comment.PosterUserId = DekiContext.Current.User.ID; comment.CreateDate = DateTime.UtcNow; //Note (MaxM): Replytoid/replies not yet exposed //ulong replyToId = context.GetParam<ulong>("replyto", 0); //if (replyToId == 0) // newComment.ReplyToId = null; //else // newComment.ReplyToId = replyToId; ushort commentNumber; uint commentId = DbUtils.CurrentSession.Comments_Insert(comment, out commentNumber); if (commentId == 0) { return null; } else { comment.Id = commentId; comment.Number = commentNumber; PageBL.Touch(page, comment.CreateDate); RecentChangeBL.AddCommentCreateRecentChange(comment.CreateDate, page, DekiContext.Current.User, string.Format(DekiResources.COMMENT_ADDED, comment.Number.ToString()), comment); return comment; } }
//--- Methods --- public virtual CommentBE Copy() { CommentBE comment = new CommentBE(); comment.Content = Content; comment.ContentMimeType = ContentMimeType; comment.CreateDate = CreateDate; comment.DeleteDate = DeleteDate; comment.DeleterUserId = DeleterUserId; comment.Id = Id; comment.LastEditDate = LastEditDate; comment.LastEditUserId = LastEditUserId; comment.Number = Number; comment.PageId = PageId; comment.PosterUserId = PosterUserId; comment.Title = Title; return(comment); }
public static CommentBE EditExistingComment(PageBE page, CommentBE comment, DreamMessage request, DreamContext context) { if (comment.PosterUserId != DekiContext.Current.User.ID) { PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN); } ValidateCommentText(request.ContentType, request.AsText()); comment.LastEditDate = DateTime.UtcNow; comment.LastEditUserId = DekiContext.Current.User.ID; comment.Content = request.AsText(); comment.ContentMimeType = request.ContentType.ToString(); DbUtils.CurrentSession.Comments_Update(comment); PageBL.Touch(page, comment.LastEditDate.Value); RecentChangeBL.AddCommentUpdateRecentChange(comment.LastEditDate.Value, page, DekiContext.Current.User, string.Format(DekiResources.COMMENT_EDITED, comment.Number.ToString()), comment); return comment; }
//--- Methods --- public virtual CommentBE Copy() { CommentBE comment = new CommentBE(); comment.Content = Content; comment.ContentMimeType = ContentMimeType; comment.CreateDate = CreateDate; comment.DeleteDate = DeleteDate; comment.DeleterUserId = DeleterUserId; comment.Id = Id; comment.LastEditDate = LastEditDate; comment.LastEditUserId = LastEditUserId; comment.Number = Number; comment.PageId = PageId; comment.PosterUserId = PosterUserId; comment.Title = Title; return comment; }
private static void AddCommentRecentChange(DateTime timestamp, PageBE page, UserBE user, string summary, CommentBE comment, RC rcType) { //TODO MaxM: Consider truncating summary DbUtils.CurrentSession.RecentChanges_Insert(timestamp, page, user, summary, 0, rcType, 0, string.Empty, false, 0); }
public static void AddCommentUpdateRecentChange(DateTime timestamp, PageBE page, UserBE user, string summary, CommentBE comment) { AddCommentRecentChange(timestamp, page, user, summary, comment, RC.COMMENT_UPDATE); }
public void Comments_Update(CommentBE comment) { Stopwatch sw = Stopwatch.StartNew(); _next.Comments_Update(comment); LogQuery(CATEGORY_COMMENTS, "Comments_Update", sw, "comment", comment); }
public static void DeleteComment(PageBE page, CommentBE comment) { if (!comment.IsCommentMarkedAsDeleted) { comment.DeleteDate = DateTime.UtcNow; comment.DeleterUserId = DekiContext.Current.User.ID; DbUtils.CurrentSession.Comments_Update(comment); PageBL.Touch(page, comment.DeleteDate.Value); RecentChangeBL.AddCommentDeleteRecentChange(comment.DeleteDate.Value, page, DekiContext.Current.User, string.Format(DekiResources.COMMENT_DELETED, comment.Number.ToString()), comment); DekiContext.Current.Instance.EventSink.CommentDelete(DreamContext.Current.StartTime, comment, page, DekiContext.Current.User); } }
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 static void AddCommentRecentChange(DateTime timestamp, PageBE page, UserBE user, DekiResource summary, CommentBE comment, RC rcType) { var resources = DekiContext.Current.Resources; //TODO MaxM: Consider truncating summary DbUtils.CurrentSession.RecentChanges_Insert(timestamp, page, user, resources.Localize(summary), 0, rcType, 0, string.Empty, false, 0); }
public static void AddCommentDeleteRecentChange(DateTime timestamp, PageBE page, UserBE user, DekiResource summary, CommentBE comment) { AddCommentRecentChange(timestamp, page, user, summary, comment, RC.COMMENT_DELETE); }
internal Hashtable MakeCommentObject(CommentBE comment) { Hashtable entry = new Hashtable(StringComparer.OrdinalIgnoreCase) { { "text", comment.Content }, { "mime", comment.ContentMimeType }, { "date", DekiScriptLibrary.CultureDateTime(comment.CreateDate) }, { "author", PropertyAt("$user", comment.PosterUserId) }, { "page", PropertyAt("$page", comment.PageId) }, { "uri", PropertyAt("$commenturi", comment.PageId, comment.Number) }, { "number", comment.Number } }; return entry; }
private void GetCommentFromRequest(DreamContext context, Permissions access, out PageBE page, out CommentBE comment) { page = null; comment = null; ushort commentNumber = context.GetParam<ushort>("commentnumber"); if(commentNumber != 0) { page = PageBL.AuthorizePage(DekiContext.Current.User, Permissions.READ, false); comment = DbUtils.CurrentSession.Comments_GetByPageIdNumber(page.ID, commentNumber); } if(comment == null) { throw new DreamAbortException(DreamMessage.NotFound(DekiResources.COMMENT_NOT_FOUND)); } }
public XUri GetUri(CommentBE comment) { return CommentBL.GetUri(comment); }
public static void DeleteComment(PageBE page, CommentBE comment) { if(comment.PosterUserId != DekiContext.Current.User.ID) { PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN); } if (!comment.IsCommentMarkedAsDeleted) { comment.DeleteDate = DateTime.UtcNow; comment.DeleterUserId = DekiContext.Current.User.ID; DbUtils.CurrentSession.Comments_Update(comment); PageBL.Touch(page, comment.DeleteDate.Value); RecentChangeBL.AddCommentDeleteRecentChange(comment.DeleteDate.Value, page, DekiContext.Current.User, DekiResources.COMMENT_DELETED(comment.Number), comment); DekiContext.Current.Instance.EventSink.CommentDelete(DekiContext.Current.Now, comment, page, DekiContext.Current.User); } }
public static XUri GetUri(CommentBE comment) { return DekiContext.Current.ApiUri.At("pages", comment.PageId.ToString(), "comments", comment.Number.ToString()); }
public static XDoc GetCommentXml(CommentBE comment, string suffix) { return GetCommentXml(new List<CommentBE>() {comment}, false, suffix, true, null, null, null, null, null); }
public void CommentPoke(DateTime eventTime, CommentBE comment, PageBE parent, UserBE user) { CommentChanged(eventTime, comment, parent, user, NO_OP); }
public void CommentDelete(DateTime eventTime, CommentBE comment, PageBE parent, UserBE user) { PageDependentChanged(eventTime, parent, user, COMMENTS, DELETE); CommentChanged(eventTime, comment, parent, user, DELETE); }
private void CommentChanged(DateTime eventTime, CommentBE comment, PageBE parent, UserBE user, params string[] channelPath) { try { XUri channel = _channel.At(COMMENTS).At(channelPath); XUri resource = CommentBL.GetUri(comment).WithHost(_wikiid); string[] origin = new string[] { CommentBL.GetUri(comment).AsServerUri().ToString() }; string path = parent.Title.AsUiUriPath() + "#comment" + comment.Number; XDoc doc = new XDoc("deki-event") //userid is deprecated and user/id should be used instead .Elem("userid", comment.PosterUserId) .Elem("pageid", comment.PageId) .Elem("uri.page", PageBL.GetUriCanonical(parent).AsServerUri().ToString()) .Start("user") .Attr("id", user.ID) .Attr("anonymous", UserBL.IsAnonymous(user)) .Elem("uri", UserBL.GetUri(user)) .End() .Elem("channel", channel) .Elem("uri", CommentBL.GetUri(comment).AsServerUri().ToString()) .Elem("path", path) .Start("content").Attr("uri", CommentBL.GetUri(comment).AsServerUri().At("content").ToString()).End(); if(comment.Content.Length < 255) { doc["content"].Attr("type", comment.ContentMimeType).Value(comment.Content); } Queue(eventTime, channel, resource, origin, doc); } catch(Exception e) { _log.WarnMethodCall("CommentChanged", "event couldn't be created"); } }
private void GetCommentFromRequest(DreamContext context, Permissions access, out PageBE page, out CommentBE comment) { page = null; comment = null; ushort commentNumber = context.GetParam<ushort>("commentnumber"); if(commentNumber != 0) { page = PageBL_AuthorizePage(context, null, Permissions.READ, false); comment = DbUtils.CurrentSession.Comments_GetByPageIdNumber(page.ID, commentNumber); } if(comment == null) { throw new CommentNotFoundException(); } }
public uint Comments_Insert(CommentBE comment, out ushort commentNumber) { Stopwatch sw = Stopwatch.StartNew(); var ret = _next.Comments_Insert(comment, out commentNumber); LogQuery(CATEGORY_COMMENTS, "Comments_Insert", sw, "comment", comment); return ret; }