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"); } }
public static XDoc GetCommentXml(CommentBE comment, string suffix) { return(GetCommentXml(new List <CommentBE>() { comment }, false, suffix, true, null, null, null, null, null)); }
public Yield GetCommentContent(DreamContext context, DreamMessage request, Result <DreamMessage> response) { PageBE page = null; CommentBE comment = null; GetCommentFromRequest(context, Permissions.READ, out page, out comment); response.Return(DreamMessage.Ok(new MimeType(comment.ContentMimeType), comment.Content)); yield break; }
public Yield DeleteComment(DreamContext context, DreamMessage request, Result <DreamMessage> response) { PageBE page = null; CommentBE comment = null; GetCommentFromRequest(context, Permissions.ADMIN, out page, out comment); CommentBL.DeleteComment(page, comment); response.Return(DreamMessage.Ok()); yield break; }
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 CommentBE Comments_GetById(uint commentId) { CommentBE comment = null; Catalog.NewQuery(@" /* Comments_GetById */ select * from `comments` where `cmnt_id` = ?COMMENTID") .With("COMMENTID", commentId) .Execute(delegate(IDataReader dr) { if (dr.Read()) { comment = Comments_Populate(dr); } }); 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, DekiResources.COMMENT_EDITED(comment.Number), comment); return(comment); }
public Yield GetComment(DreamContext context, DreamMessage request, Result <DreamMessage> response) { PageBE page = null; CommentBE comment = null; var commentId = context.GetParam <uint>("commentid", 0); if (commentId > 0) { comment = CommentBL.GetComment(commentId); } else { GetCommentFromRequest(context, Permissions.READ, out page, out comment); } response.Return(DreamMessage.Ok(CommentBL.GetCommentXml(comment, null))); yield break; }
public uint Comments_Insert(CommentBE comment, out ushort commentNumber) { uint commentId = 0; ushort tempCommentNumber = 0; var attempts = 3; while (attempts > 0) { try { Catalog.NewQuery(@" /* Comments_Insert */ insert into `comments` (`cmnt_page_id`, `cmnt_poster_user_id`, `cmnt_content`, `cmnt_content_mimetype`, `cmnt_title`, `cmnt_create_date`, `cmnt_number`) select ?PAGE_ID, ?POSTER_USER_ID, ?CONTENT, ?MIMETYPE, ?TITLE, ?TIMESTAMP, (select ifnull((select max(`cmnt_number`) from `comments` where `cmnt_page_id` = ?PAGE_ID), 0)+1); select cmnt_id, cmnt_number from comments where cmnt_id = LAST_INSERT_ID();") .With("PAGE_ID", comment.PageId) .With("POSTER_USER_ID", comment.PosterUserId) .With("CONTENT", comment.Content) .With("MIMETYPE", comment.ContentMimeType) .With("TITLE", comment.Title) .With("TIMESTAMP", comment.CreateDate) .Execute(delegate(IDataReader dr) { if (dr.Read()) { commentId = dr.Read <uint>("cmnt_id"); tempCommentNumber = dr.Read <ushort>("cmnt_number"); } }); } catch (MySqlException e) { // trap for duplicate key (since comment number calculation is a race condition) if (e.Number == 1062) { attempts--; if (attempts > 0) { continue; } throw new CommentConcurrencyException(comment.PageId, e); } throw; } break; } commentNumber = tempCommentNumber; return(commentId); }
private CommentBE Comments_Populate(IDataReader dr) { CommentBE comment = new CommentBE(); comment.Content = dr.Read <string>("cmnt_content"); comment.ContentMimeType = dr.Read <string>("cmnt_content_mimetype"); comment.CreateDate = dr.Read <DateTime>("cmnt_create_date"); comment.DeleteDate = dr.Read <DateTime?>("cmnt_delete_date"); comment.DeleterUserId = dr.Read <uint?>("cmnt_deleter_user_id"); comment.Id = dr.Read <ulong>("cmnt_id"); comment.LastEditDate = dr.Read <DateTime?>("cmnt_last_edit"); comment.LastEditUserId = dr.Read <uint?>("cmnt_last_edit_user_id"); comment.Number = dr.Read <ushort>("cmnt_number"); comment.PageId = dr.Read <ulong>("cmnt_page_id"); comment.PosterUserId = dr.Read <uint>("cmnt_poster_user_id"); comment.Title = dr.Read <string>("cmnt_title"); return(comment); }
public CommentBE Comments_GetByPageIdNumber(ulong pageId, ushort commentNumber) { CommentBE comment = null; Catalog.NewQuery(@" /* Comments_GetByPageIdNumber */ select * from `comments` where `cmnt_page_id` = ?PAGEID and `cmnt_number` = ?NUMBER;" ) .With("PAGEID", pageId) .With("NUMBER", commentNumber) .Execute(delegate(IDataReader dr) { if (dr.Read()) { comment = Comments_Populate(dr); } }); return(comment); }
public void Comments_Update(CommentBE comment) { Catalog.NewQuery(@" /* Comments_Update */ update comments set cmnt_last_edit_user_id = ?LAST_EDIT_USER_ID, cmnt_last_edit = ?EDIT_TIMESTAMP, cmnt_content = ?CONTENT, cmnt_content_mimetype = ?MIMETYPE, cmnt_deleter_user_id = ?DELETER_USER_ID, cmnt_delete_date = ?DELETE_TIMESTAMP where cmnt_id = ?COMMENTID;") .With("COMMENTID", comment.Id) .With("LAST_EDIT_USER_ID", comment.LastEditUserId) .With("EDIT_TIMESTAMP", comment.LastEditDate) .With("CONTENT", comment.Content) .With("MIMETYPE", comment.ContentMimeType) .With("DELETER_USER_ID", comment.DeleterUserId) .With("DELETE_TIMESTAMP", comment.DeleteDate) .Execute(); }
public Yield PostPageComment(DreamContext context, DreamMessage request, Result <DreamMessage> response) { PageBE page = PageBL_AuthorizePage(context, null, Permissions.READ, false); if (UserBL.IsAnonymous(DekiContext.Current.User)) { throw new CommentPostForAnonymousDeniedException(AUTHREALM, string.Empty); } CommentBE comment = CommentBL.PostNewComment(page, request, context); if (comment != null) { DekiContext.Current.Instance.EventSink.CommentCreate(DekiContext.Current.Now, comment, page, DekiContext.Current.User); response.Return(DreamMessage.Ok(CommentBL.GetCommentXml(comment, null))); } else { throw new CommentFailedPostFatalException(); } yield break; }
public IList <CommentBE> Comments_GetByUser(uint userId) { List <CommentBE> ret = new List <CommentBE>(); Catalog.NewQuery(@" /* Comments_GetByUser */ select * from `comments` where `cmnt_poster_user_id` = ?CMNT_POSTER_USER_ID order by `cmnt_create_date` desc ") .With("CMNT_POSTER_USER_ID", userId) .Execute(delegate(IDataReader dr) { while (dr.Read()) { CommentBE c = Comments_Populate(dr); ret.Add(c); } }); return(ret); }
public Yield PutCommentContent(DreamContext context, DreamMessage request, Result <DreamMessage> response) { PageBE page = null; CommentBE comment = null; GetCommentFromRequest(context, Permissions.READ, out page, out comment); if (UserBL.IsAnonymous(DekiContext.Current.User)) { throw new CommentPostForAnonymousDeniedException(AUTHREALM, string.Empty); } comment = CommentBL.EditExistingComment(page, comment, request, context); if (comment != null) { DekiContext.Current.Instance.EventSink.CommentUpdate(DekiContext.Current.Now, comment, page, DekiContext.Current.User); response.Return(DreamMessage.Ok(CommentBL.GetCommentXml(comment, null))); } else { throw new CommentFailedEditFatalException(); } yield break; }
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, DekiResources.COMMENT_ADDED(comment.Number), comment); return(comment); } }
private CommentBE Comments_Populate(IDataReader dr) { CommentBE comment = new CommentBE(); comment.Content = dr.Read<string>("cmnt_content"); comment.ContentMimeType = dr.Read<string>("cmnt_content_mimetype"); comment.CreateDate = dr.Read<DateTime>("cmnt_create_date"); comment.DeleteDate = dr.Read<DateTime?>("cmnt_delete_date"); comment.DeleterUserId = dr.Read<uint?>("cmnt_deleter_user_id"); comment.Id = dr.Read<ulong>("cmnt_id"); comment.LastEditDate = dr.Read<DateTime?>("cmnt_last_edit"); comment.LastEditUserId = dr.Read<uint?>("cmnt_last_edit_user_id"); comment.Number = dr.Read<ushort>("cmnt_number"); comment.PageId = dr.Read<ulong>("cmnt_page_id"); comment.PosterUserId = dr.Read<uint>("cmnt_poster_user_id"); comment.Title = dr.Read<string>("cmnt_title"); return comment; }
public uint Comments_Insert(CommentBE comment, out ushort commentNumber) { uint commentId = 0; ushort tempCommentNumber = 0; var attempts = 3; while(attempts > 0) { try { Catalog.NewQuery(@" /* Comments_Insert */ insert into `comments` (`cmnt_page_id`, `cmnt_poster_user_id`, `cmnt_content`, `cmnt_content_mimetype`, `cmnt_title`, `cmnt_create_date`, `cmnt_number`) select ?PAGE_ID, ?POSTER_USER_ID, ?CONTENT, ?MIMETYPE, ?TITLE, ?TIMESTAMP, (select ifnull((select max(`cmnt_number`) from `comments` where `cmnt_page_id` = ?PAGE_ID), 0)+1); select cmnt_id, cmnt_number from comments where cmnt_id = LAST_INSERT_ID();") .With("PAGE_ID", comment.PageId) .With("POSTER_USER_ID", comment.PosterUserId) .With("CONTENT", comment.Content) .With("MIMETYPE", comment.ContentMimeType) .With("TITLE", comment.Title) .With("TIMESTAMP", comment.CreateDate) .Execute(delegate(IDataReader dr) { if(dr.Read()) { commentId = dr.Read<uint>("cmnt_id"); tempCommentNumber = dr.Read<ushort>("cmnt_number"); } }); } catch(MySqlException e) { // trap for duplicate key (since comment number calculation is a race condition) if(e.Number == 1062) { attempts--; if(attempts > 0) { continue; } throw new CommentConcurrencyException(comment.PageId, e); } throw; } break; } commentNumber = tempCommentNumber; return commentId; }
public void CommentDelete(DateTime eventTime, CommentBE comment, PageBE parent, UserBE user) { PageDependentChanged(eventTime, parent, user, COMMENTS, DELETE); CommentChanged(eventTime, comment, parent, user, DELETE); }
public void CommentPoke(DateTime eventTime, CommentBE comment, PageBE parent, UserBE user) { CommentChanged(eventTime, comment, parent, user, NO_OP); }
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 IList <CommentBE> Comments_GetByPage(PageBE page, CommentFilter searchStatus, bool includePageDescendants, uint?postedByUserId, SortDirection datePostedSortDir, uint?offset, uint?limit, out uint totalComments) { List <CommentBE> comments = new List <CommentBE>(); uint totalCommentsTemp = 0; string joins = string.Empty; if (includePageDescendants) { joins = "JOIN pages \n\tON comments.cmnt_page_id = pages.page_id"; } string whereClauses = "\n 1=1"; switch (searchStatus) { case CommentFilter.DELETED: whereClauses += "\n AND cmnt_delete_date is not null"; break; case CommentFilter.NONDELETED: whereClauses += "\n AND cmnt_delete_date is null"; break; } if (includePageDescendants) { whereClauses += @" AND( ( (( ?TITLE = '' AND pages.page_title != '') OR (LEFT(pages.page_title, CHAR_LENGTH(?TITLE) + 1) = CONCAT(?TITLE, '/') AND SUBSTRING(pages.page_title, CHAR_LENGTH(?TITLE) + 2, 1) != '/')) AND pages.page_namespace = ?NS AND pages.page_is_redirect = 0 ) OR pages.page_id = ?PAGEID)" ; } else { whereClauses += "\n AND cmnt_page_id = ?PAGEID"; } if (postedByUserId != null) { whereClauses += "\n AND cmnt_poster_user_id = ?POSTERID"; } string orderby = string.Empty; if (datePostedSortDir != SortDirection.UNDEFINED) { orderby = string.Format("ORDER BY cmnt_create_date {0}, cmnt_id {0}", datePostedSortDir.ToString()); } List <uint> userids = new List <uint>(); string query = string.Format(@" /* Comments_GetByPage */ SELECT SQL_CALC_FOUND_ROWS comments.* FROM comments {0} WHERE {1} {2} LIMIT ?COUNT OFFSET ?OFFSET; select found_rows() as totalcomments;" , joins, whereClauses, orderby); Catalog.NewQuery(query) .With("PAGEID", page.ID) .With("TITLE", page.Title.AsUnprefixedDbPath()) .With("NS", (int)page.Title.Namespace) .With("POSTERID", postedByUserId) .With("COUNT", limit ?? UInt32.MaxValue) .With("OFFSET", offset ?? 0) .Execute(delegate(IDataReader dr) { while (dr.Read()) { CommentBE c = Comments_Populate(dr); if (c.DeleterUserId != null) { userids.Add(c.DeleterUserId ?? 0); } if (c.LastEditUserId != null) { userids.Add(c.LastEditUserId ?? 0); } userids.Add(c.PosterUserId); comments.Add(c); } if (dr.NextResult() && dr.Read()) { totalCommentsTemp = DbUtils.Convert.To <uint>(dr["totalcomments"]) ?? 0; } }); totalComments = totalCommentsTemp; return(comments); }
public static XUri GetUri(CommentBE comment) { return(DekiContext.Current.ApiUri.At("pages", comment.PageId.ToString(), "comments", comment.Number.ToString())); }
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(); } }
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); }
public XUri GetUri(CommentBE comment) { return(CommentBL.GetUri(comment)); }
public static void AddCommentUpdateRecentChange(DateTime timestamp, PageBE page, UserBE user, DekiResource summary, CommentBE comment) { AddCommentRecentChange(timestamp, page, user, summary, comment, RC.COMMENT_UPDATE); }