FormatWithPhase3() public static method

Performs the Phase 3 of the formatting process.
public static FormatWithPhase3 ( string raw, FormattingContext context, System.PageInfo current ) : string
raw string The raw WikiMarkup to format.
context FormattingContext The formatting context.
current System.PageInfo The current Page, if any.
return string
Exemplo n.º 1
0
        /// <summary>
        /// Prints the footer.
        /// </summary>
        public void PrintFooter()
        {
            string f = FormattingPipeline.FormatWithPhase1And2(currentWiki, Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.Footer, currentNamespace),
                                                               false, FormattingContext.Footer, null);

            lblFooterDiv.Text = FormattingPipeline.FormatWithPhase3(currentWiki, f, FormattingContext.Footer, null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the formatted Page Content, properly handling content caching and the Formatting Pipeline.
        /// </summary>
        /// <param name="page">The Page to get the formatted Content of.</param>
        /// <param name="cached">Specifies whether the formatted content has to be cached or not.</param>
        /// <returns>The formatted content.</returns>
        public static string GetFormattedPageContent(PageInfo page, bool cached)
        {
            var content = Cache.GetFormattedPageContent(page);

            if (content == null)
            {
                PageContent pg = GetPageContent(page, cached);

                var pcc = page.Provider.GetContentCache(page);
                if (pcc != null)
                {
                    content        = pcc.FormattedContent;
                    pg.LinkedPages = pcc.LinkedPages;
                }
                else
                {
                    content        = FormattingPipeline.FormatWithPhase1And2(pg.Content, false, FormattingContext.PageContent, page, out var linkedPages);
                    pg.LinkedPages = linkedPages;

                    if (!pg.IsEmpty() && cached && !page.NonCached && !Settings.DisableCache)
                    {
                        Cache.SetFormattedPageContent(page, content);
                        page.Provider.SetContentCache(page, content, linkedPages);
                    }
                }
            }

            return(FormattingPipeline.FormatWithPhase3(content, FormattingContext.PageContent, page));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prints a message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="parent">The parent message.</param>
        /// <param name="sb">The output <see cref="T:StringBuilder" />.</param>
        private void PrintMessage(Message message, Message parent, StringBuilder sb)
        {
            // Header
            sb.Append(@"<div class=""messageheader"">");
            sb.Append(Preferences.AlignWithTimezone(message.DateTime).ToString(Settings.DateTimeFormat));
            sb.Append(" ");
            sb.Append(Properties.Messages.By);
            sb.Append(" ");
            sb.Append(Users.UserLink(message.Username));

            // Subject
            if (message.Subject.Length > 0)
            {
                sb.Append(@"<br /><span class=""messagesubject"">");
                sb.Append(FormattingPipeline.PrepareTitle(message.Subject, false, FormattingContext.MessageBody, page));
                sb.Append("</span>");
            }

            sb.Append("</div>");

            // Body
            sb.Append(@"<div class=""messagebody"">");
            sb.Append(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(message.Body, false, FormattingContext.MessageBody, page),
                                                          FormattingContext.MessageBody, page));
            sb.Append("</div>");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Prints the header.
        /// </summary>
        public void PrintHeader()
        {
            string h = FormattingPipeline.FormatWithPhase1And2(currentWiki, Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.Header, currentNamespace),
                                                               false, FormattingContext.Header, currentPageFullName);

            lblHeaderDiv.Text = FormattingPipeline.FormatWithPhase3(currentWiki, h, FormattingContext.Header, currentPageFullName);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Prints the header.
        /// </summary>
        public void PrintHeader()
        {
            string h = FormattingPipeline.FormatWithPhase1And2(currentWiki, "{wikititle}",
                                                               false, FormattingContext.Header, null);

            lblHeaderDivClean.Text = "<h1>" + FormattingPipeline.FormatWithPhase3(currentWiki, h, FormattingContext.Header, null) + "</h1>";
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the formatted Page Content, properly handling content caching and the Formatting Pipeline.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="page">The Page to get the formatted Content of.</param>
        /// <returns>The formatted content.</returns>
        public static string GetFormattedPageContent(string wiki, PageContent page)
        {
            string[] linkedPages;
            string   content = FormattingPipeline.FormatWithPhase1And2(wiki, page.Content, false, FormattingContext.PageContent, page.FullName, out linkedPages);

            page.LinkedPages = linkedPages;
            return(FormattingPipeline.FormatWithPhase3(wiki, content, FormattingContext.PageContent, page.FullName));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Prints the sidebar.
        /// </summary>
        public void PrintSidebar()
        {
            string s = Content.GetPseudoCacheValue(GetPseudoCacheItemName("Sidebar"));

            if (s == null)
            {
                s = FormattingPipeline.FormatWithPhase1And2(GetMetadataItemWithFallback(MetaDataItem.Sidebar, currentNamespace),
                                                            false, FormattingContext.Sidebar, currentPage);
                Content.SetPseudoCacheValue(GetPseudoCacheItemName("Sidebar"), s);
            }
            lblSidebarDiv.Text = FormattingPipeline.FormatWithPhase3(s, FormattingContext.Sidebar, currentPage);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Prints the header.
        /// </summary>
        public void PrintHeader()
        {
            string h = Content.GetPseudoCacheValue(GetPseudoCacheItemName("Header"));

            if (h == null)
            {
                h = FormattingPipeline.FormatWithPhase1And2(GetMetadataItemWithFallback(MetaDataItem.Header, currentNamespace),
                                                            false, FormattingContext.Header, currentPage);
                Content.SetPseudoCacheValue(GetPseudoCacheItemName("Header"), h);
            }
            lblHeaderDiv.Text = FormattingPipeline.FormatWithPhase3(h, FormattingContext.Header, currentPage);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Prints the footer.
        /// </summary>
        public void PrintFooter()
        {
            string f = Content.GetPseudoCacheValue(GetPseudoCacheItemName("Footer"));

            if (f == null)
            {
                f = FormattingPipeline.FormatWithPhase1And2(GetMetadataItemWithFallback(MetaDataItem.Footer, currentNamespace),
                                                            false, FormattingContext.Footer, currentPage);
                Content.SetPseudoCacheValue(GetPseudoCacheItemName("Footer"), f);
            }
            lblFooterDiv.Text = FormattingPipeline.FormatWithPhase3(f, FormattingContext.Footer, currentPage);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Prints the page header and page footer.
        /// </summary>
        public void PrintPageHeaderAndFooter()
        {
            string h = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.PageHeader, currentNamespace);

            h = @"<div id=""PageInternalHeaderDiv"">" + FormattingPipeline.FormatWithPhase1And2(currentWiki, h, false, FormattingContext.PageHeader, currentPageFullName) + "</div>";

            lblPageHeaderDiv.Text = FormattingPipeline.FormatWithPhase3(currentWiki, h, FormattingContext.PageHeader, currentPageFullName);

            h = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.PageFooter, currentNamespace);
            h = @"<div id=""PageInternalFooterDiv"">" + FormattingPipeline.FormatWithPhase1And2(currentWiki, h, false, FormattingContext.PageFooter, currentPageFullName) + "</div>";

            lblPageFooterDiv.Text = FormattingPipeline.FormatWithPhase3(currentWiki, h, FormattingContext.PageFooter, currentPageFullName);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Prints the register notice.
        /// </summary>
        private void PrintRegisterNotice()
        {
            string n = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.RegisterNotice, null);

            if (!string.IsNullOrEmpty(n))
            {
                n = FormattingPipeline.FormatWithPhase1And2(currentWiki, n, false, FormattingContext.Other, null);
            }
            if (!string.IsNullOrEmpty(n))
            {
                lblRegisterDescription.Text = FormattingPipeline.FormatWithPhase3(currentWiki, n, FormattingContext.Other, null);
            }
        }
Exemplo n.º 12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request["Text"] != null)
     {
         // Context should be available by parsing the UrlReferrer, which
         // might not be available depending on the browser (this page is invoked via XmlHttpRequest)
         Response.Write(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(Request["Text"],
                                                                                                    false, ScrewTurn.Wiki.PluginFramework.FormattingContext.Unknown, null), ScrewTurn.Wiki.PluginFramework.FormattingContext.Unknown, null));
         //Response.Write(Formatter.Format(Request["Text"], null));
     }
     else
     {
         Response.Write("No input text.");
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the formatted Page Content, properly handling content caching and the Formatting Pipeline.
        /// </summary>
        /// <param name="page">The Page to get the formatted Content of.</param>
        /// <param name="cached">Specifies whether the formatted content has to be cached or not.</param>
        /// <returns>The formatted content.</returns>
        public static string GetFormattedPageContent(PageInfo page, bool cached)
        {
            string content = Cache.GetFormattedPageContent(page);

            if (content == null)
            {
                PageContent pg = GetPageContent(page, cached);
                string[]    linkedPages;
                content        = FormattingPipeline.FormatWithPhase1And2(pg.Content, false, FormattingContext.PageContent, page, out linkedPages);
                pg.LinkedPages = linkedPages;
                if (!pg.IsEmpty() && cached && !page.NonCached && !Settings.DisableCache)
                {
                    Cache.SetFormattedPageContent(page, content);
                }
            }
            return(FormattingPipeline.FormatWithPhase3(content, FormattingContext.PageContent, page));
        }
Exemplo n.º 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentWiki = DetectWiki();

            Page.Title = Properties.Messages.AccessDeniedTitle + " - " + Settings.GetWikiTitle(currentWiki);

            string n = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.AccessDeniedNotice, null);

            if (!string.IsNullOrEmpty(n))
            {
                n = FormattingPipeline.FormatWithPhase1And2(currentWiki, n, false, FormattingContext.Other, null);
            }
            if (!string.IsNullOrEmpty(n))
            {
                lblDescription.Text = FormattingPipeline.FormatWithPhase3(currentWiki, n, FormattingContext.Other, null);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Prints the login notice.
        /// </summary>
        public void PrintLoginNotice()
        {
            string n = Content.GetPseudoCacheValue("LoginNotice");

            if (n == null)
            {
                n = Settings.Provider.GetMetaDataItem(MetaDataItem.LoginNotice, null);
                if (!string.IsNullOrEmpty(n))
                {
                    n = FormattingPipeline.FormatWithPhase1And2(n, false, FormattingContext.Other, null);
                    Content.SetPseudoCacheValue("LoginNotice", n);
                }
            }
            if (!string.IsNullOrEmpty(n))
            {
                lblDescription.Text = FormattingPipeline.FormatWithPhase3(n, FormattingContext.Other, null);
            }
        }
Exemplo n.º 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = Properties.Messages.AccessDeniedTitle + " - " + Settings.WikiTitle;

            string n = Content.GetPseudoCacheValue("AccessDeniedNotice");

            if (n == null)
            {
                n = Settings.Provider.GetMetaDataItem(MetaDataItem.AccessDeniedNotice, null);
                if (!string.IsNullOrEmpty(n))
                {
                    n = FormattingPipeline.FormatWithPhase1And2(n, false, FormattingContext.Other, null);
                    Content.SetPseudoCacheValue("AccessDeniedNotice", n);
                }
            }
            if (!string.IsNullOrEmpty(n))
            {
                lblDescription.Text = FormattingPipeline.FormatWithPhase3(n, FormattingContext.Other, null);
            }
        }
Exemplo n.º 17
0
        protected void btnPreview_Click(object sender, EventArgs e)
        {
            SelectTab(2);

            //added for WYSIWYG
            //if last view was WYSIWYG take text from WYSIWYG to Preview
            //in both cases I need to synchronize WYSIWYG and Markup view
            if (inWYSIWYG)
            {
                lblPreview.Text = lblWYSIWYG.Text.Replace("&lt;", "<").Replace("&gt;", ">");
                txtMarkup.Text  = ReverseFormatter.ReverseFormat(lblWYSIWYG.Text);
            }
            else
            {
                lblPreview.Text = FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(txtMarkup.Text, false, FormattingContext.Unknown, null), FormattingContext.Unknown, null);
                //lblWYSIWYG.Text = lblPreview.Text;
                lblWYSIWYG.Text = Formatter.Format(txtMarkup.Text, false, FormattingContext.Unknown, null, out var links, true);
            }
            //end
        }
Exemplo n.º 18
0
        /// <summary>
        /// Prints the page header and page footer.
        /// </summary>
        public void PrintPageHeaderAndFooter()
        {
            string h = Content.GetPseudoCacheValue(GetPseudoCacheItemName("PageHeader"));

            if (h == null)
            {
                h = GetMetadataItemWithFallback(MetaDataItem.PageHeader, currentNamespace);
                h = @"<div id=""PageInternalHeaderDiv"">" + FormattingPipeline.FormatWithPhase1And2(h, false, FormattingContext.PageHeader, currentPage) + "</div>";
                Content.SetPseudoCacheValue(GetPseudoCacheItemName("PageHeader"), h);
            }
            lblPageHeaderDiv.Text = FormattingPipeline.FormatWithPhase3(h, FormattingContext.PageHeader, currentPage);

            h = Content.GetPseudoCacheValue(GetPseudoCacheItemName("PageFooter"));
            if (h == null)
            {
                h = GetMetadataItemWithFallback(MetaDataItem.PageFooter, currentNamespace);
                h = @"<div id=""PageInternalFooterDiv"">" + FormattingPipeline.FormatWithPhase1And2(h, false, FormattingContext.PageFooter, currentPage) + "</div>";
                Content.SetPseudoCacheValue(GetPseudoCacheItemName("PageFooter"), h);
            }
            lblPageFooterDiv.Text = FormattingPipeline.FormatWithPhase3(h, FormattingContext.PageFooter, currentPage);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Loads the draft information, if any.
        /// </summary>
        /// <param name="currentPage">The current page name.</param>
        private void LoadDraft(string currentPage)
        {
            PageInfo    page  = Pages.FindPage(currentPage);
            PageContent draft = Pages.GetDraft(page);

            if (draft != null)
            {
                pnlApproveRevision.Visible = true;
                lblDateTime.Text           = Preferences.AlignWithTimezone(draft.LastModified).ToString(Settings.DateTimeFormat);
                lblUser.Text = Users.UserLink(draft.User, true);

                // Ampersands are escaped automatically
                lnkEdit.NavigateUrl  = "Edit.aspx?Page=" + Tools.UrlEncode(currentPage);
                lnkDiff.NavigateUrl  = "Diff.aspx?Page=" + Tools.UrlEncode(currentPage) + "&Rev1=Current&Rev2=Draft";
                lblDraftPreview.Text = FormattingPipeline.FormatWithPhase3(
                    FormattingPipeline.FormatWithPhase1And2(draft.Content, false, FormattingContext.PageContent, page), FormattingContext.PageContent, page);
            }
            else
            {
                pnlApproveRevision.Visible = false;
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Prepares the message deletion GUI.
        /// </summary>
        private void PrepareDeleteMessage()
        {
            string ms = Request["Message"];
            string pg = Request["Page"];

            if (ms == null || ms.Length == 0 || pg == null || pg.Length == 0)
            {
                UrlTools.RedirectHome();
            }

            PageInfo page = Pages.FindPage(pg);

            if (page == null)
            {
                UrlTools.RedirectHome();
            }

            if (page.Provider.ReadOnly)
            {
                UrlTools.Redirect(UrlTools.BuildUrl(page.FullName, Settings.PageExtension));
            }

            bool canManageDiscussion = AuthChecker.CheckActionForPage(page, Actions.ForPages.ManageDiscussion,
                                                                      SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames());

            if (!canManageDiscussion)
            {
                UrlTools.Redirect("AccessDenied.aspx");
            }

            int id = -1;

            try {
                id = int.Parse(ms);
            }
            catch {
                UrlTools.RedirectHome();
            }

            Message message = Pages.FindMessage(Pages.GetPageMessages(page), id);

            if (message == null)
            {
                UrlTools.RedirectHome();
            }

            StringBuilder sb = new StringBuilder(500);

            sb.Append("<b>");
            sb.Append(FormattingPipeline.PrepareTitle(message.Subject, false, FormattingContext.MessageBody, page));
            sb.Append("</b><br /><small>");
            sb.Append(Properties.Messages.Posted);
            sb.Append(" ");
            sb.Append(Preferences.AlignWithTimezone(message.DateTime).ToString(Settings.DateTimeFormat));
            sb.Append(" ");
            sb.Append(Properties.Messages.By);
            sb.Append(" ");
            sb.Append(Users.UserLink(message.Username));
            sb.Append("</small><br /><br />");
            sb.Append(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(message.Body, false, FormattingContext.MessageBody, page),
                                                          FormattingContext.MessageBody, page));

            lblDeleteMessageContent.Text = sb.ToString();
        }
Exemplo n.º 21
0
        /// <summary>
        /// Prints the history.
        /// </summary>
        public void PrintHistory()
        {
            if (page == null)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            if (Request["Revision"] == null)
            {
                // Show version list
                List <int> revisions = Pages.GetBackups(page);
                revisions.Reverse();

                List <RevisionRow> result = new List <RevisionRow>(revisions.Count + 1);

                result.Add(new RevisionRow(-1, Content.GetPageContent(page, false), false));

                foreach (int rev in revisions)
                {
                    PageContent content = Pages.GetBackupContent(page, rev);

                    result.Add(new RevisionRow(rev, content, canRollback));
                }

                rptHistory.DataSource = result;
                rptHistory.DataBind();
            }
            else
            {
                int rev = -1;
                if (!int.TryParse(Request["Revision"], out rev))
                {
                    UrlTools.Redirect(page.FullName + Settings.PageExtension);
                }

                List <int> backups = Pages.GetBackups(page);
                if (!backups.Contains(rev))
                {
                    UrlTools.Redirect(page.FullName + Settings.PageExtension);
                    return;
                }
                PageContent revision = Pages.GetBackupContent(page, rev);
                sb.Append(@"<table class=""box"" cellpadding=""0"" cellspacing=""0""><tr><td>");
                sb.Append(@"<p style=""text-align: center;""><b>");
                if (rev > 0)
                {
                    sb.Append(@"<a href=""");
                    UrlTools.BuildUrl(sb, "History.aspx?Page=", Tools.UrlEncode(page.FullName),
                                      "&amp;Revision=", Tools.GetVersionString((int)(rev - 1)));

                    sb.Append(@""">&laquo; ");
                    sb.Append(Properties.Messages.OlderRevision);
                    sb.Append("</a>");
                }
                else
                {
                    sb.Append("&laquo; ");
                    sb.Append(Properties.Messages.OlderRevision);
                }

                sb.Append(@" - <a href=""");
                UrlTools.BuildUrl(sb, "History.aspx?Page=", Tools.UrlEncode(page.FullName));
                sb.Append(@""">");
                sb.Append(Properties.Messages.BackToHistory);
                sb.Append("</a> - ");

                if (rev < backups.Count - 1)
                {
                    sb.Append(@"<a href=""");
                    UrlTools.BuildUrl(sb, "History.aspx?Page=", Tools.UrlEncode(page.FullName),
                                      "&amp;Revision=", Tools.GetVersionString((int)(rev + 1)));

                    sb.Append(@""">");
                    sb.Append(Properties.Messages.NewerRevision);
                    sb.Append(" &raquo;</a>");
                }
                else
                {
                    sb.Append(@"<a href=""");
                    UrlTools.BuildUrl(sb, Tools.UrlEncode(page.FullName), Settings.PageExtension);
                    sb.Append(@""">");
                    sb.Append(Properties.Messages.CurrentRevision);
                    sb.Append("</a>");
                }
                sb.Append("</b></p></td></tr></table><br />");

                sb.Append(@"<h3 class=""separator"">");
                sb.Append(Properties.Messages.PageRevision);
                sb.Append(": ");
                sb.Append(Preferences.AlignWithTimezone(revision.LastModified).ToString(Settings.DateTimeFormat));
                sb.Append("</h3><br />");

                sb.Append(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(revision.Content,
                                                                                                      false, FormattingContext.PageContent, page).Replace(Formatter.EditSectionPlaceHolder, ""), FormattingContext.PageContent, page));
            }

            lblHistory.Text = sb.ToString();
        }
Exemplo n.º 22
0
        /// <summary>
        /// Prints a message.
        /// </summary>
        /// <param name="message">The message to print.</param>
        /// <param name="parent">The parent message, or <c>null</c>.</param>
        /// <param name="sb">The output <see cref="T:StringBuilder" />.</param>
        private void PrintMessage(Message message, Message parent, StringBuilder sb)
        {
            // Print header
            sb.Append(@"<div class=""messageheader"">");
            //sb.AppendFormat(@"<a id=""MSG_{0}""></a>", message.ID);

            if (!currentPage.Provider.ReadOnly)
            {
                // Print reply/edit/delete buttons only if provider is not read-only
                sb.Append(@"<div class=""reply"">");

                if (canPostMessages)
                {
                    sb.Append(@"<a class=""reply"" href=""");
                    sb.Append(UrlTools.BuildUrl("Post.aspx?Page=", Tools.UrlEncode(currentPage.FullName), "&amp;Parent=", message.ID.ToString()));

                    sb.Append(@""">");
                    sb.Append(Properties.Messages.Reply);
                    sb.Append("</a>");
                }

                // If current user is the author of the message or is an admin, print the edit hyperLink
                // A message can be edited only if the user is authenticated - anonymous users cannot edit their messages
                if (SessionFacade.LoginKey != null && ((message.Username == SessionFacade.CurrentUsername && canPostMessages) || canManageDiscussion))
                {
                    sb.Append(@" <a class=""edit"" href=""");
                    sb.Append(UrlTools.BuildUrl("Post.aspx?Page=", Tools.UrlEncode(currentPage.FullName), "&amp;Edit=", message.ID.ToString()));

                    sb.Append(@""">");
                    sb.Append(Properties.Messages.Edit);
                    sb.Append("</a>");
                }

                // If the current user is an admin, print the delete hyperLink
                if (SessionFacade.LoginKey != null && canManageDiscussion)
                {
                    sb.Append(@" <a class=""delete"" href=""");
                    sb.Append(UrlTools.BuildUrl("Operation.aspx?Operation=DeleteMessage&amp;Message=", message.ID.ToString(),
                                                "&amp;Page=", Tools.UrlEncode(currentPage.FullName)));

                    sb.Append(@""">");
                    sb.Append(Properties.Messages.Delete);
                    sb.Append("</a>");
                }
                sb.Append("</div>");
            }

            sb.Append(@"<div>");
            sb.AppendFormat(@"<a id=""{0}"" href=""#{0}"" title=""Permalink"">&#0182;</a> ", Tools.GetMessageIdForAnchor(message.DateTime));

            // Print subject
            if (message.Subject.Length > 0)
            {
                sb.Append(@"<span class=""messagesubject"">");
                sb.Append(FormattingPipeline.PrepareTitle(message.Subject, false, FormattingContext.MessageBody, currentPage));
                sb.Append("</span>");
            }

            // Print message date/time
            sb.Append(@"<span class=""messagedatetime"">");
            sb.Append(Preferences.AlignWithTimezone(message.DateTime).ToString(Settings.DateTimeFormat));
            sb.Append(" ");
            sb.Append(Properties.Messages.By);
            sb.Append(" ");
            sb.Append(Users.UserLink(message.Username));
            sb.Append("</span>");

            sb.Append("</div>");

            sb.Append("</div>");

            // Print body
            sb.Append(@"<div class=""messagebody"">");
            sb.Append(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(message.Body, false, FormattingContext.MessageBody, currentPage),
                                                          FormattingContext.MessageBody, currentPage));
            sb.Append("</div>");
        }
Exemplo n.º 23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            rssFeedsMode = Settings.RssFeedsMode;
            if (rssFeedsMode == RssFeedsMode.Disabled)
            {
                Response.Clear();
                Response.StatusCode = 404;
                Response.End();
                return;
            }

            string currentUsername = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames();

            currentNamespace = DetectNamespace();
            if (string.IsNullOrEmpty(currentNamespace))
            {
                currentNamespace = null;
            }

            if (SessionFacade.LoginKey == null)
            {
                // Look for username/password in the query string
                if (Request["Username"] != null && Request["Password"] != null)
                {
                    // Try to authenticate
                    UserInfo u = Users.FindUser(Request["Username"]);
                    if (u != null)
                    {
                        // Very "dirty" way - pages should not access Providers
                        if (u.Provider.TestAccount(u, Request["Password"]))
                        {
                            // Valid account
                            currentUsername = Request["Username"];
                            currentGroups   = Users.FindUser(currentUsername).Groups;
                        }
                    }
                    else
                    {
                        // Check for built-in admin account
                        if (Request["Username"].Equals("admin") && Request["Password"].Equals(Settings.MasterPassword))
                        {
                            currentUsername = "******";
                            currentGroups   = new string[] { Settings.AdministratorsGroup };
                        }
                    }
                }
            }

            Response.ClearContent();
            Response.ContentType     = "text/xml;charset=UTF-8";
            Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;

            if (Request["Page"] != null)
            {
                PageInfo page = Pages.FindPage(Request["Page"]);
                if (page == null)
                {
                    return;
                }

                PageContent content = Content.GetPageContent(page, true);
                if (Request["Discuss"] == null)
                {
                    // Check permission for the page
                    bool canReadPage = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadPage, currentUsername, currentGroups);
                    if (!canReadPage)
                    {
                        Response.StatusCode = 401;
                        return;
                    }

                    // Start an XML writer for the output stream
                    using (XmlWriter rss = XmlWriter.Create(Response.OutputStream)) {
                        // Build an RSS header
                        BuildRssHeader(rss);

                        // Build the channel element
                        BuildChannelHead(rss, Settings.WikiTitle + " - " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page)),
                                         Settings.MainUrl + page.FullName + Settings.PageExtension,
                                         Settings.MainUrl + UrlTools.BuildUrl("RSS.aspx?Page=", page.FullName),
                                         Formatter.StripHtml(content.Title) + " - " + Properties.Messages.PageUpdates);

                        // Write the item element
                        rss.WriteStartElement("item");
                        rss.WriteStartElement("title");
                        rss.WriteCData(Formatter.StripHtml(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page)));
                        rss.WriteEndElement();
                        rss.WriteElementString("link", Settings.MainUrl + page.FullName + Settings.PageExtension);

                        UserInfo user     = Users.FindUser(content.User);
                        string   username = user != null?Users.GetDisplayName(user) : content.User;

                        // Create the description tag
                        rss.WriteStartElement("description");
                        if (rssFeedsMode == RssFeedsMode.Summary)
                        {
                            rss.WriteCData(Formatter.StripHtml(content.Title) + ": " + Properties.Messages.ThePageHasBeenUpdatedBy + " " +
                                           username + (content.Comment.Length > 0 ? ".<br />" + content.Comment : "."));
                        }
                        else
                        {
                            rss.WriteCData(Content.GetFormattedPageContent(page, false));
                        }
                        rss.WriteEndElement();

                        // Write the remaining elements
                        rss.WriteElementString("author", username);
                        rss.WriteElementString("pubDate", content.LastModified.ToUniversalTime().ToString("R"));
                        rss.WriteStartElement("guid");
                        rss.WriteAttributeString("isPermaLink", "false");
                        rss.WriteString(GetGuid(page.FullName, content.LastModified));
                        rss.WriteEndElement();

                        // Complete the item element
                        CompleteCurrentElement(rss);

                        // Complete the channel element
                        CompleteCurrentElement(rss);

                        // Complete the rss element
                        CompleteCurrentElement(rss);

                        // Finish off
                        rss.Flush();
                        rss.Close();
                    }
                }
                else
                {
                    // Check permission for the discussion
                    bool canReadDiscussion = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadDiscussion, currentUsername, currentGroups);
                    if (!canReadDiscussion)
                    {
                        Response.StatusCode = 401;
                        return;
                    }

                    List <Message> messages = new List <Message>(Pages.GetPageMessages(page));
                    // Un-tree Messages
                    messages = UnTreeMessages(messages);
                    // Sort from newer to older
                    messages.Sort(new MessageDateTimeComparer(true));

                    // Start an XML writer for the output stream
                    using (XmlWriter rss = XmlWriter.Create(Response.OutputStream)) {
                        // Build an RSS header
                        BuildRssHeader(rss);

                        // Build the channel element
                        BuildChannelHead(rss, Settings.WikiTitle + " - " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page)) + " - Discussion Updates",
                                         Settings.MainUrl + page.FullName + Settings.PageExtension + "?Discuss=1",
                                         Settings.MainUrl + UrlTools.BuildUrl("RSS.aspx?Page=", page.FullName, "&Discuss=1"),
                                         Settings.WikiTitle + " - " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page)) + " - Discussion Updates");

                        for (int i = 0; i < messages.Count; i++)
                        {
                            // Write the item element
                            rss.WriteStartElement("item");
                            rss.WriteStartElement("title");
                            rss.WriteCData(Formatter.StripHtml(FormattingPipeline.PrepareTitle(messages[i].Subject, false, FormattingContext.MessageBody, page)));
                            rss.WriteEndElement();
                            rss.WriteElementString("link", Settings.MainUrl + page.FullName + Settings.PageExtension + "?Discuss=1");

                            UserInfo user     = Users.FindUser(messages[i].Username);
                            string   username = user != null?Users.GetDisplayName(user) : messages[i].Username;

                            // Create the description tag
                            rss.WriteStartElement("description");
                            if (rssFeedsMode == RssFeedsMode.Summary)
                            {
                                rss.WriteCData(Properties.Messages.AMessageHasBeenPostedBy.Replace("##SUBJECT##", messages[i].Subject) + " " + username + ".");
                            }
                            else
                            {
                                rss.WriteCData(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(messages[i].Body, false, FormattingContext.MessageBody, page), FormattingContext.MessageBody, page));
                            }
                            rss.WriteEndElement();

                            // Write the remaining elements
                            rss.WriteElementString("author", username);
                            rss.WriteElementString("pubDate", messages[i].DateTime.ToUniversalTime().ToString("R"));
                            rss.WriteStartElement("guid");
                            rss.WriteAttributeString("isPermaLink", "false");
                            rss.WriteString(GetGuid(page.FullName + "-" + messages[i].ID, messages[i].DateTime));
                            rss.WriteEndElement();

                            // Complete the item element
                            CompleteCurrentElement(rss);
                        }

                        // Complete the channel element
                        CompleteCurrentElement(rss);

                        // Complete the rss element
                        CompleteCurrentElement(rss);

                        // Finish off
                        rss.Flush();
                        rss.Close();
                    }
                }
            }
            else
            {
                if (Request["Discuss"] == null)
                {
                    // All page updates

                    // Start an XML writer for the output stream
                    using (XmlWriter rss = XmlWriter.Create(Response.OutputStream)) {
                        // Build an RSS header
                        BuildRssHeader(rss);

                        bool   useCat = false;
                        string cat    = "";
                        if (Request["Category"] != null)
                        {
                            useCat = true;
                            cat    = Request["Category"];
                        }

                        // Build the channel element
                        BuildChannelHead(rss, Settings.WikiTitle + " - " + Properties.Messages.PageUpdates,
                                         Settings.MainUrl,
                                         Settings.MainUrl + UrlTools.BuildUrl("RSS.aspx", (useCat ? ("?Category=" + cat) : "")),
                                         Properties.Messages.RecentPageUpdates);

                        RecentChange[] ch = RecentChanges.GetAllChanges();
                        Array.Reverse(ch);
                        for (int i = 0; i < ch.Length; i++)
                        {
                            // Suppress this entry if we've already reported this page (so we don't create duplicate entries in the feed page)
                            bool duplicateFound = false;
                            for (int j = 0; j < i; j++)
                            {
                                if (ch[j].Page == ch[i].Page)
                                {
                                    duplicateFound = true;
                                    break;
                                }
                            }
                            if (duplicateFound)
                            {
                                continue;
                            }

                            // Skip message-related entries
                            if (!IsPageChange(ch[i].Change))
                            {
                                continue;
                            }

                            PageInfo p = Pages.FindPage(ch[i].Page);
                            if (p != null)
                            {
                                // Check permissions for every page
                                bool canReadThisPage = AuthChecker.CheckActionForPage(p, Actions.ForPages.ReadPage, currentUsername, currentGroups);
                                if (!canReadThisPage)
                                {
                                    continue;
                                }

                                if (useCat)
                                {
                                    CategoryInfo[] infos = Pages.GetCategoriesForPage(p);
                                    if (infos.Length == 0 && cat != "-")
                                    {
                                        continue;
                                    }
                                    if (infos.Length != 0)
                                    {
                                        bool found = false;
                                        for (int k = 0; k < infos.Length; k++)
                                        {
                                            if (infos[k].FullName == cat)
                                            {
                                                found = true;
                                                break;
                                            }
                                        }
                                        if (!found)
                                        {
                                            continue;
                                        }
                                    }
                                }
                            }

                            // Check namespace
                            if (p != null && NameTools.GetNamespace(p.FullName) != currentNamespace)
                            {
                                continue;
                            }

                            // Skip deleted pages as their category binding is unknown
                            if (p == null && useCat)
                            {
                                continue;
                            }

                            // Write the item element
                            rss.WriteStartElement("item");
                            rss.WriteStartElement("title");
                            rss.WriteCData(Formatter.StripHtml(FormattingPipeline.PrepareTitle(ch[i].Title, false, FormattingContext.PageContent, p)));
                            rss.WriteEndElement();

                            if (ch[i].Change != Change.PageDeleted && p != null)
                            {
                                rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension);
                            }
                            else
                            {
                                rss.WriteElementString("link", Settings.MainUrl);
                            }

                            UserInfo user     = Users.FindUser(ch[i].User);
                            string   username = user != null?Users.GetDisplayName(user) : ch[i].User;

                            rss.WriteElementString("author", username);

                            // Create the description tag
                            StringBuilder sb = new StringBuilder();
                            if (rssFeedsMode == RssFeedsMode.Summary || p == null)
                            {
                                switch (ch[i].Change)
                                {
                                case Change.PageUpdated:
                                    sb.Append(Properties.Messages.ThePageHasBeenUpdatedBy);
                                    break;

                                case Change.PageDeleted:
                                    sb.Append(Properties.Messages.ThePageHasBeenDeletedBy);
                                    break;

                                case Change.PageRenamed:
                                    sb.Append(Properties.Messages.ThePageHasBeenRenamedBy);
                                    break;

                                case Change.PageRolledBack:
                                    sb.Append(Properties.Messages.ThePageHasBeenRolledBackBy);
                                    break;
                                }
                                sb.Append(" " + username + (ch[i].Description.Length > 0 ? ".<br />" + ch[i].Description : "."));
                            }
                            else
                            {
                                // p != null
                                sb.Append(Content.GetFormattedPageContent(p, false));
                            }
                            rss.WriteStartElement("description");
                            rss.WriteCData(sb.ToString());
                            rss.WriteEndElement();

                            // Write the remaining elements
                            rss.WriteElementString("pubDate", ch[i].DateTime.ToUniversalTime().ToString("R"));
                            rss.WriteStartElement("guid");
                            rss.WriteAttributeString("isPermaLink", "false");
                            rss.WriteString(GetGuid(ch[i].Page, ch[i].DateTime));
                            rss.WriteEndElement();

                            // Complete the item element
                            rss.WriteEndElement();
                        }

                        // Complete the channel element
                        CompleteCurrentElement(rss);

                        // Complete the rss element
                        CompleteCurrentElement(rss);

                        // Finish off
                        rss.Flush();
                        rss.Close();
                    }
                }
                else
                {
                    // All discussion updates

                    // Start an XML writer for the output stream
                    using (XmlWriter rss = XmlWriter.Create(Response.OutputStream)) {
                        // Build an RSS header
                        BuildRssHeader(rss);

                        bool   useCat = false;
                        string cat    = "";
                        if (Request["Category"] != null)
                        {
                            useCat = true;
                            cat    = Request["Category"];
                        }

                        // Build the channel element
                        BuildChannelHead(rss, Settings.WikiTitle + " - " + Properties.Messages.DiscussionUpdates,
                                         Settings.MainUrl,
                                         Settings.MainUrl + UrlTools.BuildUrl("RSS.aspx", (useCat ? ("?Category=" + cat) : "")),
                                         Properties.Messages.RecentDiscussionUpdates);

                        RecentChange[] ch = RecentChanges.GetAllChanges();
                        Array.Reverse(ch);
                        for (int i = 0; i < ch.Length; i++)
                        {
                            // Skip page-related entries
                            if (!IsMessageChange(ch[i].Change))
                            {
                                continue;
                            }

                            PageInfo p = Pages.FindPage(ch[i].Page);
                            if (p != null)
                            {
                                // Check permissions for every page
                                bool canReadThisPageDiscussion = AuthChecker.CheckActionForPage(p, Actions.ForPages.ReadDiscussion, currentUsername, currentGroups);
                                if (!canReadThisPageDiscussion)
                                {
                                    continue;
                                }

                                if (useCat)
                                {
                                    CategoryInfo[] infos = Pages.GetCategoriesForPage(p);
                                    if (infos.Length == 0 && cat != "-")
                                    {
                                        continue;
                                    }
                                    if (infos.Length != 0)
                                    {
                                        bool found = false;
                                        for (int k = 0; k < infos.Length; k++)
                                        {
                                            if (infos[k].FullName == cat)
                                            {
                                                found = true;
                                                break;
                                            }
                                        }
                                        if (!found)
                                        {
                                            continue;
                                        }
                                    }
                                }

                                // Check namespace
                                if (NameTools.GetNamespace(p.FullName) != currentNamespace)
                                {
                                    continue;
                                }

                                // Write the item element
                                rss.WriteStartElement("item");
                                rss.WriteStartElement("title");
                                rss.WriteCData(Properties.Messages.Discussion + ": " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(ch[i].Title, false, FormattingContext.PageContent, p)));
                                rss.WriteEndElement();

                                string id = Tools.GetMessageIdForAnchor(ch[i].DateTime);
                                if (ch[i].Change != Change.MessageDeleted)
                                {
                                    rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension + "?Discuss=1#" + id);
                                }
                                else
                                {
                                    rss.WriteElementString("link", Settings.MainUrl + ch[i].Page + Settings.PageExtension + "?Discuss=1");
                                }

                                string messageContent = FindMessageContent(ch[i].Page, id);

                                UserInfo user     = Users.FindUser(ch[i].User);
                                string   username = user != null?Users.GetDisplayName(user) : ch[i].User;

                                // Create the description tag
                                StringBuilder sb = new StringBuilder();
                                if (rssFeedsMode == RssFeedsMode.Summary || messageContent == null)
                                {
                                    switch (ch[i].Change)
                                    {
                                    case Change.MessagePosted:
                                        sb.Append(Properties.Messages.AMessageHasBeenPostedBy.Replace("##SUBJECT##", ch[i].MessageSubject));
                                        break;

                                    case Change.MessageEdited:
                                        sb.Append(Properties.Messages.AMessageHasBeenEditedBy.Replace("##SUBJECT##", ch[i].MessageSubject));
                                        break;

                                    case Change.MessageDeleted:
                                        sb.Append(Properties.Messages.AMessageHasBeenDeletedBy.Replace("##SUBJECT##", ch[i].MessageSubject));
                                        break;
                                    }
                                    sb.Append(" " + username + (ch[i].Description.Length > 0 ? ".<br />" + ch[i].Description : "."));
                                }
                                else
                                {
                                    sb.Append(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(messageContent, false, FormattingContext.MessageBody, null), FormattingContext.MessageBody, null));
                                }
                                rss.WriteStartElement("description");
                                rss.WriteCData(sb.ToString());
                                rss.WriteEndElement();

                                // Write the remaining elements
                                rss.WriteElementString("author", username);
                                rss.WriteElementString("pubDate", ch[i].DateTime.ToUniversalTime().ToString("R"));
                                rss.WriteStartElement("guid");
                                rss.WriteAttributeString("isPermaLink", "false");
                                rss.WriteString(GetGuid(ch[i].Page, ch[i].DateTime));
                                rss.WriteEndElement();

                                // Complete the item element
                                rss.WriteEndElement();
                            }
                        }

                        // Complete the channel element
                        CompleteCurrentElement(rss);

                        // Complete the rss element
                        CompleteCurrentElement(rss);

                        // Finish off
                        rss.Flush();
                        rss.Close();
                    }
                }
            }
        }