GetPageContent() public static method

Reads the Content of a Page.
public static GetPageContent ( System.PageInfo pageInfo, bool cached ) : PageContent
pageInfo System.PageInfo The Page.
cached bool Specifies whether the page has to be cached or not.
return ScrewTurn.Wiki.PluginFramework.PageContent
Example #1
0
        /// <summary>
        /// Sets the redirection source page link, if appropriate.
        /// </summary>
        private void SetupRedirectionSource()
        {
            if (Request["From"] != null)
            {
                PageInfo source = Pages.FindPage(Request["From"]);

                if (source != null)
                {
                    StringBuilder sb = new StringBuilder(300);
                    sb.Append(@"<div id=""RedirectionInfoDiv"">");
                    sb.Append(Properties.Messages.RedirectedFrom);
                    sb.Append(": ");
                    sb.Append(@"<a href=""");
                    sb.Append(UrlTools.BuildUrl("++", Tools.UrlEncode(source.FullName), Settings.PageExtension, "?NoRedirect=1"));
                    sb.Append(@""">");
                    PageContent w = Content.GetPageContent(source, true);
                    sb.Append(FormattingPipeline.PrepareTitle(w.Title, false, FormattingContext.PageContent, currentPage));
                    sb.Append("</a></div>");

                    lblRedirectionSource.Text = sb.ToString();
                }
                else
                {
                    lblRedirectionSource.Visible = false;
                }
            }
            else
            {
                lblRedirectionSource.Visible = false;
            }
        }
Example #2
0
        /// <summary>
        /// Appends a breadbrumb trail element.
        /// </summary>
        /// <param name="sb">The destination <see cref="T:StringBuilder" />.</param>
        /// <param name="page">The page to append.</param>
        /// <param name="dpPrefix">The drop-down menu ID prefix.</param>
        private void AppendBreadcrumb(StringBuilder sb, PageInfo page, string dpPrefix)
        {
            PageNameComparer comp = new PageNameComparer();
            PageContent      pc   = Content.GetPageContent(page, true);

            string id = AppendBreadcrumbDropDown(sb, page, dpPrefix);

            string nspace = NameTools.GetNamespace(page.FullName);

            sb.Append("&raquo; ");
            if (comp.Compare(page, currentPage) == 0)
            {
                sb.Append("<b>");
            }

            sb.AppendFormat(@"<a href=""{0}"" title=""{1}""{2}{3}{4}>{1}</a>",
                            Tools.UrlEncode(page.FullName) + Settings.PageExtension,
                            FormattingPipeline.PrepareTitle(pc.Title, false, FormattingContext.PageContent, currentPage) + (string.IsNullOrEmpty(nspace) ? "" : (" (" + NameTools.GetNamespace(page.FullName) + ")")),
                            (id != null ? @" onmouseover=""javascript:return __ShowDropDown(event, '" + id + @"', this);""" : ""),
                            (id != null ? @" id=""lnk" + id + @"""" : ""),
                            (id != null ? @" onmouseout=""javascript:return __HideDropDown('" + id + @"');""" : ""));
            if (comp.Compare(page, currentPage) == 0)
            {
                sb.Append("</b>");
            }

            sb.Append(" ");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Title = Properties.Messages.PageIncomingLinks + " - " + Settings.WikiTitle;

            var page = Pages.FindPage(Request["Page"]);

            PageContent content;

            if (page != null)
            {
                content = Content.GetPageContent(page, true);

                lblTitle.Text = Properties.Messages.PageIncomingLinks + ": " + FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page);

                if (!AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadPage, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames()))
                {
                    UrlTools.Redirect("AccessDenied.aspx");
                    return;
                }
            }

            var incomingLinks = Pages.GetPageIncomingLinks(page);

            foreach (var link in incomingLinks)
            {
                var linkPage        = Pages.FindPage(link);
                var linkPageContent = linkPage.Provider.GetContent(linkPage);
                ulItems.InnerHtml += string.Format("<li><a href=\"{0}\">{1}</a></li>", UrlTools.BuildUrl(Tools.UrlEncode(link), Settings.PageExtension), linkPageContent.Title);
            }
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = Properties.Messages.HistoryTitle + " - " + Settings.WikiTitle;

            page = Pages.FindPage(Request["Page"]);

            if (page != null)
            {
                canRollback = AuthChecker.CheckActionForPage(page, Actions.ForPages.ManagePage,
                                                             SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames());

                content       = Content.GetPageContent(page, true);
                lblTitle.Text = Properties.Messages.PageHistory + ": " + FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page);

                bool canView = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadPage,
                                                              SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames());
                if (!canView)
                {
                    UrlTools.Redirect("AccessDenied.aspx");
                }
            }
            else
            {
                lblTitle.Text = Properties.Messages.PageNotFound;
                return;
            }

            if (!Page.IsPostBack && page != null)
            {
                List <int> revisions = Pages.GetBackups(page);
                revisions.Reverse();
                // Populate dropdown lists
                lstRev1.Items.Clear();
                lstRev2.Items.Clear();
                lstRev2.Items.Add(new ListItem(Properties.Messages.Current, "Current"));
                if (Request["Rev2"] != null && Request["Rev2"].Equals(lstRev2.Items[0].Value))
                {
                    lstRev2.SelectedIndex = 0;
                }
                for (int i = 0; i < revisions.Count; i++)
                {
                    lstRev1.Items.Add(new ListItem(revisions[i].ToString(), revisions[i].ToString()));
                    lstRev2.Items.Add(new ListItem(revisions[i].ToString(), revisions[i].ToString()));
                    if (Request["Rev1"] != null && Request["Rev1"].Equals(lstRev1.Items[i].Value))
                    {
                        lstRev1.SelectedIndex = i;
                    }
                    if (Request["Rev2"] != null && Request["Rev2"].Equals(lstRev2.Items[i + 1].Value))
                    {
                        lstRev2.SelectedIndex = i + 1;
                    }
                }
                if (revisions.Count == 0)
                {
                    btnCompare.Enabled = false;
                }
            }

            PrintHistory();
        }
        protected List <TreeElement> ctPages_Populate(object sender, PopulateEventArgs e)
        {
            List <TreeElement> result = new List <TreeElement>(100);

            NamespaceInfo selectedNamespace = Pages.FindNamespace(lstNamespace.SelectedValue);
            NamespaceInfo currentNamespace  = DetectNamespaceInfo();

            foreach (PageInfo pi in Pages.GetPages(selectedNamespace))
            {
                PageContent cont              = Content.GetPageContent(pi, true);
                string      formattedTitle    = FormattingPipeline.PrepareTitle(cont.Title, false, FormattingContext.Other, pi);
                string      onClickJavascript = "javascript:";
                // Populate the page title box if the title is different to the page name
                if (pi.FullName != cont.Title)
                {
                    // Supply the page title to the Javascript that sets the page title on the page
                    // We can safely escape the \ character, but the " character is interpreted by the browser even if it is escaped to Javascript, so we can't allow it.
                    // The non-wysiwyg version escapes ' and replaces " with escaped ', but ' breaks the html insertion, so remove it altogether
                    // Similarly, < on it's own is fine, but causes problems when combined with text and > to form a tag.  Safest to remove < characters to prevent
                    // breaking the drop-down.
                    onClickJavascript += "SetValue('txtPageTitle', '" + cont.Title.Replace("\\", "\\\\").Replace("'", "").Replace("\"", "").Replace("<", "") + "');";
                }
                else
                {
                    onClickJavascript += "SetValue('txtPageTitle', '');";
                }
                // Populate the page name (#468: add ++ to all ReverseFormatter to work)
                onClickJavascript += "return SetValue('txtPageName', '" + (selectedNamespace != currentNamespace ? "++" : "") + pi.FullName + "');";
                TreeElement item = new TreeElement((selectedNamespace != currentNamespace ? "++" : "") + pi.FullName, formattedTitle, onClickJavascript);
                result.Add(item);
            }
            return(result);
        }
Example #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            page = Pages.FindPage(Request["Page"]);
            if (page == null)
            {
                UrlTools.RedirectHome();
            }

            // Check permissions
            bool canView = false;

            if (Request["Discuss"] == null)
            {
                canView = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadPage,
                                                         SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames());
            }
            else
            {
                canView = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadDiscussion,
                                                         SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames());
            }
            if (!canView)
            {
                UrlTools.Redirect("AccessDenied.aspx");
            }

            content = Content.GetPageContent(page, true);

            Page.Title = FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page) + " - " + Settings.WikiTitle;

            PrintContent();
        }
Example #7
0
        /// <summary>
        /// Prints the results of the automatic search.
        /// </summary>
        public void PrintSearchResults()
        {
            StringBuilder sb = new StringBuilder(1000);

            List <SearchResult> similarPages = SearchClass.Search(new SearchField[] { SearchField.PageFullName }, Request["Page"], SearchOptions.AtLeastOneWord);

            List <PageInfo> results = new List <PageInfo>();

            foreach (SearchResult page in similarPages)
            {
                if (page.DocumentType == DocumentType.Page)
                {
                    PageDocument pageDocument = page.Document as PageDocument;
                    PageInfo     pageInfo     = Pages.FindPage(pageDocument.PageFullName);
                    results.Add(pageInfo);
                }
            }
            if (results.Count > 0)
            {
                sb.Append("<p>");
                sb.Append(Properties.Messages.WereYouLookingFor);
                sb.Append("</p>");
                sb.Append("<ul>");
                PageContent c;
                for (int i = 0; i < results.Count; i++)
                {
                    c = Content.GetPageContent(results[i], true);
                    sb.Append(@"<li><a href=""");
                    UrlTools.BuildUrl(sb, Tools.UrlEncode(results[i].FullName), Settings.PageExtension);
                    sb.Append(@""">");
                    sb.Append(FormattingPipeline.PrepareTitle(c.Title, false, FormattingContext.PageContent, c.PageInfo));
                    sb.Append("</a></li>");
                }
                sb.Append("</ul>");
            }
            else
            {
                sb.Append("<p>");
                sb.Append(Properties.Messages.NoSimilarPages);
                sb.Append("</p>");
            }
            sb.Append(@"<br /><p>");
            sb.Append(Properties.Messages.YouCanAlso);
            sb.Append(@" <a href=""");
            UrlTools.BuildUrl(sb, "Search.aspx?Query=", Tools.UrlEncode(Request["Page"]));
            sb.Append(@""">");
            sb.Append(Properties.Messages.PerformASearch);
            sb.Append("</a> ");
            sb.Append(Properties.Messages.Or);
            sb.Append(@" <a href=""");
            UrlTools.BuildUrl(sb, "Edit.aspx?Page=", Tools.UrlEncode(Request["Page"]));
            sb.Append(@"""><b>");
            sb.Append(Properties.Messages.CreateThePage);
            sb.Append("</b></a> (");
            sb.Append(Properties.Messages.CouldRequireLogin);
            sb.Append(").</p>");

            lblSearchResults.Text = sb.ToString();
        }
Example #8
0
 /// <summary>
 /// Rebuilds the page links for the specified pages.
 /// </summary>
 /// <param name="pages">The pages.</param>
 private void RebuildPageLinks(IList <PageInfo> pages)
 {
     foreach (PageInfo page in pages)
     {
         PageContent content = Content.GetPageContent(page, false);
         Pages.StorePageOutgoingLinks(page, content.Content);
     }
 }
Example #9
0
        /// <summary>
        /// Creates a new instance of the <see cref="T:SearchResultRow" /> class.
        /// </summary>
        /// <param name="result">The result to use.</param>
        /// <returns>The instance.</returns>
        public static SearchResultRow CreateInstance(SearchResult result)
        {
            //string queryStringKeywords = "HL=" + GetKeywordsForQueryString(result.Matches);
            string queryStringKeywords = "HL=" + HttpContext.Current.Request.QueryString["Query"].Replace(" ", ",");

            if (result.DocumentType == DocumentType.Page)
            {
                PageDocument doc      = result.Document as PageDocument;
                PageInfo     pageInfo = Pages.FindPage(doc.PageFullName);
                return(new SearchResultRow(doc.PageFullName + Settings.PageExtension + "?" + queryStringKeywords, Page,
                                           FormattingPipeline.PrepareTitle(doc.Title, false, FormattingContext.PageContent, pageInfo), result.Relevance,
                                           string.IsNullOrEmpty(doc.HighlightedContent) ? doc.Content : doc.HighlightedContent));
            }
            else if (result.DocumentType == DocumentType.Message)
            {
                MessageDocument doc      = result.Document as MessageDocument;
                PageInfo        pageInfo = Pages.FindPage(doc.PageFullName);
                PageContent     content  = Cache.GetPageContent(pageInfo);
                if (content == null)
                {
                    content = Content.GetPageContent(pageInfo, false);
                }

                return(new SearchResultRow(content.FullName + Settings.PageExtension + "?" + queryStringKeywords + "&amp;Discuss=1#" + Tools.GetMessageIdForAnchor(doc.DateTime), Message,
                                           FormattingPipeline.PrepareTitle(doc.Subject, false, FormattingContext.MessageBody, pageInfo) + " (" +
                                           FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.MessageBody, content.PageInfo) +
                                           ")", result.Relevance, doc.HighlightedBody));
            }
            else if (result.DocumentType == DocumentType.File)
            {
                FileDocument fileDoc = result.Document as FileDocument;

                string[] fileParts = fileDoc.FileName.Split(new char[] { '|' });

                return(new SearchResultRow("GetFile.aspx?File=" + Tools.UrlEncode(fileDoc.FileName.Substring(fileParts[0].Length + 1)) +
                                           "&amp;Provider=" + Tools.UrlEncode(fileParts[0]),
                                           File, fileParts[1], result.Relevance, fileDoc.HighlightedFileContent));
            }
            else if (result.DocumentType == DocumentType.Attachment)
            {
                PageAttachmentDocument attnDoc = result.Document as PageAttachmentDocument;
                PageInfo    pageInfo           = Pages.FindPage(attnDoc.PageFullName);
                PageContent content            = Cache.GetPageContent(pageInfo);
                if (content == null)
                {
                    content = Content.GetPageContent(pageInfo, false);
                }

                return(new SearchResultRow(content.FullName + Settings.PageExtension, Attachment,
                                           attnDoc.FileName + " (" +
                                           FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, content.PageInfo) +
                                           ")", result.Relevance, attnDoc.HighlightedFileContent));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Example #10
0
        protected void rptPages_DataBinding(object sender, EventArgs e)
        {
            if (currentPages == null)
            {
                currentPages = GetPages();
            }
            NamespaceInfo nspace = DetectNamespaceInfo();

            List <PageRow> result = new List <PageRow>(PageSize);

            string currentUser = SessionFacade.GetCurrentUsername();

            string[] currentGroups = SessionFacade.GetCurrentGroupNames();

            bool canSetPermissions = AdminMaster.CanManagePermissions(currentUser, currentGroups);
            bool canDeletePages    = AuthChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.DeletePages, currentUser, currentGroups);

            var orphanPages = Pages.GetOrphanedPages(currentPages);

            for (int i = rangeBegin; i <= rangeEnd; i++)
            {
                PageInfo page = currentPages[i];

                PageContent currentContent = Content.GetPageContent(page, false);

                // The page can be selected if the user can either manage or delete the page or manage the discussion
                // Repeat checks for enabling/disabling sections when a page is selected
                bool canEdit             = AuthChecker.CheckActionForPage(page, Actions.ForPages.ModifyPage, currentUser, currentGroups);
                bool canManagePage       = false;
                bool canManageDiscussion = false;
                if (!canDeletePages)
                {
                    canManagePage = AuthChecker.CheckActionForPage(page, Actions.ForPages.ManagePage, currentUser, currentGroups);
                }
                if (!canDeletePages && !canManagePage)
                {
                    canManageDiscussion = AuthChecker.CheckActionForPage(page, Actions.ForPages.ManageDiscussion, currentUser, currentGroups);
                }
                bool canSelect = canManagePage | canDeletePages | canManageDiscussion;

                PageContent firstContent = null;
                List <int>  baks         = Pages.GetBackups(page);
                if (baks.Count == 0)
                {
                    firstContent = currentContent;
                }
                else
                {
                    firstContent = Pages.GetBackupContent(page, baks[0]);
                }

                result.Add(new PageRow(page, currentContent, firstContent,
                                       Pages.GetMessageCount(page), baks.Count, orphanPages.Contains(page.FullName),
                                       canEdit, canSelect, canSetPermissions, txtCurrentPage.Value == page.FullName));
            }

            rptPages.DataSource = result;
        }
Example #11
0
        protected void btnAddPage_Click(object sender, EventArgs e)
        {
            PageInfo    page    = Pages.FindPage(lstAvailablePage.SelectedValue);
            PageContent content = Content.GetPageContent(page, false);

            lstPages.Items.Add(new ListItem(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, page), page.FullName));

            lstAvailablePage.Items.RemoveAt(lstAvailablePage.SelectedIndex);
            btnAddPage.Enabled = lstAvailablePage.Items.Count > 0;
        }
Example #12
0
        /// <summary>
        /// Verifies the need for a page redirection, and performs it when appropriate.
        /// </summary>
        private void VerifyAndPerformPageRedirection()
        {
            if (currentPage == null)
            {
                return;
            }

            // Force formatting so that the destination can be detected
            Content.GetFormattedPageContent(currentPage, true);

            PageInfo dest = Redirections.GetDestination(currentPage, out var fragment);

            if (dest == null)
            {
                return;
            }

            if (dest != null)
            {
                if (Request["NoRedirect"] != "1")
                {
                    var fullUrl = dest.FullName + Settings.PageExtension + "?From=" + currentPage.FullName;
                    if (!string.IsNullOrEmpty(fragment))
                    {
                        fullUrl += "#" + fragment;
                    }

                    UrlTools.Redirect(fullUrl, false);
                }
                else
                {
                    // Write redirection hint
                    var sb = new StringBuilder();
                    sb.Append(@"<div id=""RedirectionDiv"">");
                    sb.Append(Properties.Messages.ThisPageRedirectsTo);
                    sb.Append(": ");
                    sb.Append(@"<a href=""");

                    var fullUrl = UrlTools.BuildUrl("++", Tools.UrlEncode(dest.FullName), Settings.PageExtension, "?From=", Tools.UrlEncode(currentPage.FullName));
                    if (!string.IsNullOrEmpty(fragment))
                    {
                        fullUrl += "#" + fragment;
                    }
                    sb.Append(fullUrl);
                    sb.Append(@""">");
                    PageContent k = Content.GetPageContent(dest, true);
                    sb.Append(FormattingPipeline.PrepareTitle(k.Title, false, FormattingContext.PageContent, currentPage));
                    sb.Append("</a></div>");
                    var literal = new Literal();
                    literal.Text = sb.ToString();
                    plhContent.Controls.Add(literal);
                }
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            PageInfo    page    = Pages.FindPage(lstAvailablePage.SelectedValue);
            PageContent content = Content.GetPageContent(page, false);

            lstPages.Items.Add(new ListItem(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, page), page.FullName));

            txtPageName.Text = "";
            lstAvailablePage.Items.Clear();
            btnAdd.Enabled = false;
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            lstAvailablePage.Items.Clear();
            btnAddPage.Enabled = false;

            txtPageName.Text = txtPageName.Text.Trim();

            if (txtPageName.Text.Length == 0)
            {
                return;
            }

            List <SearchResult> similarPages = SearchClass.Search(new SearchField[] { SearchField.PageFullName }, txtPageName.Text, SearchOptions.AtLeastOneWord);

            List <PageInfo> pages = new List <PageInfo>();

            foreach (SearchResult page in similarPages)
            {
                if (page.DocumentType == DocumentType.Page)
                {
                    PageDocument pageDocument = page.Document as PageDocument;
                    PageInfo     pageInfo     = Pages.FindPage(pageDocument.PageFullName);
                    pages.Add(pageInfo);
                }
            }

            string cp = CurrentProvider;

            foreach (PageInfo page in
                     from p in pages
                     where p.Provider.GetType().FullName == cp
                     select p)
            {
                // Filter pages already in the list
                bool found = false;
                foreach (ListItem item in lstPages.Items)
                {
                    if (item.Value == page.FullName)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    PageContent content = Content.GetPageContent(page, false);
                    lstAvailablePage.Items.Add(new ListItem(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, page), page.FullName));
                }
            }

            btnAddPage.Enabled = lstAvailablePage.Items.Count > 0;
        }
Example #15
0
        /// <summary>
        /// Gets the formatted page excerpt.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="matches">The matches to highlight.</param>
        /// <returns>The excerpt.</returns>
        private static string GetExcerpt(PageInfo page, WordInfoCollection matches)
        {
            PageContent pageContent = Content.GetPageContent(page, true);
            string      content     = pageContent.Content;

            List <WordInfo> sortedMatches = new List <WordInfo>(matches);

            sortedMatches.RemoveAll(delegate(WordInfo wi) { return(wi.Location != WordLocation.Content); });
            sortedMatches.Sort(delegate(WordInfo x, WordInfo y) { return(x.FirstCharIndex.CompareTo(y.FirstCharIndex)); });

            return(BuildFormattedExcerpt(sortedMatches, Host.Instance.PrepareContentForIndexing(page, content)));
        }
        /// <summary>
        /// Deletes and de-indexes a page attachment.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="pageFullName">The page full name.</param>
        /// <param name="name">The attachment name.</param>
        /// <returns><c>true</c> if the attachment was deleted, <c>false</c> otherwise.</returns>
        public static bool DeletePageAttachment(IFilesStorageProviderV30 provider, string pageFullName, string name)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (pageFullName == null)
            {
                throw new ArgumentNullException("pageFullName");
            }

            if (pageFullName.Length == 0)
            {
                throw new ArgumentException("Page Full Name cannot be empty", "pageFullName");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }

            PageInfo pageInfo = Pages.FindPage(pageFullName);

            if (pageInfo == null)
            {
                return(false);
            }
            PageContent page = Content.GetPageContent(pageInfo, false);

            if (page == null)
            {
                return(false);
            }

            bool done = provider.DeletePageAttachment(pageInfo, name);

            if (!done)
            {
                return(false);
            }

            SearchClass.UnindexPageAttachment(name, page);

            Host.Instance.OnAttachmentActivity(provider.GetType().FullName, name, pageFullName, null, FileActivity.AttachmentDeleted);

            return(true);
        }
Example #17
0
        /// <summary>
        /// Appends the drop-down menu DIV with outgoing links for a page.
        /// </summary>
        /// <param name="sb">The destination <see cref="T:StringBuilder" />.</param>
        /// <param name="page">The page.</param>
        /// <param name="dbPrefix">The drop-down menu DIV ID prefix.</param>
        /// <returns>The DIV ID, or <c>null</c> if no target pages were found.</returns>
        private string AppendBreadcrumbDropDown(StringBuilder sb, PageInfo page, string dbPrefix)
        {
            // Build outgoing links list
            // Generate list DIV
            // Return DIV's ID

            var outgoingLinks = Pages.GetPageOutgoingLinks(page);

            if (outgoingLinks == null || outgoingLinks.Length == 0)
            {
                return(null);
            }

            var id = dbPrefix + Guid.NewGuid().ToString();

            var buffer = new StringBuilder(300);

            buffer.AppendFormat(@"<div id=""{0}"" style=""display: none;"" class=""pageoutgoinglinksmenu"" onmouseover=""javascript:return __CancelHideTimer();"" onmouseout=""javascript:return __HideDropDown('{0}');"">", id);
            var count = 0;

            foreach (var link in outgoingLinks)
            {
                PageInfo target = Pages.FindPage(link);
                if (target != null)
                {
                    count++;
                    PageContent cont = Content.GetPageContent(target, true);

                    var title = FormattingPipeline.PrepareTitle(cont.Title, false, FormattingContext.PageContent, currentPage);

                    buffer.AppendFormat(@"<a href=""{0}{1}"" title=""{2}"">{2}</a>", link, Settings.PageExtension, title, title);
                }
                if (count >= 20)
                {
                    break;
                }
            }
            buffer.Append("</div>");

            sb.Insert(0, buffer.ToString());

            if (count > 0)
            {
                return(id);
            }
            else
            {
                return(null);
            }
        }
Example #18
0
        /// <summary>
        /// Prints the results of the automatic search.
        /// </summary>
        public void PrintSearchResults()
        {
            StringBuilder sb = new StringBuilder(1000);

            PageInfo[] results = SearchTools.SearchSimilarPages(Request["Page"], DetectNamespace());
            if (results.Length > 0)
            {
                sb.Append("<p>");
                sb.Append(Properties.Messages.WereYouLookingFor);
                sb.Append("</p>");
                sb.Append("<ul>");
                PageContent c;
                for (int i = 0; i < results.Length; i++)
                {
                    c = Content.GetPageContent(results[i], true);
                    sb.Append(@"<li><a href=""");
                    UrlTools.BuildUrl(sb, Tools.UrlEncode(results[i].FullName), Settings.PageExtension);
                    sb.Append(@""">");
                    sb.Append(FormattingPipeline.PrepareTitle(c.Title, false, FormattingContext.PageContent, c.PageInfo));
                    sb.Append("</a></li>");
                }
                sb.Append("</ul>");
            }
            else
            {
                sb.Append("<p>");
                sb.Append(Properties.Messages.NoSimilarPages);
                sb.Append("</p>");
            }
            sb.Append(@"<br /><p>");
            sb.Append(Properties.Messages.YouCanAlso);
            sb.Append(@" <a href=""");
            UrlTools.BuildUrl(sb, "Search.aspx?Query=", Tools.UrlEncode(Request["Page"]));
            sb.Append(@""">");
            sb.Append(Properties.Messages.PerformASearch);
            sb.Append("</a> ");
            sb.Append(Properties.Messages.Or);
            sb.Append(@" <a href=""");
            UrlTools.BuildUrl(sb, "Edit.aspx?Page=", Tools.UrlEncode(Request["Page"]));
            sb.Append(@"""><b>");
            sb.Append(Properties.Messages.CreateThePage);
            sb.Append("</b></a> (");
            sb.Append(Properties.Messages.CouldRequireLogin);
            sb.Append(").</p>");

            lblSearchResults.Text = sb.ToString();
        }
Example #19
0
        /// <summary>
        /// Gets the creator of a page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <returns>The creator.</returns>
        private string GetCreator(PageInfo page)
        {
            List <int> baks = Pages.GetBackups(page);

            PageContent content = null;

            if (baks.Count > 0)
            {
                content = Pages.GetBackupContent(page, baks[0]);
            }
            else
            {
                content = Content.GetPageContent(page, false);
            }

            return(content.User);
        }
Example #20
0
        /// <summary>
        /// Creates a new instance of the <see cref="T:SearchResultRow" /> class.
        /// </summary>
        /// <param name="result">The result to use.</param>
        /// <returns>The instance.</returns>
        public static SearchResultRow CreateInstance(SearchResult result)
        {
            var queryStringKeywords = "HL=" + GetKeywordsForQueryString(result.Matches);

            if (result.Document.TypeTag == PageDocument.StandardTypeTag)
            {
                var pageDoc = result.Document as PageDocument;

                return(new SearchResultRow(pageDoc.PageInfo.FullName + Settings.PageExtension + "?" + queryStringKeywords, Page,
                                           FormattingPipeline.PrepareTitle(pageDoc.Title, false, FormattingContext.PageContent, pageDoc.PageInfo),
                                           result.Relevance.Value, GetExcerpt(pageDoc.PageInfo, result.Matches)));
            }
            else if (result.Document.TypeTag == MessageDocument.StandardTypeTag)
            {
                var msgDoc = result.Document as MessageDocument;

                PageContent content = Content.GetPageContent(msgDoc.PageInfo, true);

                return(new SearchResultRow(msgDoc.PageInfo.FullName + Settings.PageExtension + "?" + queryStringKeywords + "&amp;Discuss=1#" + Tools.GetMessageIdForAnchor(msgDoc.DateTime), Message,
                                           FormattingPipeline.PrepareTitle(msgDoc.Title, false, FormattingContext.MessageBody, content.PageInfo) + " (" +
                                           FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.MessageBody, content.PageInfo) +
                                           ")", result.Relevance.Value, GetExcerpt(msgDoc.PageInfo, msgDoc.MessageID, result.Matches)));
            }
            else if (result.Document.TypeTag == FileDocument.StandardTypeTag)
            {
                var fileDoc = result.Document as FileDocument;

                return(new SearchResultRow("GetFile.aspx?File=" + Tools.UrlEncode(fileDoc.Name.Substring(fileDoc.Provider.Length + 1)) +
                                           "&amp;Provider=" + Tools.UrlEncode(fileDoc.Provider),
                                           File, fileDoc.Title, result.Relevance.Value, ""));
            }
            else if (result.Document.TypeTag == PageAttachmentDocument.StandardTypeTag)
            {
                var         attnDoc = result.Document as PageAttachmentDocument;
                PageContent content = Content.GetPageContent(attnDoc.Page, false);

                return(new SearchResultRow(attnDoc.Page.FullName + Settings.PageExtension, Attachment,
                                           attnDoc.Title + " (" +
                                           FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, content.PageInfo) +
                                           ")", result.Relevance.Value, ""));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Example #21
0
        protected List <TreeElement> ctPages_Populate(object sender, PopulateEventArgs e)
        {
            string currentNamespace = DetectNamespace();

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

            List <TreeElement> result = new List <TreeElement>(100);

            foreach (PageInfo pi in Pages.GetPages(Pages.FindNamespace(lstNamespace.SelectedValue)))
            {
                string pageNamespace = NameTools.GetNamespace(pi.FullName);
                if (string.IsNullOrEmpty(pageNamespace))
                {
                    pageNamespace = null;
                }

                PageContent cont              = Content.GetPageContent(pi, true);
                string      formattedTitle    = FormattingPipeline.PrepareTitle(cont.Title, false, FormattingContext.Other, pi);
                string      onClickJavascript = "javascript:";
                // Populate the page title box if the title is different to the page name
                if (pi.FullName != cont.Title)
                {
                    // Supply the page title to the Javascript that sets the page title on the page
                    // We can safely escape the \ and ' characters, but the " character is interpreted by the browser even if it is escaped to Javascript, so we can't allow it.
                    // Instead we replace it with an escaped single quote.
                    // Similarly, < on it's own is fine, but causes problems when combined with text and > to form a tag.  Safest to remove < characters to prevent
                    // breaking the drop-down.
                    onClickJavascript += "SetValue('txtPageTitle', '" + cont.Title.Replace("\\", "\\\\").Replace("'", "\\'").Replace("\"", "\\'").Replace("<", "") + "');";
                }
                else
                {
                    onClickJavascript += "SetValue('txtPageTitle', '');";
                }
                // Populate the page name
                onClickJavascript += "return SetValue('txtPageName', '" +
                                     ((pageNamespace == currentNamespace ? NameTools.GetLocalName(pi.FullName) : ("++" + pi.FullName))).Replace("++++", "++") + "');";
                TreeElement item = new TreeElement(pi.FullName, formattedTitle, onClickJavascript);
                result.Add(item);
            }
            return(result);
        }
Example #22
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            lstAvailablePage.Items.Clear();
            btnAddPage.Enabled = false;

            txtPageName.Text = txtPageName.Text.Trim();

            if (txtPageName.Text.Length == 0)
            {
                return;
            }

            PageInfo[] pages = SearchTools.SearchSimilarPages(txtPageName.Text, CurrentNamespace);

            string cp = CurrentProvider;

            foreach (PageInfo page in
                     from p in pages
                     where p.Provider.GetType().FullName == cp
                     select p)
            {
                // Filter pages already in the list
                bool found = false;
                foreach (ListItem item in lstPages.Items)
                {
                    if (item.Value == page.FullName)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    PageContent content = Content.GetPageContent(page, false);
                    lstAvailablePage.Items.Add(new ListItem(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, page), page.FullName));
                }
            }

            btnAddPage.Enabled = lstAvailablePage.Items.Count > 0;
        }
Example #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:PageRow" /> class.
        /// </summary>
        /// <param name="nspace">The namespace.</param>
        /// <param name="nspacePrefix">The namespace prefix.</param>
        /// <param name="name">The full name.</param>
        /// <param name="linkingPages">The pages that link the wanted page.</param>
        public WantedPageRow(string nspace, string nspacePrefix, string name, List <string> linkingPages)
        {
            this.nspace       = nspace;
            this.nspacePrefix = nspacePrefix;
            this.name         = name;

            StringBuilder sb = new StringBuilder(100);

            for (int i = 0; i < linkingPages.Count; i++)
            {
                PageInfo page = Pages.FindPage(linkingPages[i]);
                if (page != null)
                {
                    PageContent content = Content.GetPageContent(page, false);

                    sb.AppendFormat(@"<a href=""{0}{1}"" title=""{2}"" target=""_blank"">{2}</a>, ", page.FullName, Settings.PageExtension,
                                    FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, page));
                }
            }
            this.linkingPages = sb.ToString().TrimEnd(' ', ',');
        }
Example #24
0
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            if (currentPage == null && txtName.Visible)
            {
                currentPage = Pages.FindPage(NameTools.GetFullName(DetectNamespace(), txtName.Text));
            }
            if (currentPage != null)
            {
                // Try redirecting to proper section
                string anchor = null;
                if (currentSection != -1)
                {
                    int start, len;
                    ExtractSection(Content.GetPageContent(currentPage, true).Content, currentSection, out start, out len, out anchor);
                }

                UrlTools.Redirect(Tools.UrlEncode(currentPage.FullName) + Settings.PageExtension + (anchor != null ? ("#" + anchor + "_" + currentSection.ToString()) : ""));
            }
            else
            {
                UrlTools.Redirect(UrlTools.BuildUrl("Default.aspx"));
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            txtPageName.Text = txtPageName.Text.Trim();

            if (txtPageName.Text.Length == 0)
            {
                lstAvailablePage.Items.Clear();
                btnAdd.Enabled = false;
                return;
            }

            PageInfo[] pages = SearchTools.SearchSimilarPages(txtPageName.Text, lstNamespace.SelectedValue);

            lstAvailablePage.Items.Clear();

            foreach (PageInfo page in pages)
            {
                PageContent content = Content.GetPageContent(page, false);
                lstAvailablePage.Items.Add(new ListItem(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, page), page.FullName));
            }

            btnAdd.Enabled = pages.Length > 0;
        }
        protected void rptNavPaths_ItemCommand(object sender, CommandEventArgs e)
        {
            txtCurrentNavPath.Value = e.CommandArgument as string;

            if (e.CommandName == "Select")
            {
                if (!CanManagePagesInCurrentNamespace())
                {
                    return;
                }

                txtName.Text    = txtCurrentNavPath.Value;
                txtName.Enabled = false;

                NavigationPath path = NavigationPaths.Find(txtCurrentNavPath.Value);
                foreach (string page in path.Pages)
                {
                    PageInfo pageInfo = Pages.FindPage(page);
                    if (pageInfo != null)
                    {
                        PageContent content = Content.GetPageContent(pageInfo, false);
                        lstPages.Items.Add(new ListItem(FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.Other, pageInfo), pageInfo.FullName));
                    }
                }

                cvName2.Enabled   = false;
                btnCreate.Visible = false;
                btnSave.Visible   = true;
                btnDelete.Visible = true;

                pnlList.Visible        = false;
                pnlEditNavPath.Visible = true;

                lblResult.Text = "";
            }
        }
Example #27
0
        public void PrintDiff()
        {
            if (Request["Page"] == null || Request["Rev1"] == null || Request["Rev2"] == null)
            {
                Redirect();
                return;
            }

            StringBuilder sb = new StringBuilder();

            PageInfo page = Pages.FindPage(Request["Page"]);

            if (page == null)
            {
                Redirect();
                return;
            }

            bool canView = AuthChecker.CheckActionForPage(page, Actions.ForPages.ReadPage,
                                                          SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames());

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

            int    rev1     = -1;
            int    rev2     = -1;
            string rev1Text = "";
            string rev2Text = "";

            PageContent rev1Content = null;
            PageContent rev2Content = null;
            bool        draft       = false;

            // Load rev1 content
            if (int.TryParse(Request["Rev1"], out rev1))
            {
                rev1Content = Pages.GetBackupContent(page, rev1);
                rev1Text    = rev1.ToString();
                if (rev1 >= 0 && rev1Content == null && Pages.GetBackupContent(page, rev1 - 1) != null)
                {
                    rev1Content = Content.GetPageContent(page, false);
                }
                if (rev1Content == null)
                {
                    Redirect();
                }
            }
            else
            {
                // Look for current
                if (Request["Rev1"].ToLowerInvariant() == "current")
                {
                    rev1Content = Content.GetPageContent(page, false);
                    rev1Text    = Properties.Messages.Current;
                }
                else
                {
                    Redirect();
                }
            }

            if (int.TryParse(Request["Rev2"], out rev2))
            {
                rev2Content = Pages.GetBackupContent(page, rev2);
                rev2Text    = rev2.ToString();
                if (rev2 >= 0 && rev2Content == null && Pages.GetBackupContent(page, rev2 - 1) != null)
                {
                    rev2Content = Content.GetPageContent(page, false);
                }
                if (rev2Content == null)
                {
                    Redirect();
                }
            }
            else
            {
                // Look for current or draft
                if (Request["Rev2"].ToLowerInvariant() == "current")
                {
                    rev2Content = Content.GetPageContent(page, false);
                    rev2Text    = Properties.Messages.Current;
                }
                else if (Request["Rev2"].ToLowerInvariant() == "draft")
                {
                    rev2Content = Pages.GetDraft(page);
                    rev2Text    = Properties.Messages.Draft;
                    draft       = true;
                    if (rev2Content == null)
                    {
                        Redirect();
                    }
                }
                else
                {
                    Redirect();
                }
            }

            PageContent content = Content.GetPageContent(page, true);

            lblTitle.Text = Properties.Messages.DiffingPageTitle.Replace("##PAGETITLE##",
                                                                         FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, page)).Replace("##REV1##", rev1Text).Replace("##REV2##", rev2Text);

            lblBack.Text = string.Format(@"<a href=""{0}"">&laquo; {1}</a>",
                                         UrlTools.BuildUrl("History.aspx?Page=", Tools.UrlEncode(Request["Page"]), "&amp;Rev1=", Request["Rev1"], "&amp;Rev2=", Request["Rev2"]),
                                         Properties.Messages.Back);
            lblBack.Visible = !draft;

            sb.Append(Properties.Messages.DiffColorKey);
            sb.Append("<br /><br />");

            string result = DiffTools.DiffRevisions(rev1Content.Content, rev2Content.Content);

            sb.Append(result);

            lblDiff.Text = sb.ToString();
        }
Example #28
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();
        }
Example #29
0
        protected void btnRename_Click(object sender, EventArgs e)
        {
            // Check name for change, validity and existence of another page with same name
            // Perform rename
            // Create shadow page, if needed

            PageInfo page = Pages.FindPage(txtCurrentPage.Value);

            if (!AuthChecker.CheckActionForNamespace(Pages.FindNamespace(NameTools.GetNamespace(page.FullName)), Actions.ForNamespaces.DeletePages,
                                                     SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames()))
            {
                return;
            }

            txtNewName.Text = txtNewName.Text.Trim();

            string currentNamespace = NameTools.GetNamespace(txtCurrentPage.Value);
            string currentPage      = NameTools.GetLocalName(txtCurrentPage.Value);

            if (!Page.IsValid)
            {
                return;
            }

            if (txtNewName.Text.ToLowerInvariant() == currentPage.ToLowerInvariant())
            {
                return;
            }

            if (Pages.FindPage(NameTools.GetFullName(currentNamespace, txtNewName.Text)) != null)
            {
                lblRenameResult.CssClass = "resulterror";
                lblRenameResult.Text     = Properties.Messages.PageAlreadyExists;
                return;
            }

            Log.LogEntry("Page rename requested for " + txtCurrentPage.Value, EntryType.General, Log.SystemUsername);

            PageInfo    oldPage    = Pages.FindPage(txtCurrentPage.Value);
            PageContent oldContent = Content.GetPageContent(oldPage, false);

            bool done = Pages.RenamePage(oldPage, txtNewName.Text);

            if (done)
            {
                if (chkShadowPage.Checked)
                {
                    done = Pages.CreatePage(currentNamespace, currentPage);

                    if (done)
                    {
                        done = Pages.ModifyPage(Pages.FindPage(txtCurrentPage.Value),
                                                oldContent.Title, oldContent.User, oldContent.LastModified,
                                                oldContent.Comment, ">>> [" + txtNewName.Text + "]",
                                                new string[0], oldContent.Description, SaveMode.Normal);

                        if (done)
                        {
                            ResetPageList();

                            RefreshList();
                            lblRenameResult.CssClass = "resultok";
                            lblRenameResult.Text     = Properties.Messages.PageRenamed;
                            ReturnToList();
                        }
                        else
                        {
                            lblRenameResult.CssClass = "resulterror";
                            lblRenameResult.Text     = Properties.Messages.PageRenamedCouldNotSetShadowPageContent;
                        }
                    }
                    else
                    {
                        lblRenameResult.CssClass = "resulterror";
                        lblRenameResult.Text     = Properties.Messages.PageRenamedCouldNotCreateShadowPage;
                    }
                }
                else
                {
                    RefreshList();
                    lblRenameResult.CssClass = "resultok";
                    lblRenameResult.Text     = Properties.Messages.PageRenamed;
                    ReturnToList();
                }
            }
            else
            {
                lblRenameResult.CssClass = "resulterror";
                lblRenameResult.Text     = Properties.Messages.CouldNotRenamePage;
            }
        }
        /// <summary>
        /// Stores and indexes a page attachment.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="pageFullName">The page full name.</param>
        /// <param name="name">The attachment name.</param>
        /// <param name="source">The source stream.</param>
        /// <param name="overwrite"><c>true</c> to overwrite an existing attachment with the same name, <c>false</c> otherwise.</param>
        /// <returns><c>true</c> if the attachment was stored, <c>false</c> otherwise.</returns>
        public static bool StorePageAttachment(IFilesStorageProviderV30 provider, string pageFullName, string name, Stream source, bool overwrite)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (pageFullName == null)
            {
                throw new ArgumentNullException("pageFullName");
            }

            if (pageFullName.Length == 0)
            {
                throw new ArgumentException("Page Full Name cannot be empty", "pageFullName");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (name.Length == 0)
            {
                throw new ArgumentException("Name cannot be empty", "name");
            }

            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            PageInfo pageInfo = Pages.FindPage(pageFullName);

            if (pageInfo == null)
            {
                return(false);
            }
            PageContent page = Content.GetPageContent(pageInfo, false);

            if (page == null)
            {
                return(false);
            }

            bool done = provider.StorePageAttachment(pageInfo, name, source, overwrite);

            if (!done)
            {
                return(false);
            }

            if (overwrite)
            {
                SearchClass.UnindexPageAttachment(name, page);
            }

            // Index the attached file
            string tempDir = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Guid.NewGuid().ToString());

            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }

            string tempFile = Path.Combine(tempDir, name);

            source.Seek(0, SeekOrigin.Begin);
            using (FileStream temp = File.Create(tempFile))
            {
                source.CopyTo(temp);
            }
            SearchClass.IndexPageAttachment(name, tempFile, page);
            Directory.Delete(tempDir, true);

            Host.Instance.OnAttachmentActivity(provider.GetType().FullName, name, pageFullName, null, FileActivity.AttachmentUploaded);

            return(true);
        }