<commit_before>using System;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Web.Admin.Pages;

namespace Subtext.Web.Admin.Feedback
{
    public partial class EditPage : ConfirmationPage
    {
        int _feedbackId = NullValue.NullInt32;

        public EditPage()
        {
            TabSectionId = "Feedback";
        }

        bool ReturnToOriginalPost
        {
            get
            {
                string returnText = Request.QueryString["return-to-post"] ?? "false";
                return String.Equals(returnText, "true", StringComparison.InvariantCultureIgnoreCase);
            }
        }

        protected string CancelUrl
        {
            get
            {
                if(FeedbackId > -1 && ReturnToOriginalPost)
                {
                    // We came from outside the post, let's go there.
                    FeedbackItem updatedFeedback = FeedbackItem.Get(FeedbackId);
                    if(updatedFeedback != null)
                    {
                        return Url.FeedbackUrl(updatedFeedback);
                    }
                }
                //Go back to the list.
                return Master.ListUrl();
            }
        }

        public int FeedbackId
        {
            get
            {
                if(_feedbackId == NullValue.NullInt32)
                {
                    string feedbackIdText = Request.QueryString["FeedbackID"] ?? " ";
                    int id;
                    if(int.TryParse(feedbackIdText, out id))
                    {
                        _feedbackId = id;
                    }
                }
                return _feedbackId;
            }
        }

        protected new FeedbackMaster Master
        {
            get { return base.Master as FeedbackMaster; }
        }

        protected override void OnLoad(EventArgs e)
        {
            if(FeedbackId == NullValue.NullInt32)
            {
                Response.Redirect(CancelUrl);
                return;
            }

            if(!IsPostBack)
            {
                BindFeedbackEdit();
            }
            base.OnLoad(e);
        }

        private void BindFeedbackEdit()
        {
            FeedbackItem currentFeedback = FeedbackItem.Get(FeedbackId);
            if(currentFeedback == null)
            {
                Response.Redirect("./");
                return;
            }

            SetConfirmation();
            lblName.Text = currentFeedback.Author;
            lblEmail.Text = currentFeedback.Email;
            if(currentFeedback.Email.Length > 0)
            {
                hlAuthorEmail.NavigateUrl = "mailto:" + currentFeedback.Email;
            }

            hlEntryLink.NavigateUrl = Url.FeedbackUrl(currentFeedback);
            hlEntryLink.Text = Url.FeedbackUrl(currentFeedback);
            if(currentFeedback.SourceUrl != null)
            {
                txbWebsite.Text = currentFeedback.SourceUrl.ToString();
            }

            txbTitle.Text = currentFeedback.Title;

            richTextEditor.Text = currentFeedback.Body;
        }

        private void SetConfirmation()
        {
            var confirmPage = (ConfirmationPage)Page;
            confirmPage.IsInEdit = true;
            confirmPage.Message = "You will lose any unsaved content";

            lkbPost.Attributes.Add("OnClick", BypassFunctionName);
        }

        private void UpdateFeedback()
        {
            Uri feedbackWebsite = null;
            valtxbWebsite.IsValid = !(txbWebsite.Text.Length > 0) || Uri.TryCreate(txbWebsite.Text, UriKind.RelativeOrAbsolute, out feedbackWebsite);

            if(Page.IsValid)
            {
                FeedbackItem updatedFeedback = FeedbackItem.Get(FeedbackId);
                updatedFeedback.Title = txbTitle.Text;
                updatedFeedback.Body = richTextEditor.Text;
                if(feedbackWebsite != null)
                {
                    updatedFeedback.SourceUrl = feedbackWebsite;
                }
                FeedbackItem.Update(updatedFeedback);

                if(ReturnToOriginalPost)
                {
                    Response.Redirect(Url.FeedbackUrl(updatedFeedback));
                    return;
                }

                Messages.ShowMessage(Constants.RES_SUCCESSEDIT, false);
            }
        }

        protected void lkbPost_Click(object sender, EventArgs e)
        {
            UpdateFeedback();
        }
    }
}<commit_msg>Fixed issue #177: Editing a comment doesn't invalidate cache for that comment.<commit_after>using System;
using Subtext.Framework;
using Subtext.Framework.Components;
using Subtext.Framework.Data;
using Subtext.Web.Admin.Pages;

namespace Subtext.Web.Admin.Feedback
{
    public partial class EditPage : ConfirmationPage
    {
        int _feedbackId = NullValue.NullInt32;

        public EditPage()
        {
            TabSectionId = "Feedback";
        }

        bool ReturnToOriginalPost
        {
            get
            {
                string returnText = Request.QueryString["return-to-post"] ?? "false";
                return String.Equals(returnText, "true", StringComparison.InvariantCultureIgnoreCase);
            }
        }

        protected string CancelUrl
        {
            get
            {
                if(FeedbackId > -1 && ReturnToOriginalPost)
                {
                    // We came from outside the post, let's go there.
                    FeedbackItem updatedFeedback = FeedbackItem.Get(FeedbackId);
                    if(updatedFeedback != null)
                    {
                        return Url.FeedbackUrl(updatedFeedback);
                    }
                }
                //Go back to the list.
                return Master.ListUrl();
            }
        }

        public int FeedbackId
        {
            get
            {
                if(_feedbackId == NullValue.NullInt32)
                {
                    string feedbackIdText = Request.QueryString["FeedbackID"] ?? " ";
                    int id;
                    if(int.TryParse(feedbackIdText, out id))
                    {
                        _feedbackId = id;
                    }
                }
                return _feedbackId;
            }
        }

        protected new FeedbackMaster Master
        {
            get { return base.Master as FeedbackMaster; }
        }

        protected override void OnLoad(EventArgs e)
        {
            if(FeedbackId == NullValue.NullInt32)
            {
                Response.Redirect(CancelUrl);
                return;
            }

            if(!IsPostBack)
            {
                BindFeedbackEdit();
            }
            base.OnLoad(e);
        }

        private void BindFeedbackEdit()
        {
            FeedbackItem currentFeedback = FeedbackItem.Get(FeedbackId);
            if(currentFeedback == null)
            {
                Response.Redirect("./");
                return;
            }

            SetConfirmation();
            lblName.Text = currentFeedback.Author;
            lblEmail.Text = currentFeedback.Email;
            if(currentFeedback.Email.Length > 0)
            {
                hlAuthorEmail.NavigateUrl = "mailto:" + currentFeedback.Email;
            }

            hlEntryLink.NavigateUrl = Url.FeedbackUrl(currentFeedback);
            hlEntryLink.Text = Url.FeedbackUrl(currentFeedback);
            if(currentFeedback.SourceUrl != null)
            {
                txbWebsite.Text = currentFeedback.SourceUrl.ToString();
            }

            txbTitle.Text = currentFeedback.Title;

            richTextEditor.Text = currentFeedback.Body;
        }

        private void SetConfirmation()
        {
            var confirmPage = (ConfirmationPage)Page;
            confirmPage.IsInEdit = true;
            confirmPage.Message = "You will lose any unsaved content";

            lkbPost.Attributes.Add("OnClick", BypassFunctionName);
        }

        private void UpdateFeedback()
        {
            Uri feedbackWebsite = null;
            valtxbWebsite.IsValid = !(txbWebsite.Text.Length > 0) || Uri.TryCreate(txbWebsite.Text, UriKind.RelativeOrAbsolute, out feedbackWebsite);

            if(Page.IsValid)
            {
                FeedbackItem updatedFeedback = FeedbackItem.Get(FeedbackId);
                updatedFeedback.Title = txbTitle.Text;
                updatedFeedback.Body = richTextEditor.Text;
                if(feedbackWebsite != null)
                {
                    updatedFeedback.SourceUrl = feedbackWebsite;
                }
                FeedbackItem.Update(updatedFeedback);
                Cacher.InvalidateFeedback(updatedFeedback.Entry, SubtextContext);
                if(ReturnToOriginalPost)
                {
                    Response.Redirect(Url.FeedbackUrl(updatedFeedback));
                    return;
                }

                
                Messages.ShowMessage(Constants.RES_SUCCESSEDIT, false);
            }
        }

        protected void lkbPost_Click(object sender, EventArgs e)
        {
            UpdateFeedback();
        }
    }
}
{'fraction_non_alphanumeric': 0.07585481325618096, 'fraction_numerical': 0.0022093634928984744, 'mean_word_length': 1.22883939038687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146051', 'n_tokens_mistral': 2464, 'n_tokens_neox': 2201, 'n_words': 393}