Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = Properties.Messages.EditTitle + " - " + Settings.WikiTitle;

            lblEditNotice.Text = Formatter.FormatPhase3(Formatter.Format(Settings.Provider.GetMetaDataItem(
                                                                             MetaDataItem.EditNotice, DetectNamespace()), false, FormattingContext.Other, null), FormattingContext.Other, null);

            // Prepare page unload warning
            var ua = Request.UserAgent;

            if (!string.IsNullOrEmpty(ua))
            {
                ua = ua.ToLowerInvariant();
                var sbua = new StringBuilder(50);
                sbua.Append(@"<script type=""text/javascript"">");
                sbua.Append("\r\n<!--\r\n");
                if (ua.Contains("gecko"))
                {
                    // Mozilla
                    sbua.Append("addEventListener('beforeunload', __UnloadPage, true);");
                }
                else
                {
                    // IE
                    sbua.Append("window.attachEvent('onbeforeunload', __UnloadPage);");
                }
                sbua.Append("\r\n// -->\r\n");
                sbua.Append("</script>");
                lblUnloadPage.Text = sbua.ToString();
            }

            if (!Page.IsPostBack)
            {
                PopulateCategories(new CategoryInfo[0]);

                if (Settings.AutoGeneratePageNames)
                {
                    pnlPageName.Visible   = false;
                    pnlManualName.Visible = true;
                }
            }

            // Load requested page, if any
            if (Request["Page"] != null || Page.IsPostBack)
            {
                string name = null;
                if (Request["Page"] != null)
                {
                    name = Request["Page"];
                }
                else
                {
                    name = txtName.Text;
                }

                currentPage = Pages.FindPage(name);

                // If page already exists, load the content and disable page name,
                // otherwise pre-fill page name
                if (currentPage != null)
                {
                    // Look for a draft
                    currentContent = Pages.GetDraft(currentPage);

                    if (currentContent == null)
                    {
                        // No cache because the page will be probably modified in a few minutes
                        currentContent = Content.GetPageContent(currentPage, false);
                    }
                    else
                    {
                        isDraft = true;
                    }

                    // Set current page for editor and attachment manager
                    editor.CurrentPage            = currentPage;
                    attachmentManager.CurrentPage = currentPage;

                    if (!int.TryParse(Request["Section"], out currentSection))
                    {
                        currentSection = -1;
                    }

                    // Fill data, if not posted back
                    if (!Page.IsPostBack)
                    {
                        // Set keywords, description
                        SetKeywords(currentContent.Keywords);
                        txtDescription.Text = currentContent.Description;

                        txtName.Text          = NameTools.GetLocalName(currentPage.FullName);
                        txtName.Enabled       = false;
                        pnlPageName.Visible   = false;
                        pnlManualName.Visible = false;

                        PopulateCategories(Pages.GetCategoriesForPage(currentPage));

                        txtTitle.Text = currentContent.Title;

                        // Manage section, if appropriate (disable if draft)
                        if (!isDraft && currentSection != -1)
                        {
                            int startIndex, len;
                            var dummy = "";
                            ExtractSection(currentContent.Content, currentSection, out startIndex, out len, out dummy);
                            editor.SetContent(currentContent.Content.Substring(startIndex, len), Settings.UseVisualEditorAsDefault);
                        }
                        else
                        {
                            // Select default editor view (WikiMarkup or Visual) and populate content
                            editor.SetContent(currentContent.Content, Settings.UseVisualEditorAsDefault);
                        }
                    }
                }
                else
                {
                    // Pre-fill name, if not posted back
                    if (!Page.IsPostBack)
                    {
                        // Set both name and title, as the NAME was provided from the query-string and must be preserved
                        pnlPageName.Visible   = true;
                        pnlManualName.Visible = false;
                        txtName.Text          = NameTools.GetLocalName(name);
                        txtTitle.Text         = txtName.Text;
                        editor.SetContent(LoadTemplateIfAppropriate(), Settings.UseVisualEditorAsDefault);
                    }
                }
            }
            else
            {
                if (!Page.IsPostBack)
                {
                    chkMinorChange.Visible = false;
                    chkSaveAsDraft.Visible = false;

                    editor.SetContent(LoadTemplateIfAppropriate(), Settings.UseVisualEditorAsDefault);
                }
            }

            // Here is centralized all permissions-checking code
            DetectPermissions();

            // Verify the following permissions:
            // - if new page, check for page creation perms
            // - else, check for editing perms
            //    - full edit or edit with approval
            // - categories management
            // - attachment manager
            // - CAPTCHA if enabled and user is anonymous
            // ---> recheck every time an action is performed

            if (currentPage == null)
            {
                // Check permissions for creating new pages
                if (!canCreateNewPages)
                {
                    if (SessionFacade.LoginKey == null)
                    {
                        UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                    }
                    else
                    {
                        UrlTools.Redirect("AccessDenied.aspx");
                    }
                }
            }
            else
            {
                // Check permissions for editing current page
                if (!canEdit && !canEditWithApproval)
                {
                    if (SessionFacade.LoginKey == null)
                    {
                        UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed()));
                    }
                    else
                    {
                        UrlTools.Redirect("AccessDenied.aspx");
                    }
                }
            }

            if (!canEdit && canEditWithApproval)
            {
                // Hard-wire status of draft and minor change checkboxes
                chkMinorChange.Enabled = false;
                chkSaveAsDraft.Enabled = false;
                chkSaveAsDraft.Checked = true;
            }

            // Setup categories
            lstCategories.Enabled       = canManagePageCategories;
            pnlCategoryCreation.Visible = canCreateNewCategories;

            // Setup attachment manager (require at least download permissions)
            attachmentManager.Visible = canDownloadAttachments;

            // CAPTCHA
            pnlCaptcha.Visible = SessionFacade.LoginKey == null && !Settings.DisableCaptchaControl;
            captcha.Visible    = pnlCaptcha.Visible;

            // Moderation notice
            pnlApprovalRequired.Visible = !canEdit && canEditWithApproval;

            // Check and manage editing collisions
            ManageEditingCollisions();

            if (!Page.IsPostBack)
            {
                ManageTemplatesDisplay();

                // Display draft status
                ManageDraft();
            }

            // Setup session refresh iframe
            PrintSessionRefresh();
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["OpenSearch"] != null)
            {
                GenerateOpenSearchDescription();
                return;
            }

            Page.Title = Properties.Messages.SearchTitle + " - " + Settings.WikiTitle;

            lblStrings.Text = string.Format("<script type=\"text/javascript\"><!--\r\nvar AllNamespacesCheckbox = '{0}';\r\n//-->\r\n</script>", chkAllNamespaces.ClientID);

            txtQuery.Focus();

            if (!Page.IsPostBack)
            {
                // Initialize all controls

                string[] queryStringCategories = null;
                if (Request["Categories"] != null)
                {
                    queryStringCategories = Request["Categories"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    Array.Sort(queryStringCategories);
                }

                if (Request["SearchUncategorized"] != null)
                {
                    chkUncategorizedPages.Checked = Request["SearchUncategorized"] == "1";
                }

                if (Request["Query"] != null)
                {
                    chkAllNamespaces.Checked       = Request["AllNamespaces"] == "1";
                    chkFilesAndAttachments.Checked = Request["FilesAndAttachments"] == "1";
                }

                if (chkAllNamespaces.Checked)
                {
                    lblHideCategoriesScript.Text = "<script type=\"text/javascript\"><!--\r\ndocument.getElementById('CategoryFilterDiv').style['display'] = 'none';\r\n//-->\r\n</script>";
                }

                List <CategoryInfo> allCategories = Pages.GetCategories(DetectNamespaceInfo());

                lstCategories.Items.Clear();

                List <string> selectedCategories = new List <string>(allCategories.Count);

                // Populate categories list and select specified categories if any
                foreach (CategoryInfo cat in allCategories)
                {
                    ListItem item = new ListItem(NameTools.GetLocalName(cat.FullName), cat.FullName);
                    if (queryStringCategories != null)
                    {
                        if (Array.Find(queryStringCategories, delegate(string c) { return(c == cat.FullName); }) != null)
                        {
                            item.Selected = true;
                            selectedCategories.Add(cat.FullName);
                        }
                    }
                    else
                    {
                        item.Selected = true;
                        selectedCategories.Add(cat.FullName);
                    }
                    lstCategories.Items.Add(item);
                }

                // Select mode if specified
                if (Request["Mode"] != null)
                {
                    switch (Request["Mode"])
                    {
                    case "1":
                        rdoAtLeastOneWord.Checked = true;
                        rdoAllWords.Checked       = false;
                        rdoExactPhrase.Checked    = false;
                        break;

                    case "2":
                        rdoAtLeastOneWord.Checked = false;
                        rdoAllWords.Checked       = true;
                        rdoExactPhrase.Checked    = false;
                        break;

                    default:
                        rdoAtLeastOneWord.Checked = false;
                        rdoAllWords.Checked       = false;
                        rdoExactPhrase.Checked    = true;
                        break;
                    }
                }

                if (Request["Query"] != null)
                {
                    txtQuery.Text = Request["Query"];

                    btnGo_Click(sender, e);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Prints the pages.
        /// </summary>
        public void PrintPages()
        {
            StringBuilder sb = new StringBuilder(65536);

            if (currentPages == null)
            {
                currentPages = GetAllPages();
            }

            string currentWiki = DetectWiki();

            // Prepare ExtendedPageInfo array
            ExtendedPageInfo[] tempPageList = new ExtendedPageInfo[rangeEnd - rangeBegin + 1];
            for (int i = 0; i < tempPageList.Length; i++)
            {
                tempPageList[i] = new ExtendedPageInfo(currentPages[rangeBegin + i], GetCreator(currentPages[rangeBegin + i]), currentPages[rangeBegin + i].User);
            }

            // Prepare for sorting
            bool          reverse = false;
            SortingMethod sortBy  = SortingMethod.Title;

            if (Request["SortBy"] != null)
            {
                try {
                    sortBy = (SortingMethod)Enum.Parse(typeof(SortingMethod), Request["SortBy"], true);
                }
                catch {
                    // Backwards compatibility
                    if (Request["SortBy"].ToLowerInvariant() == "date")
                    {
                        sortBy = SortingMethod.DateTime;
                    }
                }
                if (Request["Reverse"] != null)
                {
                    reverse = true;
                }
            }

            SortedDictionary <SortingGroup, List <ExtendedPageInfo> > sortedPages = PageSortingTools.Sort(tempPageList, sortBy, reverse);

            sb.Append(@"<table id=""PageListTable"" class=""generic"" cellpadding=""0"" cellspacing=""0"">");
            sb.Append("<thead>");
            sb.Append(@"<tr class=""tableheader"">");

            // Page title
            sb.Append(@"<th><a rel=""nofollow"" href=""");
            UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?SortBy=Title",
                              (!reverse && sortBy == SortingMethod.Title ? "&amp;Reverse=1" : ""),
                              (Request["Cat"] != null ? "&amp;Cat=" + Tools.UrlEncode(Request["Cat"]) : ""),
                              "&amp;Page=", selectedPage.ToString());

            sb.Append(@""" title=""");
            sb.Append(Properties.Messages.SortByTitle);
            sb.Append(@""">");
            sb.Append(Properties.Messages.PageTitle);
            sb.Append((reverse && sortBy.Equals("title") ? " &uarr;" : ""));
            sb.Append((!reverse && sortBy.Equals("title") ? " &darr;" : ""));
            sb.Append("</a></th>");

            // Message count
            sb.Append(@"<th><img src=""Images/Comment.png"" alt=""Comments"" /></th>");

            // Creation date/time
            sb.Append(@"<th><a rel=""nofollow"" href=""");
            UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?SortBy=Creation",
                              (!reverse && sortBy == SortingMethod.Creation ? "&amp;Reverse=1" : ""),
                              (Request["Cat"] != null ? "&amp;Cat=" + Tools.UrlEncode(Request["Cat"]) : ""),
                              "&amp;Page=", selectedPage.ToString());

            sb.Append(@""" title=""");
            sb.Append(Properties.Messages.SortByDate);
            sb.Append(@""">");
            sb.Append(Properties.Messages.CreatedOn);
            sb.Append((reverse && sortBy.Equals("creation") ? " &uarr;" : ""));
            sb.Append((!reverse && sortBy.Equals("creation") ? " &darr;" : ""));
            sb.Append("</a></th>");

            // Mod. date/time
            sb.Append(@"<th><a rel=""nofollow"" href=""");
            UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?SortBy=DateTime",
                              (!reverse && sortBy == SortingMethod.DateTime ? "&amp;Reverse=1" : ""),
                              (Request["Cat"] != null ? "&amp;Cat=" + Tools.UrlEncode(Request["Cat"]) : ""),
                              "&amp;Page=", selectedPage.ToString());

            sb.Append(@""" title=""");
            sb.Append(Properties.Messages.SortByDate);
            sb.Append(@""">");
            sb.Append(Properties.Messages.ModifiedOn);
            sb.Append((reverse && sortBy.Equals("date") ? " &uarr;" : ""));
            sb.Append((!reverse && sortBy.Equals("date") ? " &darr;" : ""));
            sb.Append("</a></th>");

            // Creator
            sb.Append(@"<th><a rel=""nofollow"" href=""");
            UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?SortBy=Creator",
                              (!reverse && sortBy == SortingMethod.Creator ? "&amp;Reverse=1" : ""),
                              (Request["Cat"] != null ? "&amp;Cat=" + Tools.UrlEncode(Request["Cat"]) : ""),
                              "&amp;Page=", selectedPage.ToString());

            sb.Append(@""" title=""");
            sb.Append(Properties.Messages.SortByUser);
            sb.Append(@""">");
            sb.Append(Properties.Messages.CreatedBy);
            sb.Append((reverse && sortBy.Equals("creator") ? " &uarr;" : ""));
            sb.Append((!reverse && sortBy.Equals("creator") ? " &darr;" : ""));
            sb.Append("</a></th>");

            // Last author
            sb.Append(@"<th><a rel=""nofollow"" href=""");
            UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?SortBy=User",
                              (!reverse && sortBy == SortingMethod.User ? "&amp;Reverse=1" : ""),
                              (Request["Cat"] != null ? "&amp;Cat=" + Tools.UrlEncode(Request["Cat"]) : ""),
                              "&amp;Page=", selectedPage.ToString());

            sb.Append(@""" title=""");
            sb.Append(Properties.Messages.SortByUser);
            sb.Append(@""">");
            sb.Append(Properties.Messages.ModifiedBy);
            sb.Append((reverse && sortBy.Equals("user") ? " &uarr;" : ""));
            sb.Append((!reverse && sortBy.Equals("user") ? " &darr;" : ""));
            sb.Append("</a></th>");

            // Categories
            sb.Append("<th>");
            sb.Append(Properties.Messages.Categories);
            sb.Append("</th>");

            sb.Append("</tr>");
            sb.Append("</thead><tbody>");

            foreach (SortingGroup key in sortedPages.Keys)
            {
                List <ExtendedPageInfo> pageList = sortedPages[key];
                for (int i = 0; i < pageList.Count; i++)
                {
                    if (i == 0)
                    {
                        // Add group header
                        sb.Append(@"<tr class=""tablerow"">");
                        if (sortBy == SortingMethod.Title)
                        {
                            sb.AppendFormat("<td colspan=\"7\"><b>{0}</b></td>", key.Label);
                        }
                        else if (sortBy == SortingMethod.Creation)
                        {
                            sb.AppendFormat("<td colspan=\"2\"></td><td colspan=\"5\"><b>{0}</b></td>", key.Label);
                        }
                        else if (sortBy == SortingMethod.DateTime)
                        {
                            sb.AppendFormat("<td colspan=\"3\"></td><td colspan=\"4\"><b>{0}</b></td>", key.Label);
                        }
                        else if (sortBy == SortingMethod.Creator)
                        {
                            sb.AppendFormat("<td colspan=\"4\"></td><td colspan=\"3\"><b>{0}</b></td>", key.Label);
                        }
                        else if (sortBy == SortingMethod.User)
                        {
                            sb.AppendFormat("<td colspan=\"5\"></td><td colspan=\"2\"><b>{0}</b></td>", key.Label);
                        }
                        sb.Append("</tr>");
                    }

                    sb.Append(@"<tr class=""tablerow");
                    if ((i + 1) % 2 == 0)
                    {
                        sb.Append("alternate");
                    }
                    sb.Append(@""">");

                    // Page title
                    sb.Append(@"<td>");
                    sb.Append(@"<a href=""");
                    UrlTools.BuildUrl(currentWiki, sb, Tools.UrlEncode(pageList[i].PageContent.FullName), GlobalSettings.PageExtension);
                    sb.Append(@""">");
                    sb.Append(pageList[i].Title);
                    sb.Append("</a>");
                    sb.Append("</td>");

                    // Message count
                    sb.Append(@"<td>");
                    int msg = pageList[i].MessageCount;
                    if (msg > 0)
                    {
                        sb.Append(@"<a href=""");
                        UrlTools.BuildUrl(currentWiki, sb, Tools.UrlEncode(pageList[i].PageContent.FullName), GlobalSettings.PageExtension, "?Discuss=1");
                        sb.Append(@""" title=""");
                        sb.Append(Properties.Messages.Discuss);
                        sb.Append(@""">");
                        sb.Append(msg.ToString());
                        sb.Append("</a>");
                    }
                    else
                    {
                        sb.Append("&nbsp;");
                    }
                    sb.Append("</td>");

                    // Creation date/time
                    sb.Append(@"<td>");
                    sb.Append(Preferences.AlignWithTimezone(currentWiki, pageList[i].CreationDateTime).ToString(Settings.GetDateTimeFormat(currentWiki)) + "&nbsp;");
                    sb.Append("</td>");

                    // Mod. date/time
                    sb.Append(@"<td>");
                    sb.Append(Preferences.AlignWithTimezone(currentWiki, pageList[i].PageContent.LastModified).ToString(Settings.GetDateTimeFormat(currentWiki)) + "&nbsp;");
                    sb.Append("</td>");

                    // Creator
                    sb.Append(@"<td>");
                    sb.Append(Users.UserLink(currentWiki, pageList[i].Creator));
                    sb.Append("</td>");

                    // Last author
                    sb.Append(@"<td>");
                    sb.Append(Users.UserLink(currentWiki, pageList[i].LastAuthor));
                    sb.Append("</td>");

                    // Categories
                    CategoryInfo[] cats = Pages.GetCategoriesForPage(pageList[i].PageContent);
                    sb.Append(@"<td>");
                    if (cats.Length == 0)
                    {
                        sb.Append(@"<a href=""");
                        UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?Cat=-");
                        sb.Append(@""">");
                        sb.Append(Properties.Messages.NC);
                        sb.Append("</a>");
                    }
                    else
                    {
                        for (int k = 0; k < cats.Length; k++)
                        {
                            sb.Append(@"<a href=""");
                            UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?Cat=", Tools.UrlEncode(cats[k].FullName));
                            sb.Append(@""">");
                            sb.Append(NameTools.GetLocalName(cats[k].FullName));
                            sb.Append("</a>");
                            if (k != cats.Length - 1)
                            {
                                sb.Append(", ");
                            }
                        }
                    }
                    sb.Append("</td>");

                    sb.Append("</tr>");
                }
            }
            sb.Append("</tbody>");
            sb.Append("</table>");

            Literal lbl = new Literal();

            lbl.Text = sb.ToString();
            pnlPageList.Controls.Clear();
            pnlPageList.Controls.Add(lbl);
        }
Example #4
0
        /// <summary>
        /// Sets the content and visibility of all toolbar links.
        /// </summary>
        /// <param name="canEdit">A value indicating whether the current user can edit the page.</param>
        /// <param name="canViewDiscussion">A value indicating whether the current user can view the page discussion.</param>
        /// <param name="canPostMessages">A value indicating whether the current user can post messages in the page discussion.</param>
        /// <param name="canDownloadAttachments">A value indicating whether the current user can download attachments.</param>
        /// <param name="canRollback">A value indicating whether the current user can rollback the page.</param>
        /// <param name="canAdmin">A value indicating whether the current user can perform at least one administration task.</param>
        /// <param name="canSetPerms">A value indicating whether the current user can set page permissions.</param>
        private void SetupToolbarLinks(bool canEdit, bool canViewDiscussion, bool canPostMessages,
                                       bool canDownloadAttachments, bool canRollback, bool canAdmin, bool canSetPerms)
        {
            lblDiscussLink.Visible = !discussMode && !viewCodeMode && canViewDiscussion;
            if (lblDiscussLink.Visible)
            {
                lblDiscussLink.Text = string.Format(@"<a id=""DiscussLink"" title=""{0}"" href=""{3}?Discuss=1"">{1} ({2})</a>",
                                                    Properties.Messages.Discuss, Properties.Messages.Discuss, Pages.GetMessageCount(currentPage),
                                                    UrlTools.BuildUrl(NameTools.GetLocalName(currentPage.FullName), Settings.PageExtension));
            }

            lblEditLink.Visible = Settings.EnablePageToolbar && !discussMode && !viewCodeMode && canEdit;
            if (lblEditLink.Visible)
            {
                lblEditLink.Text = string.Format(@"<a id=""EditLink"" title=""{0}"" href=""{1}"">{2}</a>",
                                                 Properties.Messages.EditThisPage,
                                                 UrlTools.BuildUrl("Edit.aspx?Page=", Tools.UrlEncode(currentPage.FullName)),
                                                 Properties.Messages.Edit);
            }

            if (Settings.EnablePageToolbar && Settings.EnableViewPageCodeFeature)
            {
                lblViewCodeLink.Visible = !discussMode && !viewCodeMode && !canEdit;
                if (lblViewCodeLink.Visible)
                {
                    lblViewCodeLink.Text = string.Format(@"<a id=""ViewCodeLink"" title=""{0}"" href=""{2}?Code=1"">{1}</a>",
                                                         Properties.Messages.ViewPageCode, Properties.Messages.ViewPageCode,
                                                         UrlTools.BuildUrl(NameTools.GetLocalName(currentPage.FullName), Settings.PageExtension));
                }
            }
            else
            {
                lblViewCodeLink.Visible = false;
            }

            lblHistoryLink.Visible = Settings.EnablePageToolbar && !discussMode && !viewCodeMode;
            if (lblHistoryLink.Visible)
            {
                lblHistoryLink.Text = string.Format(@"<a id=""HistoryLink"" title=""{0}"" href=""{1}"">{2}</a>",
                                                    Properties.Messages.ViewPageHistory,
                                                    UrlTools.BuildUrl("History.aspx?Page=", Tools.UrlEncode(currentPage.FullName)),
                                                    Properties.Messages.History);
            }

            int attachmentCount = GetAttachmentCount();

            lblAttachmentsLink.Visible = canDownloadAttachments && !discussMode && !viewCodeMode && attachmentCount > 0;
            if (lblAttachmentsLink.Visible)
            {
                lblAttachmentsLink.Text = string.Format(@"<a id=""PageAttachmentsLink"" title=""{0}"" href=""#"" onclick=""javascript:return __ToggleAttachmentsMenu(event.clientX, event.clientY);"">{1}</a>",
                                                        Properties.Messages.Attachments, Properties.Messages.Attachments);
            }
            attachmentViewer.Visible = lblAttachmentsLink.Visible;

            int bakCount = GetBackupCount();

            lblAdminToolsLink.Visible = Settings.EnablePageToolbar && !discussMode && !viewCodeMode &&
                                        ((canRollback && bakCount > 0) || canAdmin || canSetPerms);
            if (lblAdminToolsLink.Visible)
            {
                lblAdminToolsLink.Text = string.Format(@"<a id=""AdminToolsLink"" title=""{0}"" href=""#"" onclick=""javascript:return __ToggleAdminToolsMenu(event.clientX, event.clientY);"">{1}</a>",
                                                       Properties.Messages.AdminTools, Properties.Messages.Admin);

                if (canRollback && bakCount > 0)
                {
                    lblRollbackPage.Text = string.Format(@"<a href=""AdminPages.aspx?Rollback={0}"" onclick=""javascript:return __RequestConfirm();"" title=""{1}"">{2}</a>",
                                                         Tools.UrlEncode(currentPage.FullName),
                                                         Properties.Messages.RollbackThisPage, Properties.Messages.Rollback);
                }
                else
                {
                    lblRollbackPage.Visible = false;
                }

                if (canAdmin)
                {
                    lblAdministratePage.Text = string.Format(@"<a href=""AdminPages.aspx?Admin={0}"" title=""{1}"">{2}</a>",
                                                             Tools.UrlEncode(currentPage.FullName),
                                                             Properties.Messages.AdministrateThisPage, Properties.Messages.Administrate);
                }
                else
                {
                    lblAdministratePage.Visible = false;
                }

                if (canSetPerms)
                {
                    lblSetPagePermissions.Text = string.Format(@"<a href=""AdminPages.aspx?Perms={0}"" title=""{1}"">{2}</a>",
                                                               Tools.UrlEncode(currentPage.FullName),
                                                               Properties.Messages.SetPermissionsForThisPage, Properties.Messages.Permissions);
                }
                else
                {
                    lblSetPagePermissions.Visible = false;
                }
            }

            lblPostMessageLink.Visible = discussMode && !viewCodeMode && canPostMessages;
            if (lblPostMessageLink.Visible)
            {
                lblPostMessageLink.Text = string.Format(@"<a id=""PostReplyLink"" title=""{0}"" href=""{1}"">{2}</a>",
                                                        Properties.Messages.PostMessage,
                                                        UrlTools.BuildUrl("Post.aspx?Page=", Tools.UrlEncode(currentPage.FullName)),
                                                        Properties.Messages.PostMessage);
            }

            lblBackLink.Visible = discussMode || viewCodeMode;
            if (lblBackLink.Visible)
            {
                lblBackLink.Text = string.Format(@"<a id=""BackLink"" title=""{0}"" href=""{1}"">{2}</a>",
                                                 Properties.Messages.Back,
                                                 UrlTools.BuildUrl(Tools.UrlEncode(currentPage.FullName), Settings.PageExtension, "?NoRedirect=1"),
                                                 Properties.Messages.Back);
            }
        }
Example #5
0
        public void PrintCat(string currentWiki)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<ul>");
            sb.Append(@"<li><a href=""");
            UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?Cat=-");
            sb.Append(@""">");
            sb.Append(Properties.Messages.UncategorizedPages);
            sb.Append("</a> (");
            sb.Append(Pages.GetUncategorizedPages(currentWiki, currentNamespace).Length.ToString());
            sb.Append(")");
            sb.Append(@" - <small><a href=""");
            UrlTools.BuildUrl(currentWiki, sb, "RSS.aspx?Category=-");
            sb.Append(@""" title=""");
            sb.Append(Properties.Messages.RssForThisCategory);
            sb.Append(@""">RSS</a> - <a href=""");
            UrlTools.BuildUrl(currentWiki, sb, "RSS.aspx?Discuss=1&amp;Category=-");
            sb.Append(@""" title=""");
            sb.Append(Properties.Messages.RssForThisCategoryDiscussion);
            sb.Append(@""">");
            sb.Append(Properties.Messages.DiscussionsRss);
            sb.Append("</a>");
            sb.Append("</small>");
            sb.Append("</li></ul><br />");

            sb.Append("<ul>");

            List <CategoryInfo> categories = Pages.GetCategories(currentWiki, currentNamespace);

            for (int i = 0; i < categories.Count; i++)
            {
                if (categories[i].Pages.Length > 0)
                {
                    sb.Append(@"<li>");
                    sb.Append(@"<a href=""");
                    UrlTools.BuildUrl(currentWiki, sb, "AllPages.aspx?Cat=", Tools.UrlEncode(categories[i].FullName));
                    sb.Append(@""">");
                    sb.Append(NameTools.GetLocalName(categories[i].FullName));
                    sb.Append("</a> (");
                    sb.Append(categories[i].Pages.Length.ToString());
                    sb.Append(")");
                    sb.Append(@" - <small><a href=""");
                    UrlTools.BuildUrl(currentWiki, sb, "RSS.aspx?Category=", Tools.UrlEncode(categories[i].FullName));
                    sb.Append(@""" title=""");
                    sb.Append(Properties.Messages.RssForThisCategory);
                    sb.Append(@""">RSS</a> - <a href=""");
                    UrlTools.BuildUrl(currentWiki, sb, "RSS.aspx?Discuss=1&amp;Category=", Tools.UrlEncode(categories[i].FullName));
                    sb.Append(@""" title=""");
                    sb.Append(Properties.Messages.RssForThisCategoryDiscussion);
                    sb.Append(@""">");
                    sb.Append(Properties.Messages.DiscussionsRss);
                    sb.Append("</a>");
                    sb.Append("</small>");
                    sb.Append("</li>");
                }
                else
                {
                    sb.Append(@"<li><i>");
                    sb.Append(NameTools.GetLocalName(categories[i].FullName));
                    sb.Append("</i></li>");
                }
            }
            sb.Append("</ul>");
            lblCatList.Text = sb.ToString();
        }
Example #6
0
        /// <summary>
        /// Migrates <b>all</b> the data from a Pages Provider to another one.
        /// </summary>
        /// <param name="source">The source Provider.</param>
        /// <param name="destination">The destination Provider.</param>
        public static void MigratePagesStorageProviderData(IPagesStorageProviderV30 source, IPagesStorageProviderV30 destination)
        {
            // Move Snippets
            Snippet[] snippets = source.GetSnippets( );
            for (int i = 0; i < snippets.Length; i++)
            {
                destination.AddSnippet(snippets[i].Name, snippets[i].Content);
                source.RemoveSnippet(snippets[i].Name);
            }

            // Move Content Templates
            ContentTemplate[] templates = source.GetContentTemplates( );
            for (int i = 0; i < templates.Length; i++)
            {
                destination.AddContentTemplate(templates[i].Name, templates[i].Content);
                source.RemoveContentTemplate(templates[i].Name);
            }

            // Create namespaces
            NamespaceInfo[] namespaces        = source.GetNamespaces( );
            NamespaceInfo[] createdNamespaces = new NamespaceInfo[namespaces.Length];
            for (int i = 0; i < namespaces.Length; i++)
            {
                createdNamespaces[i] = destination.AddNamespace(namespaces[i].Name);
            }

            List <NamespaceInfo> sourceNamespaces = new List <NamespaceInfo>( );

            sourceNamespaces.Add(null);
            sourceNamespaces.AddRange(namespaces);

            int currentNamespaceIndex = 0;

            foreach (NamespaceInfo currentNamespace in sourceNamespaces)
            {
                // Load all nav paths now to avoid problems with missing pages from source provider
                // after the pages have been moved already
                NavigationPath[] sourceNavPaths = source.GetNavigationPaths(currentNamespace);

                // Copy categories (removed from source later)
                CategoryInfo[] sourceCats = source.GetCategories(currentNamespace);
                for (int i = 0; i < sourceCats.Length; i++)
                {
                    destination.AddCategory(NameTools.GetNamespace(sourceCats[i].FullName), NameTools.GetLocalName(sourceCats[i].FullName));
                }

                // Move Pages
                PageInfo[] pages = source.GetPages(currentNamespace);
                for (int i = 0; i < pages.Length; i++)
                {
                    // Create Page
                    PageInfo newPage = destination.AddPage(NameTools.GetNamespace(pages[i].FullName),
                                                           NameTools.GetLocalName(pages[i].FullName), pages[i].CreationDateTime);
                    if (newPage == null)
                    {
                        Log.LogEntry("Unable to move Page " + pages[i].FullName + " - Skipping", EntryType.Error, Log.SystemUsername);
                        continue;
                    }

                    // Get content and store it, without backup
                    PageContent c = source.GetContent(pages[i]);
                    destination.ModifyPage(newPage, c.Title, c.User, c.LastModified, c.Comment, c.Content, c.Keywords, c.Description, SaveMode.Normal);

                    // Move all the backups
                    int[] revs = source.GetBackups(pages[i]);
                    for (int k = 0; k < revs.Length; k++)
                    {
                        c = source.GetBackupContent(pages[i], revs[k]);
                        destination.SetBackupContent(c, revs[k]);
                    }

                    // Move all messages
                    Message[] messages = source.GetMessages(pages[i]);
                    destination.BulkStoreMessages(newPage, messages);

                    // Bind current page (find all proper categories, and use them to bind the page)
                    List <string> pageCats = new List <string>( );
                    for (int k = 0; k < sourceCats.Length; k++)
                    {
                        for (int z = 0; z < sourceCats[k].Pages.Length; z++)
                        {
                            if (sourceCats[k].Pages[z].Equals(newPage.FullName))
                            {
                                pageCats.Add(sourceCats[k].FullName);
                                break;
                            }
                        }
                    }
                    destination.RebindPage(newPage, pageCats.ToArray( ));

                    // Copy draft
                    PageContent draft = source.GetDraft(pages[i]);
                    if (draft != null)
                    {
                        destination.ModifyPage(newPage, draft.Title, draft.User, draft.LastModified,
                                               draft.Comment, draft.Content, draft.Keywords, draft.Description, SaveMode.Draft);
                    }

                    // Remove Page from source
                    source.RemovePage(pages[i]);                         // Also deletes the Messages
                }

                // Remove Categories from source
                for (int i = 0; i < sourceCats.Length; i++)
                {
                    source.RemoveCategory(sourceCats[i]);
                }

                // Move navigation paths
                List <PageInfo> newPages = new List <PageInfo>(destination.GetPages(currentNamespace == null ? null : createdNamespaces[currentNamespaceIndex]));
                for (int i = 0; i < sourceNavPaths.Length; i++)
                {
                    PageInfo[] tmp = new PageInfo[sourceNavPaths[i].Pages.Length];
                    for (int k = 0; k < tmp.Length; k++)
                    {
                        tmp[k] = newPages.Find(delegate(PageInfo p) { return(p.FullName == sourceNavPaths[i].Pages[k]); });
                    }
                    destination.AddNavigationPath(NameTools.GetNamespace(sourceNavPaths[i].FullName),
                                                  NameTools.GetLocalName(sourceNavPaths[i].FullName), tmp);
                    source.RemoveNavigationPath(sourceNavPaths[i]);
                }

                if (currentNamespace != null)
                {
                    // Set default page
                    PageInfo defaultPage = currentNamespace.DefaultPage == null ? null :
                                           newPages.Find(delegate(PageInfo p) { return(p.FullName == currentNamespace.DefaultPage.FullName); });
                    destination.SetNamespaceDefaultPage(createdNamespaces[currentNamespaceIndex], defaultPage);

                    // Remove namespace from source
                    source.RemoveNamespace(currentNamespace);

                    currentNamespaceIndex++;
                }
            }
        }
Example #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var context = this.Context;
            var request = context.Request;

            var currentNamespace = request.QueryString["namespace"] ?? string.Empty;
            var orphanOnly       = (request.QueryString["orphanOnly"] ?? string.Empty) == "true";
            var name             = request.QueryString["name"];
            var title            = request.QueryString["title"];
            var sortKey          = request.QueryString["sortKey"];
            var sortDesc         = (request.QueryString["sortKey"] ?? string.Empty) == "true";
            var pageIndex        = int.Parse(request.QueryString["pageIndex"] ?? "0");
            var pageSize         = int.Parse(request.QueryString["pageSize"] ?? "50");
            var incomingLink     = request.QueryString["incomingLink"];
            var outgoingLink     = request.QueryString["outgoingLink"];

            var action = request.QueryString["action"];
            var id     = request.QueryString["id"];

            var url = SetParameter(SetParameter(this.Request.Url.PathAndQuery, "action", null), "id", null);

            [email protected](new ListItem("<root>", "")
            {
                Selected = string.IsNullOrEmpty(currentNamespace)
            });
            [email protected](Pages.GetNamespaces().Select(n => new ListItem(n.Name, n.Name)
            {
                Selected = currentNamespace.Equals(n.Name)
            }).ToArray());

            this.sortKey.Items.AddRange(new[] {
                new ListItem("Nom", "name"),
                new ListItem("Titre", "title"),
                new ListItem("Dernière modification", "lastModified"),
                new ListItem("Création", "created"),
                new ListItem("Nombre de versions", "backupCount")
            });
            this.sortKey.Items.Cast <ListItem>().ForEach(x => x.Selected = (sortKey == x.Value));

            this.pageSize.Items.AddRange(new[] {
                new ListItem("30"),
                new ListItem("50"),
                new ListItem("100"),
                new ListItem("200"),
            });
            this.pageSize.Items.Cast <ListItem>().ForEach(x => x.Selected = (pageSize.ToString() == x.Value));

            this.orphanOnly.Checked = orphanOnly;
            this.title.Value        = title;
            this.name.Value         = name;

            /*
             * this.incomingLink.Value = incomingLink;
             * this.outgoingLink.Value = outgoingLink;
             *
             * this.firstLink.Visible = pageIndex > 0;
             * this.firstLink.HRef = this.SetParameter(url, "pageIndex", "0");
             * this.previousLink.Visible = pageIndex > 0;
             * this.previousLink.HRef = this.SetParameter(url, "pageIndex", (pageIndex - 1).ToString());
             * this.nextLink.HRef = this.SetParameter(url, "pageIndex", (pageIndex + 1).ToString());
             */

            switch (action)
            {
            case "del":
                this.DoDelete(id);
                break;
            }

            var nspace = Pages.GetNamespaces().FirstOrDefault(x => x.Name == currentNamespace);

            var filter = new FindPagesFilter()
            {
                Name      = name,
                Namespace = nspace,
                PageIndex = pageIndex,
                PageSize  = pageSize
            };

            IEnumerable <PageInfo> pages = null;

            if (orphanOnly)
            {
                pages = filter.ApplyOn(Pages.GetOrphanedPages(nspace));
            }
            else
            {
                pages = Pages.FindPages(filter).SelectMany(p => p);
            }

            var pagesData = pages.Select(p => new PageData
            {
                Info          = p,
                Content       = Content.GetPageContent(p, true),
                Creation      = p.Provider.GetBackupContent(p, 0),
                Backups       = p.Provider.GetBackups(p),
                IncomingLinks = Pages.GetPageIncomingLinks(p),
                OutgoingLinks = Pages.GetPageOutgoingLinks(p)
            }).ToList();

            var table = new StringBuilder();

            foreach (var page in pagesData)
            {
                table.Append("<tr>")
                .AppendFormat("<th><a href=\"{1}.ashx\">{0}</a></th>", NameTools.GetLocalName(page.Info.FullName), page.Info.FullName)
                .AppendFormat("<td>{0}</td>", page.Content.Title)
                .AppendFormat("<td class=\"center\">{0}</td>", page.Info.CreationDateTime.ToString("dd/MM/yyyy HH:mm"))
                .AppendFormat("<td class=\"center\">{0}</td>", page.Creation != null ? page.Creation.User : page.Content.User)
                .AppendFormat("<td class=\"center\">{0}</td>", page.HasBackups ? page.Content.LastModified.ToString("dd/MM/yyyy HH:mm") : "-")
                .AppendFormat("<td class=\"center\">{0}</td>", page.HasBackups ? page.Content.User : "******")
                .AppendFormat("<td class=\"center\">{0}</td>", page.Info.Provider.GetBackups(page.Info).Length + 1)
                .AppendFormat("<td class=\"center\">{0} / {1}</td>", page.IncomingLinks.Length, page.OutgoingLinks.Length)
                .Append("<td class=\"center\">")
                .AppendFormat("<a href=\"{0}\" class=\"delLink\">Suppr.</a>", this.SetParameter(this.SetParameter(url, "action", "del"), "id", page.Info.FullName))
                .Append("</td>")
                .Append("</tr>");
            }

            this.tableFooterRemark.Text = string.Format("{0} pages renvoyée(s)", pagesData.Count);

            this.tableBody.InnerHtml = table.ToString();
        }
Example #8
0
        public void MigratePagesStorageProviderData()
        {
            MockRepository mocks = new MockRepository();

            IPagesStorageProviderV30 source      = mocks.StrictMock <IPagesStorageProviderV30>();
            IPagesStorageProviderV30 destination = mocks.StrictMock <IPagesStorageProviderV30>();

            // Setup SOURCE -------------------------

            // Setup snippets
            Snippet s1 = new Snippet("S1", "Blah1", source);
            Snippet s2 = new Snippet("S2", "Blah2", source);

            Expect.Call(source.GetSnippets()).Return(new Snippet[] { s1, s2 });

            // Setup content templates
            ContentTemplate ct1 = new ContentTemplate("CT1", "Template 1", source);
            ContentTemplate ct2 = new ContentTemplate("CT2", "Template 2", source);

            Expect.Call(source.GetContentTemplates()).Return(new ContentTemplate[] { ct1, ct2 });

            // Setup namespaces
            NamespaceInfo ns1 = new NamespaceInfo("NS1", source, null);
            NamespaceInfo ns2 = new NamespaceInfo("NS2", source, null);

            Expect.Call(source.GetNamespaces()).Return(new NamespaceInfo[] { ns1, ns2 });

            // Setup pages
            PageInfo p1 = new PageInfo("Page", source, DateTime.Now);
            PageInfo p2 = new PageInfo(NameTools.GetFullName(ns1.Name, "Page"), source, DateTime.Now);
            PageInfo p3 = new PageInfo(NameTools.GetFullName(ns1.Name, "Page1"), source, DateTime.Now);

            Expect.Call(source.GetPages(null)).Return(new PageInfo[] { p1 });
            Expect.Call(source.GetPages(ns1)).Return(new PageInfo[] { p2, p3 });
            Expect.Call(source.GetPages(ns2)).Return(new PageInfo[0]);

            // Set default page for NS1
            ns1.DefaultPage = p2;

            // Setup categories/bindings
            CategoryInfo c1 = new CategoryInfo("Cat", source);

            c1.Pages = new string[] { p1.FullName };
            CategoryInfo c2 = new CategoryInfo(NameTools.GetFullName(ns1.Name, "Cat"), source);

            c2.Pages = new string[] { p2.FullName };
            CategoryInfo c3 = new CategoryInfo(NameTools.GetFullName(ns1.Name, "Cat1"), source);

            c3.Pages = new string[0];
            Expect.Call(source.GetCategories(null)).Return(new CategoryInfo[] { c1 });
            Expect.Call(source.GetCategories(ns1)).Return(new CategoryInfo[] { c2, c3 });
            Expect.Call(source.GetCategories(ns2)).Return(new CategoryInfo[0]);

            // Setup drafts
            PageContent d1 = new PageContent(p1, "Draft", "NUnit", DateTime.Now, "Comm", "Cont", new string[] { "k1", "k2" }, "Descr");

            Expect.Call(source.GetDraft(p1)).Return(d1);
            Expect.Call(source.GetDraft(p2)).Return(null);
            Expect.Call(source.GetDraft(p3)).Return(null);

            // Setup content
            PageContent ctn1 = new PageContent(p1, "Title1", "User1", DateTime.Now, "Comm1", "Cont1", null, "Descr1");
            PageContent ctn2 = new PageContent(p2, "Title2", "User2", DateTime.Now, "Comm2", "Cont2", null, "Descr2");
            PageContent ctn3 = new PageContent(p3, "Title3", "User3", DateTime.Now, "Comm3", "Cont3", null, "Descr3");

            Expect.Call(source.GetContent(p1)).Return(ctn1);
            Expect.Call(source.GetContent(p2)).Return(ctn2);
            Expect.Call(source.GetContent(p3)).Return(ctn3);

            // Setup backups
            Expect.Call(source.GetBackups(p1)).Return(new int[] { 0, 1 });
            Expect.Call(source.GetBackups(p2)).Return(new int[] { 0 });
            Expect.Call(source.GetBackups(p3)).Return(new int[0]);
            PageContent bak1_0 = new PageContent(p1, "K1_0", "U1_0", DateTime.Now, "", "Cont", null, null);
            PageContent bak1_1 = new PageContent(p1, "K1_1", "U1_1", DateTime.Now, "", "Cont", null, null);
            PageContent bak2_0 = new PageContent(p2, "K2_0", "U2_0", DateTime.Now, "", "Cont", null, null);

            Expect.Call(source.GetBackupContent(p1, 0)).Return(bak1_0);
            Expect.Call(source.GetBackupContent(p1, 1)).Return(bak1_1);
            Expect.Call(source.GetBackupContent(p2, 0)).Return(bak2_0);

            // Messages
            Message m1 = new Message(1, "User1", "Subject1", DateTime.Now, "Body1");

            m1.Replies = new Message[] { new Message(2, "User2", "Subject2", DateTime.Now, "Body2") };
            Message[] p1m = new Message[] { m1 };
            Message[] p2m = new Message[0];
            Message[] p3m = new Message[0];
            Expect.Call(source.GetMessages(p1)).Return(p1m);
            Expect.Call(source.GetMessages(p2)).Return(p2m);
            Expect.Call(source.GetMessages(p3)).Return(p3m);

            // Setup navigation paths
            NavigationPath n1 = new NavigationPath("N1", source);

            n1.Pages = new string[] { p1.FullName };
            NavigationPath n2 = new NavigationPath(NameTools.GetFullName(ns1.Name, "N1"), source);

            n2.Pages = new string[] { p2.FullName, p3.FullName };
            Expect.Call(source.GetNavigationPaths(null)).Return(new NavigationPath[] { n1 });
            Expect.Call(source.GetNavigationPaths(ns1)).Return(new NavigationPath[] { n2 });
            Expect.Call(source.GetNavigationPaths(ns2)).Return(new NavigationPath[0]);

            // Setup DESTINATION --------------------------

            // Snippets
            Expect.Call(destination.AddSnippet(s1.Name, s1.Content)).Return(new Snippet(s1.Name, s1.Content, destination));
            Expect.Call(source.RemoveSnippet(s1.Name)).Return(true);
            Expect.Call(destination.AddSnippet(s2.Name, s2.Content)).Return(new Snippet(s2.Name, s2.Content, destination));
            Expect.Call(source.RemoveSnippet(s2.Name)).Return(true);

            // Content templates
            Expect.Call(destination.AddContentTemplate(ct1.Name, ct1.Content)).Return(new ContentTemplate(ct1.Name, ct1.Name, destination));
            Expect.Call(source.RemoveContentTemplate(ct1.Name)).Return(true);
            Expect.Call(destination.AddContentTemplate(ct2.Name, ct2.Content)).Return(new ContentTemplate(ct2.Name, ct2.Name, destination));
            Expect.Call(source.RemoveContentTemplate(ct2.Name)).Return(true);

            // Namespaces
            NamespaceInfo ns1Out = new NamespaceInfo(ns1.Name, destination, null);
            NamespaceInfo ns2Out = new NamespaceInfo(ns2.Name, destination, null);

            Expect.Call(destination.AddNamespace(ns1.Name)).Return(ns1Out);
            Expect.Call(source.RemoveNamespace(ns1)).Return(true);
            Expect.Call(destination.AddNamespace(ns2.Name)).Return(ns2Out);
            Expect.Call(source.RemoveNamespace(ns2)).Return(true);

            // Pages/drafts/content/backups/messages
            PageInfo p1Out = new PageInfo(p1.FullName, destination, p1.CreationDateTime);

            Expect.Call(destination.AddPage(null, p1.FullName, p1.CreationDateTime)).Return(p1Out);
            Expect.Call(destination.ModifyPage(p1Out, ctn1.Title, ctn1.User, ctn1.LastModified, ctn1.Comment, ctn1.Content, ctn1.Keywords, ctn1.Description, SaveMode.Normal)).Return(true);
            Expect.Call(destination.ModifyPage(p1Out, d1.Title, d1.User, d1.LastModified, d1.Comment, d1.Content, d1.Keywords, d1.Description, SaveMode.Draft)).Return(true);
            Expect.Call(destination.SetBackupContent(bak1_0, 0)).Return(true);
            Expect.Call(destination.SetBackupContent(bak1_1, 1)).Return(true);
            Expect.Call(destination.BulkStoreMessages(p1Out, p1m)).Return(true);
            Expect.Call(source.RemovePage(p1)).Return(true);

            PageInfo p2Out = new PageInfo(p2.FullName, destination, p2.CreationDateTime);

            Expect.Call(destination.AddPage(NameTools.GetNamespace(p2.FullName), NameTools.GetLocalName(p2.FullName),
                                            p2.CreationDateTime)).Return(p2Out);
            Expect.Call(destination.ModifyPage(p2Out, ctn2.Title, ctn2.User, ctn2.LastModified, ctn2.Comment, ctn2.Content, ctn2.Keywords, ctn2.Description, SaveMode.Normal)).Return(true);
            Expect.Call(destination.SetBackupContent(bak2_0, 0)).Return(true);
            Expect.Call(destination.BulkStoreMessages(p2Out, p2m)).Return(true);
            Expect.Call(source.RemovePage(p2)).Return(true);

            PageInfo p3Out = new PageInfo(p3.FullName, destination, p3.CreationDateTime);

            Expect.Call(destination.AddPage(NameTools.GetNamespace(p3.FullName), NameTools.GetLocalName(p3.FullName),
                                            p3.CreationDateTime)).Return(p3Out);
            Expect.Call(destination.ModifyPage(p3Out, ctn3.Title, ctn3.User, ctn3.LastModified, ctn3.Comment, ctn3.Content, ctn3.Keywords, ctn3.Description, SaveMode.Normal)).Return(true);
            Expect.Call(destination.BulkStoreMessages(p3Out, p3m)).Return(true);
            Expect.Call(source.RemovePage(p3)).Return(true);

            // Categories/bindings
            CategoryInfo c1Out = new CategoryInfo(c1.FullName, destination);
            CategoryInfo c2Out = new CategoryInfo(c2.FullName, destination);
            CategoryInfo c3Out = new CategoryInfo(c3.FullName, destination);

            Expect.Call(destination.AddCategory(null, c1.FullName)).Return(c1Out);
            Expect.Call(destination.AddCategory(NameTools.GetNamespace(c2.FullName), NameTools.GetLocalName(c2.FullName))).Return(c2Out);
            Expect.Call(destination.AddCategory(NameTools.GetNamespace(c3.FullName), NameTools.GetLocalName(c3.FullName))).Return(c3Out);
            Expect.Call(destination.RebindPage(p1Out, new string[] { c1.FullName })).Return(true);
            Expect.Call(destination.RebindPage(p2Out, new string[] { c2.FullName })).Return(true);
            Expect.Call(destination.RebindPage(p3Out, new string[0])).Return(true);
            Expect.Call(source.RemoveCategory(c1)).Return(true);
            Expect.Call(source.RemoveCategory(c2)).Return(true);
            Expect.Call(source.RemoveCategory(c3)).Return(true);

            // Navigation paths
            NavigationPath n1Out = new NavigationPath(n1.FullName, destination);

            n1Out.Pages = n1.Pages;
            NavigationPath n2Out = new NavigationPath(n2.FullName, destination);

            n2Out.Pages = n2.Pages;

            Expect.Call(destination.AddNavigationPath(null, n1.FullName, new PageInfo[] { p1 })).Return(n1Out).Constraints(
                RMC.Is.Null(), RMC.Is.Equal(n1.FullName),
                RMC.Is.Matching <PageInfo[]>(delegate(PageInfo[] array) {
                return(array[0].FullName == p1.FullName);
            }));

            Expect.Call(destination.AddNavigationPath(NameTools.GetNamespace(n2.FullName), NameTools.GetLocalName(n2.FullName), new PageInfo[] { p2, p3 })).Return(n2Out).Constraints(
                RMC.Is.Equal(NameTools.GetNamespace(n2.FullName)), RMC.Is.Equal(NameTools.GetLocalName(n2.FullName)),
                RMC.Is.Matching <PageInfo[]>(delegate(PageInfo[] array) {
                return(array[0].FullName == p2.FullName && array[1].FullName == p3.FullName);
            }));

            Expect.Call(source.RemoveNavigationPath(n1)).Return(true);
            Expect.Call(source.RemoveNavigationPath(n2)).Return(true);

            Expect.Call(destination.SetNamespaceDefaultPage(ns1Out, p2Out)).Return(ns1Out);
            Expect.Call(destination.SetNamespaceDefaultPage(ns2Out, null)).Return(ns2Out);

            // Used for navigation paths
            Expect.Call(destination.GetPages(null)).Return(new PageInfo[] { p1Out });
            Expect.Call(destination.GetPages(ns1Out)).Return(new PageInfo[] { p2Out, p3Out });
            Expect.Call(destination.GetPages(ns2Out)).Return(new PageInfo[0]);

            mocks.Replay(source);
            mocks.Replay(destination);

            DataMigrator.MigratePagesStorageProviderData(source, destination);

            mocks.Verify(source);
            mocks.Verify(destination);
        }