/// <summary> /// Loads the content configuration. /// </summary> /// <param name="currentWiki">The wiki.</param> private void LoadContentConfig(string currentWiki) { string[] theme = Settings.GetTheme(currentWiki, null).Split(new char[] { '|' }); ThemeRootSelector.SelectedProvider = theme[0]; ThemeRootSelector.SelectedThemes = theme[1]; PopulateMainPages(Settings.GetDefaultPage(currentWiki)); txtDateTimeFormat.Text = Settings.GetDateTimeFormat(currentWiki); PopulateDateTimeFormats(); PopulateLanguages(Settings.GetDefaultLanguage(currentWiki)); PopulateTimeZones(Settings.GetDefaultTimezone(currentWiki)); txtMaxRecentChangesToDisplay.Text = Settings.GetMaxRecentChangesToDisplay(currentWiki).ToString(); lstRssFeedsMode.SelectedIndex = -1; switch (Settings.GetRssFeedsMode(currentWiki)) { case RssFeedsMode.FullText: lstRssFeedsMode.SelectedIndex = 0; break; case RssFeedsMode.Summary: lstRssFeedsMode.SelectedIndex = 1; break; case RssFeedsMode.Disabled: lstRssFeedsMode.SelectedIndex = 2; break; } chkEnableDoubleClickEditing.Checked = Settings.GetEnableDoubleClickEditing(currentWiki); chkEnableSectionEditing.Checked = Settings.GetEnableSectionEditing(currentWiki); chkEnableSectionAnchors.Checked = Settings.GetEnableSectionAnchors(currentWiki); chkEnablePageToolbar.Checked = Settings.GetEnablePageToolbar(currentWiki); chkEnableViewPageCode.Checked = Settings.GetEnableViewPageCodeFeature(currentWiki); chkEnablePageInfoDiv.Checked = Settings.GetEnablePageInfoDiv(currentWiki); chkEnableBreadcrumbsTrail.Checked = !Settings.GetDisableBreadcrumbsTrail(currentWiki); chkAutoGeneratePageNames.Checked = Settings.GetAutoGeneratePageNames(currentWiki); chkProcessSingleLineBreaks.Checked = Settings.GetProcessSingleLineBreaks(currentWiki); chkUseVisualEditorAsDefault.Checked = Settings.GetUseVisualEditorAsDefault(currentWiki); if (Settings.GetKeptBackupNumber(currentWiki) == -1) { txtKeptBackupNumber.Text = ""; } else { txtKeptBackupNumber.Text = Settings.GetKeptBackupNumber(currentWiki).ToString(); } chkDisplayGravatars.Checked = Settings.GetDisplayGravatars(currentWiki); txtListSize.Text = Settings.GetListSize(currentWiki).ToString(); }
protected void btnSave_Click(object sender, EventArgs e) { bool wasVisible = pnlPageName.Visible; pnlPageName.Visible = true; if (!wasVisible && Settings.GetAutoGeneratePageNames(currentWiki) && txtName.Enabled) { txtName.Text = GenerateAutoName(txtTitle.Text); } txtName.Text = txtName.Text.Trim(); Page.Validate("nametitle"); Page.Validate("captcha"); if (!Page.IsValid) { if (!rfvTitle.IsValid || !rfvName.IsValid || !cvName1.IsValid || !cvName2.IsValid) { pnlPageName.Visible = true; pnlManualName.Visible = false; } return; } pnlPageName.Visible = wasVisible; // Check permissions if (currentPage == null) { // Check permissions for creating new pages if (!canCreateNewPages) { UrlTools.Redirect("AccessDenied.aspx"); } } else { // Check permissions for editing current page if (!canEdit && !canEditWithApproval) { UrlTools.Redirect("AccessDenied.aspx"); } } chkMinorChange.Visible = true; chkSaveAsDraft.Visible = true; // Verify edit with approval if (!canEdit && canEditWithApproval) { chkSaveAsDraft.Checked = true; } // Check for scripts (Administrators can always add SCRIPT tags) if (!SessionFacade.GetCurrentGroupNames(currentWiki).Contains(Settings.GetAdministratorsGroup(currentWiki)) && !Settings.GetScriptTagsAllowed(currentWiki)) { Regex r = new Regex(@"\<script.*?\>", RegexOptions.Compiled | RegexOptions.IgnoreCase); if (r.Match(editor.GetContent()).Success) { lblResult.Text = @"<span style=""color: #FF0000;"">" + Properties.Messages.ScriptDetected + "</span>"; return; } } bool redirect = true; if (sender == btnSaveAndContinue) { redirect = false; } lblResult.Text = ""; lblResult.CssClass = ""; string username = ""; if (SessionFacade.LoginKey == null) { username = Request.UserHostAddress; } else { username = SessionFacade.CurrentUsername; } IPagesStorageProviderV40 provider = FindAppropriateProvider(); // Create list of selected categories List <CategoryInfo> categories = new List <CategoryInfo>(); for (int i = 0; i < lstCategories.Items.Count; i++) { if (lstCategories.Items[i].Selected) { CategoryInfo cat = Pages.FindCategory(currentWiki, lstCategories.Items[i].Value); // Sanity check if (cat.Provider == provider) { categories.Add(cat); } } } txtComment.Text = txtComment.Text.Trim(); txtDescription.Text = txtDescription.Text.Trim(); SaveMode saveMode = SaveMode.Backup; if (chkSaveAsDraft.Checked) { saveMode = SaveMode.Draft; } if (chkMinorChange.Checked) { saveMode = SaveMode.Normal; } if (txtName.Enabled) { // Find page, if inexistent create it Log.LogEntry("Page update requested for " + txtName.Text, EntryType.General, username, currentWiki); string nspace = DetectNamespaceInfo() != null?DetectNamespaceInfo().Name : null; PageContent pg = Pages.FindPage(NameTools.GetFullName(DetectNamespace(), txtName.Text), provider); if (pg == null) { saveMode = SaveMode.Normal; pg = Pages.SetPageContent(currentWiki, nspace, txtName.Text, provider, txtTitle.Text, username, DateTime.UtcNow, txtComment.Text, editor.GetContent(), GetKeywords(), txtDescription.Text, saveMode); attachmentManager.CurrentPage = pg; } else { Pages.SetPageContent(currentWiki, nspace, txtName.Text, provider, txtTitle.Text, username, DateTime.UtcNow, txtComment.Text, editor.GetContent(), GetKeywords(), txtDescription.Text, saveMode); } // Save categories binding Pages.Rebind(pg, categories.ToArray()); // If not a draft, remove page draft if (saveMode != SaveMode.Draft) { Pages.DeleteDraft(pg.FullName, pg.Provider); isDraft = false; } else { isDraft = true; } ManageDraft(); lblResult.CssClass = "resultok"; lblResult.Text = Properties.Messages.PageSaved; // This is a new page, so only who has page management permissions can execute this code // No notification must be sent for drafts awaiting approval if (redirect) { Collisions.CancelEditingSession(pg, username); string target = UrlTools.BuildUrl(currentWiki, Tools.UrlEncode(txtName.Text), GlobalSettings.PageExtension, "?NoRedirect=1"); UrlTools.Redirect(target); } else { // Disable PageName, because the name cannot be changed anymore txtName.Enabled = false; pnlManualName.Visible = false; } } else { // Used for redirecting to a specific section after editing it string anchor = ""; if (currentPage == null) { currentPage = Pages.FindPage(currentWiki, NameTools.GetFullName(DetectNamespace(), txtName.Text)); } // Save data Log.LogEntry("Page update requested for " + currentPage.FullName, EntryType.General, username, currentWiki); if (!isDraft && currentSection != -1) { StringBuilder sb = new StringBuilder(currentPage.Content.Length); int start, len; ExtractSection(currentPage.Content, currentSection, out start, out len, out anchor); if (start > 0) { sb.Append(currentPage.Content.Substring(0, start)); } sb.Append(editor.GetContent()); if (start + len < currentPage.Content.Length - 1) { sb.Append(currentPage.Content.Substring(start + len)); } Pages.SetPageContent(currentPage.Provider.CurrentWiki, NameTools.GetNamespace(currentPage.FullName), NameTools.GetLocalName(currentPage.FullName), txtTitle.Text, username, DateTime.UtcNow, txtComment.Text, sb.ToString(), GetKeywords(), txtDescription.Text, saveMode); } else { Pages.SetPageContent(currentPage.Provider.CurrentWiki, NameTools.GetNamespace(currentPage.FullName), NameTools.GetLocalName(currentPage.FullName), txtTitle.Text, username, DateTime.UtcNow, txtComment.Text, editor.GetContent(), GetKeywords(), txtDescription.Text, saveMode); } // Save Categories binding Pages.Rebind(currentPage, categories.ToArray()); // If not a draft, remove page draft if (saveMode != SaveMode.Draft) { Pages.DeleteDraft(currentPage.FullName, currentPage.Provider); isDraft = false; } else { isDraft = true; } ManageDraft(); lblResult.CssClass = "resultok"; lblResult.Text = Properties.Messages.PageSaved; // This code is executed every time the page is saved, even when "Save & Continue" is clicked // This causes a draft approval notification to be sent multiple times for the same page, // but this is the only solution because the user might navigate away from the page after // clicking "Save & Continue" but not "Save" or "Cancel" - in other words, it is necessary // to take every chance to send a notification because no more chances might be available if (!canEdit && canEditWithApproval) { Pages.SendEmailNotificationForDraft(currentPage.Provider.CurrentWiki, currentPage.FullName, txtTitle.Text, txtComment.Text, username); } if (redirect) { Collisions.CancelEditingSession(currentPage, username); string target = UrlTools.BuildUrl(currentWiki, Tools.UrlEncode(currentPage.FullName), GlobalSettings.PageExtension, "?NoRedirect=1", (!string.IsNullOrEmpty(anchor) ? ("#" + anchor + "_" + currentSection.ToString()) : "")); UrlTools.Redirect(target); } } }
protected void Page_Load(object sender, EventArgs e) { currentWiki = DetectWiki(); Page.Title = Properties.Messages.EditTitle + " - " + Settings.GetWikiTitle(currentWiki); lblEditNotice.Text = Formatter.FormatPhase3(currentWiki, Formatter.Format(currentWiki, Settings.GetProvider(currentWiki).GetMetaDataItem( MetaDataItem.EditNotice, DetectNamespace()), false, FormattingContext.Other, null), FormattingContext.Other, null); // Prepare page unload warning string ua = Request.UserAgent; if (!string.IsNullOrEmpty(ua)) { ua = ua.ToLowerInvariant(); StringBuilder 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.GetAutoGeneratePageNames(currentWiki)) { 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(currentWiki, name); // If page already exists, load the content and disable page name, // otherwise pre-fill page name if (currentPage != null) { keepAlive.CurrentPage = currentPage.FullName; // Look for a draft PageContent draftContent = Pages.GetDraft(currentPage); if (draftContent == null) { draftContent = currentPage; } 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(draftContent.Keywords); txtDescription.Text = draftContent.Description; txtName.Text = NameTools.GetLocalName(currentPage.FullName); txtName.Enabled = false; pnlPageName.Visible = false; pnlManualName.Visible = false; PopulateCategories(Pages.GetCategoriesForPage(currentPage)); txtTitle.Text = draftContent.Title; // Manage section, if appropriate (disable if draft) if (!isDraft && currentSection != -1) { int startIndex, len; string dummy = ""; ExtractSection(draftContent.Content, currentSection, out startIndex, out len, out dummy); editor.SetContent(draftContent.Content.Substring(startIndex, len), Settings.GetUseVisualEditorAsDefault(currentWiki)); } else { // Select default editor view (WikiMarkup or Visual) and populate content editor.SetContent(draftContent.Content, Settings.GetUseVisualEditorAsDefault(currentWiki)); } } } 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.GetUseVisualEditorAsDefault(currentWiki)); } } } else { if (!Page.IsPostBack) { chkMinorChange.Visible = false; chkSaveAsDraft.Visible = false; editor.SetContent(LoadTemplateIfAppropriate(), Settings.GetUseVisualEditorAsDefault(currentWiki)); } } // 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.GetDisableCaptchaControl(currentWiki); captcha.Visible = pnlCaptcha.Visible; // Moderation notice pnlApprovalRequired.Visible = !canEdit && canEditWithApproval; // Check and manage editing collisions ManageEditingCollisions(); if (!Page.IsPostBack) { ManageTemplatesDisplay(); // Display draft status ManageDraft(); } }