Ejemplo n.º 1
0
        /// <summary>
        /// Prints the HTML head tag.
        /// </summary>
        public void PrintHtmlHead()
        {
            StringBuilder sb = new StringBuilder(100);

            if (Settings.GetRssFeedsMode(currentWiki) != RssFeedsMode.Disabled)
            {
                sb.AppendFormat(@"<link rel=""alternate"" title=""{0}"" href=""{1}######______NAMESPACE______######RSS.aspx"" type=""application/rss+xml"" />",
                                Settings.GetWikiTitle(currentWiki), Settings.GetMainUrl(currentWiki));
                sb.Append("\n");
                sb.AppendFormat(@"<link rel=""alternate"" title=""{0}"" href=""{1}######______NAMESPACE______######RSS.aspx?Discuss=1"" type=""application/rss+xml"" />",
                                Settings.GetWikiTitle(currentWiki) + " - Discussions", Settings.GetMainUrl(currentWiki));
                sb.Append("\n");
            }

            sb.Append("######______INCLUDES______######");

            sb.AppendLine(Host.Instance.GetAllHtmlHeadContent(currentWiki));

            // Use a Control to allow 3rd party plugins to programmatically access the Page header
            string nspace = currentNamespace;

            if (nspace == null)
            {
                nspace = "";
            }
            else if (nspace.Length > 0)
            {
                nspace += ".";
            }

            Literal c = new Literal();

            c.Text = sb.ToString().Replace("######______INCLUDES______######", Tools.GetIncludes(currentWiki, currentNamespace)).Replace("######______NAMESPACE______######", nspace);
            Page.Header.Controls.Add(c);
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentWiki = Tools.DetectCurrentWiki();

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

            string mainUrl     = Settings.GetMainUrl(currentWiki);
            string rootDefault = Settings.GetDefaultPage(currentWiki).ToLowerInvariant();

            using (XmlWriter writer = XmlWriter.Create(Response.OutputStream)) {
                writer.WriteStartDocument();

                writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");
                writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
                writer.WriteAttributeString("xsi", "schemaLocation", null, "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd");

                string   user   = SessionFacade.GetCurrentUsername();
                string[] groups = SessionFacade.GetCurrentGroupNames(currentWiki);


                AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

                foreach (PageContent page in Pages.GetPages(currentWiki, null))
                {
                    if (authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ReadPage, user, groups))
                    {
                        WritePage(mainUrl, page.FullName, page.FullName.ToLowerInvariant() == rootDefault, writer);
                    }
                }
                foreach (NamespaceInfo nspace in Pages.GetNamespaces(currentWiki))
                {
                    string nspaceDefault = nspace.DefaultPageFullName.ToLowerInvariant();

                    foreach (PageContent page in Pages.GetPages(currentWiki, nspace))
                    {
                        if (authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ReadPage, user, groups))
                        {
                            WritePage(mainUrl, page.FullName, page.FullName.ToLowerInvariant() == nspaceDefault, writer);
                        }
                    }
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Notifies an error to the email addresses set in the configuration, swallowing all exceptions.
        /// </summary>
        /// <param name="ex">The exception to notify.</param>
        /// <param name="url">The URL that caused the error, if any.</param>
        public static void NotifyError(Exception ex, string url)
        {
            try {
                string[] recipients = GlobalSettings.ErrorsEmails;

                if (recipients.Length > 0)
                {
                    AsyncSendMassEmail(recipients, GlobalSettings.SenderEmail, "Error Notification", "An error occurred on " +
                                       DateTime.Now.ToString("yyyy'/'MM'/'dd' 'HH':'mm':'ss") + " (server time) in the wiki hosted at " +
                                       Settings.GetMainUrl(Tools.DetectCurrentWiki()) + " - server stack trace follows.\r\n\r\n" +
                                       (!string.IsNullOrEmpty(url) ? url + "\r\n\r\n" : "") +
                                       ex.ToString(), false);
                }
            }
            catch { }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Automatically replaces the host and port in the URL with those obtained from <see cref="Settings.GetMainUrl"/>.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns>The URL with fixed host and port.</returns>
        public static Uri FixHost(this Uri url)
        {
            // Make sure the host is replaced only once
            var originalUrl  = url.ToString();
            var originalHost = url.GetComponents(UriComponents.HostAndPort, UriFormat.Unescaped);
            Uri mainUrl      = Settings.GetMainUrl();
            var newHost      = mainUrl.GetComponents(UriComponents.HostAndPort, UriFormat.Unescaped);

            originalHost = CleanupPort(originalUrl, originalHost);
            newHost      = CleanupPort(mainUrl.ToString(), newHost);

            var hostIndex = originalUrl.IndexOf(originalHost);
            var newUrl    = originalUrl.Substring(0, hostIndex) + newHost + originalUrl.Substring(hostIndex + originalHost.Length);

            return(new Uri(newUrl));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the canonical URL tag for a page.
        /// </summary>
        /// <param name="requestUrl">The request URL.</param>
        /// <param name="currentPage">The current page.</param>
        /// <param name="nspace">The namespace.</param>
        /// <returns>The canonical URL, or an empty string if <paramref name="requestUrl"/> is already canonical.</returns>
        public static string GetCanonicalUrlTag(string requestUrl, PageInfo currentPage, NamespaceInfo nspace)
        {
            string url = "";

            if (nspace == null && currentPage.FullName == Settings.DefaultPage)
            {
                url = Settings.GetMainUrl( ).ToString( );
            }
            else
            {
                url = Settings.GetMainUrl( ).ToString( ).TrimEnd('/') + "/" + currentPage.FullName + Settings.PageExtension;
            }

            // Case sensitive
            if (url == requestUrl)
            {
                return("");
            }
            return("<link rel=\"canonical\" href=\"" + url + "\" />");
        }
Ejemplo n.º 6
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (!Settings.UsersCanRegister(currentWiki))
            {
                return;
            }

            lblResult.Text     = "";
            lblResult.CssClass = "";

            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            // Ready to save the user
            Log.LogEntry("Account creation requested for " + txtUsername.Text, EntryType.General, Log.SystemUsername, currentWiki);
            Users.AddUser(currentWiki, txtUsername.Text, txtDisplayName.Text, txtPassword1.Text, txtEmail1.Text,
                          Settings.GetAccountActivationMode(currentWiki) == AccountActivationMode.Auto, null);

            UserInfo newUser = Users.FindUser(currentWiki, txtUsername.Text);

            // Set membership to default Users group
            Users.SetUserMembership(newUser, new string[] { Settings.GetUsersGroup(currentWiki) });

            if (Settings.GetAccountActivationMode(currentWiki) == AccountActivationMode.Email)
            {
                string body = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.AccountActivationMessage, null);
                body = body.Replace("##WIKITITLE##", Settings.GetWikiTitle(currentWiki)).Replace("##USERNAME##", newUser.Username).Replace("##EMAILADDRESS##", GlobalSettings.ContactEmail);
                body = body.Replace("##ACTIVATIONLINK##", Settings.GetMainUrl(currentWiki) + "Login.aspx?Activate=" + Tools.ComputeSecurityHash(newUser.Username, newUser.Email, newUser.DateTime) + "&Username="******"Account Activation - " + Settings.GetWikiTitle(currentWiki), body, false);
            }

            lblResult.CssClass  = "resultok";
            lblResult.Text      = "<br /><br />" + Properties.Messages.AccountCreated;
            btnRegister.Enabled = false;
            pnlRegister.Visible = false;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the canonical URL tag for a page.
        /// </summary>
        /// <param name="requestUrl">The request URL.</param>
        /// <param name="currentPageFullName">The full name of the current page.</param>
        /// <param name="nspace">The namespace.</param>
        /// <returns>The canonical URL, or an empty string if <paramref name="requestUrl"/> is already canonical.</returns>
        public static string GetCanonicalUrlTag(string requestUrl, string currentPageFullName, NamespaceInfo nspace)
        {
            string url         = "";
            string currentWiki = DetectCurrentWiki();

            if (nspace == null && currentPageFullName == Settings.GetDefaultPage(currentWiki))
            {
                url = Settings.GetMainUrl(currentWiki).ToString();
            }
            else
            {
                url = Settings.GetMainUrl(currentWiki).ToString().TrimEnd('/') + "/" + currentPageFullName + GlobalSettings.PageExtension;
            }

            // Case sensitive
            if (url == requestUrl)
            {
                return("");
            }
            else
            {
                return("<link rel=\"canonical\" href=\"" + url + "\" />");
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Generates the OpenSearch description XML document and renders it to output.
        /// </summary>
        private void GenerateOpenSearchDescription()
        {
            string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<OpenSearchDescription xmlns=""http://a9.com/-/spec/opensearch/1.1/"">
	<ShortName>{0}</ShortName>
	<Description>{1}</Description>
	<Url type=""text/html"" method=""get"" template=""{2}Search.aspx?AllNamespaces=1&amp;FilesAndAttachments=1&amp;Query={3}""/>
	<Image width=""16"" height=""16"" type=""image/x-icon"">{2}{4}</Image>
	<InputEncoding>UTF-8</InputEncoding>
	<SearchForm>{2}Search.aspx</SearchForm>
</OpenSearchDescription>";

            Response.Clear();
            Response.AddHeader("content-type", "application/opensearchdescription+xml");
            Response.AddHeader("content-disposition", "inline;filename=search.xml");
            Response.Write(
                string.Format(xml,
                              Settings.GetWikiTitle(currentWiki),
                              Settings.GetWikiTitle(currentWiki) + " - Search",
                              Settings.GetMainUrl(currentWiki),
                              "{searchTerms}",
                              "Images/SearchIcon.ico"));
            Response.End();
        }
Ejemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            currentWiki = DetectWiki();

            rssFeedsMode = Settings.GetRssFeedsMode(currentWiki);
            if (rssFeedsMode == RssFeedsMode.Disabled)
            {
                Response.Clear();
                Response.StatusCode = 404;
                Response.End();
                return;
            }

            string currentUsername = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki);

            AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki));

            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(currentWiki, 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(currentWiki, currentUsername).Groups;
                        }
                    }
                    else
                    {
                        // Check for built-in admin account
                        if (Request["Username"].Equals("admin") && Request["Password"].Equals(GlobalSettings.GetMasterPassword()))
                        {
                            currentUsername = "******";
                            currentGroups   = new string[] { Settings.GetAdministratorsGroup(currentWiki) };
                        }
                    }
                }
            }

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

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

                if (Request["Discuss"] == null)
                {
                    // Check permission for the page
                    bool canReadPage = authChecker.CheckActionForPage(page.FullName, 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.GetWikiTitle(currentWiki) + " - " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(currentWiki, page.Title, false, FormattingContext.PageContent, page.FullName)),
                                         Settings.GetMainUrl(currentWiki) + page.FullName + GlobalSettings.PageExtension,
                                         Settings.GetMainUrl(currentWiki) + UrlTools.BuildUrl(currentWiki, "RSS.aspx?Page=", page.FullName),
                                         Formatter.StripHtml(page.Title) + " - " + Properties.Messages.PageUpdates);

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

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

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

                        // Write the remaining elements
                        rss.WriteElementString("author", username);
                        rss.WriteElementString("pubDate", page.LastModified.ToUniversalTime().ToString("R"));
                        rss.WriteStartElement("guid");
                        rss.WriteAttributeString("isPermaLink", "false");
                        rss.WriteString(GetGuid(page.FullName, page.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.FullName, 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.GetWikiTitle(currentWiki) + " - " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(currentWiki, page.Title, false, FormattingContext.PageContent, page.FullName)) + " - Discussion Updates",
                                         Settings.GetMainUrl(currentWiki) + page.FullName + GlobalSettings.PageExtension + "?Discuss=1",
                                         Settings.GetMainUrl(currentWiki) + UrlTools.BuildUrl(currentWiki, "RSS.aspx?Page=", page.FullName, "&Discuss=1"),
                                         Settings.GetWikiTitle(currentWiki) + " - " + Formatter.StripHtml(FormattingPipeline.PrepareTitle(currentWiki, page.Title, false, FormattingContext.PageContent, page.FullName)) + " - 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(currentWiki, messages[i].Subject, false, FormattingContext.MessageBody, page.FullName)));
                            rss.WriteEndElement();
                            rss.WriteElementString("link", Settings.GetMainUrl(currentWiki) + page.FullName + GlobalSettings.PageExtension + "?Discuss=1");

                            UserInfo user     = Users.FindUser(currentWiki, 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(currentWiki, FormattingPipeline.FormatWithPhase1And2(currentWiki, messages[i].Body, false, FormattingContext.MessageBody, page.FullName), FormattingContext.MessageBody, page.FullName));
                            }
                            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.ToString(), 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.GetWikiTitle(currentWiki) + " - " + Properties.Messages.PageUpdates,
                                         Settings.GetMainUrl(currentWiki),
                                         Settings.GetMainUrl(currentWiki) + UrlTools.BuildUrl(currentWiki, "RSS.aspx", (useCat ? ("?Category=" + cat) : "")),
                                         Properties.Messages.RecentPageUpdates);

                        RecentChange[] ch = RecentChanges.GetAllChanges(currentWiki);
                        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;
                            }

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

                                if (useCat)
                                {
                                    CategoryInfo[] infos = Pages.GetCategoriesForPage(p);
                                    if (infos.Length == 0 && cat != "-")
                                    {
                                        continue;
                                    }
                                    else 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(currentWiki, ch[i].Title, false, FormattingContext.PageContent, p.FullName)));
                            rss.WriteEndElement();
                            if (ch[i].Change != Change.PageDeleted && p != null)
                            {
                                if (ch[i].Change != Change.PageDeleted && p != null)
                                {
                                    rss.WriteElementString("link", Settings.GetMainUrl(currentWiki) + ch[i].Page + GlobalSettings.PageExtension);
                                }
                                else
                                {
                                    rss.WriteElementString("link", Settings.GetMainUrl(currentWiki));
                                }
                            }

                            UserInfo user     = Users.FindUser(currentWiki, 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(FormattedContent.GetFormattedPageContent(currentWiki, p));
                            }
                            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.GetWikiTitle(currentWiki) + " - " + Properties.Messages.DiscussionUpdates,
                                         Settings.GetMainUrl(currentWiki),
                                         Settings.GetMainUrl(currentWiki) + UrlTools.BuildUrl(currentWiki, "RSS.aspx", (useCat ? ("?Category=" + cat) : "")),
                                         Properties.Messages.RecentDiscussionUpdates);

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

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

                                if (useCat)
                                {
                                    CategoryInfo[] infos = Pages.GetCategoriesForPage(p);
                                    if (infos.Length == 0 && cat != "-")
                                    {
                                        continue;
                                    }
                                    else 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(currentWiki, ch[i].Title, false, FormattingContext.PageContent, p.FullName)));
                                rss.WriteEndElement();

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

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

                                UserInfo user     = Users.FindUser(currentWiki, 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(currentWiki, FormattingPipeline.FormatWithPhase1And2(currentWiki, 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();
                    }
                }
            }
        }
Ejemplo n.º 10
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            lblSendResult.Text     = "";
            lblSendResult.CssClass = "";

            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            UserInfo loggedUser = SessionFacade.GetCurrentUser(currentWiki);

            Log.LogEntry("Sending Email to " + currentUser.Username, EntryType.General, loggedUser.Username, currentWiki);
            EmailTools.AsyncSendEmail(currentUser.Email,
                                      "\"" + Users.GetDisplayName(loggedUser) + "\" <" + GlobalSettings.SenderEmail + ">",
                                      txtSubject.Text,
                                      Users.GetDisplayName(loggedUser) + " sent you this message from " + Settings.GetWikiTitle(currentWiki) + ". To reply, please go to " + Settings.GetMainUrl(currentWiki) + "User.aspx?Username="******"&Subject=" + Tools.UrlEncode("Re: " + txtSubject.Text) + "\nPlease do not reply to this Email.\n\n------------\n\n" + txtBody.Text,
                                      false);
            lblSendResult.Text     = Properties.Messages.MessageSent;
            lblSendResult.CssClass = "resultok";

            txtSubject.Text = "";
            txtBody.Text    = "";
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Loads the general configuration.
 /// </summary>
 /// <param name="currentWiki">The wiki.</param>
 private void LoadGeneralConfig(string currentWiki)
 {
     txtWikiTitle.Text = Settings.GetWikiTitle(currentWiki);
     txtMainUrl.Text   = Settings.GetMainUrl(currentWiki);
 }