Contains the Contents.
Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            lblResult.CssClass = "";
            lblResult.Text     = "";

            Page.Validate();

            if (!Page.IsValid)
            {
                return;
            }

            Log.LogEntry("Wiki Configuration change requested", EntryType.General, SessionFacade.CurrentUsername);

            Settings.BeginBulkUpdate();

            // Save general configuration
            Settings.WikiTitle    = txtWikiTitle.Text;
            Settings.MainUrl      = txtMainUrl.Text;
            Settings.ContactEmail = txtContactEmail.Text;
            Settings.SenderEmail  = txtSenderEmail.Text;
            Settings.ErrorsEmails = GetErrorsEmails();
            Settings.SmtpServer   = txtSmtpServer.Text;

            txtSmtpPort.Text = txtSmtpPort.Text.Trim();
            if (txtSmtpPort.Text.Length > 0)
            {
                Settings.SmtpPort = int.Parse(txtSmtpPort.Text);
            }
            else
            {
                Settings.SmtpPort = -1;
            }

            if (txtUsername.Text.Length > 0)
            {
                Settings.SmtpUsername = txtUsername.Text;
                Settings.SmtpPassword = txtPassword.Text;
            }
            else
            {
                Settings.SmtpUsername = "";
                Settings.SmtpPassword = "";
            }
            Settings.SmtpSsl = chkEnableSslForSmtp.Checked;

            // Save content configuration
            Settings.SetTheme(null, lstRootTheme.SelectedValue);
            Settings.DefaultPage               = lstMainPage.SelectedValue;
            Settings.DateTimeFormat            = txtDateTimeFormat.Text;
            Settings.DefaultLanguage           = lstDefaultLanguage.SelectedValue;
            Settings.DefaultTimezone           = int.Parse(lstDefaultTimeZone.SelectedValue);
            Settings.MaxRecentChangesToDisplay = int.Parse(txtMaxRecentChangesToDisplay.Text);
            Settings.RssFeedsMode              = (RssFeedsMode)Enum.Parse(typeof(RssFeedsMode), lstRssFeedsMode.SelectedValue);
            Settings.EnableDoubleClickEditing  = chkEnableDoubleClickEditing.Checked;
            Settings.EnableSectionEditing      = chkEnableSectionEditing.Checked;
            Settings.EnableSectionAnchors      = chkEnableSectionAnchors.Checked;
            Settings.EnablePageToolbar         = chkEnablePageToolbar.Checked;
            Settings.EnableViewPageCodeFeature = chkEnableViewPageCode.Checked;
            Settings.EnablePageInfoDiv         = chkEnablePageInfoDiv.Checked;
            Settings.DisableBreadcrumbsTrail   = !chkEnableBreadcrumbsTrail.Checked;
            Settings.AutoGeneratePageNames     = chkAutoGeneratePageNames.Checked;
            Settings.ProcessSingleLineBreaks   = chkProcessSingleLineBreaks.Checked;
            Settings.UseVisualEditorAsDefault  = chkUseVisualEditorAsDefault.Checked;
            if (txtKeptBackupNumber.Text == "")
            {
                Settings.KeptBackupNumber = -1;
            }
            else
            {
                Settings.KeptBackupNumber = int.Parse(txtKeptBackupNumber.Text);
            }

            Settings.DisplayGravatars = chkDisplayGravatars.Checked;

            // Save security configuration
            Settings.UsersCanRegister = chkAllowUsersToRegister.Checked;
            Settings.UsernameRegex    = txtUsernameRegEx.Text;
            Settings.PasswordRegex    = txtPasswordRegEx.Text;
            AccountActivationMode mode = AccountActivationMode.Email;

            switch (lstAccountActivationMode.SelectedValue.ToLowerInvariant())
            {
            case "email":
                mode = AccountActivationMode.Email;
                break;

            case "admin":
                mode = AccountActivationMode.Administrator;
                break;

            case "auto":
                mode = AccountActivationMode.Auto;
                break;
            }
            Settings.AccountActivationMode    = mode;
            Settings.UsersGroup               = lstDefaultUsersGroup.SelectedValue;
            Settings.AdministratorsGroup      = lstDefaultAdministratorsGroup.SelectedValue;
            Settings.AnonymousGroup           = lstDefaultAnonymousGroup.SelectedValue;
            Settings.DisableCaptchaControl    = !chkEnableCaptchaControl.Checked;
            Settings.DisableConcurrentEditing = chkPreventConcurrentEditing.Checked;

            if (rdoNoModeration.Checked)
            {
                Settings.ChangeModerationMode = ChangeModerationMode.None;
            }
            else if (rdoRequirePageViewingPermissions.Checked)
            {
                Settings.ChangeModerationMode = ChangeModerationMode.RequirePageViewingPermissions;
            }
            else if (rdoRequirePageEditingPermissions.Checked)
            {
                Settings.ChangeModerationMode = ChangeModerationMode.RequirePageEditingPermissions;
            }

            Settings.AllowedFileTypes = GetAllowedFileExtensions();

            Settings.FileDownloadCountFilterMode = (FileDownloadCountFilterMode)Enum.Parse(typeof(FileDownloadCountFilterMode), lstFileDownloadCountFilterMode.SelectedValue);
            Settings.FileDownloadCountFilter     = txtFileDownloadCountFilter.Text.Replace(" ", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            Settings.MaxFileSize       = int.Parse(txtMaxFileSize.Text);
            Settings.ScriptTagsAllowed = chkAllowScriptTags.Checked;
            LoggingLevel level = LoggingLevel.AllMessages;

            if (rdoAllMessages.Checked)
            {
                level = LoggingLevel.AllMessages;
            }
            else if (rdoWarningsAndErrors.Checked)
            {
                level = LoggingLevel.WarningsAndErrors;
            }
            else if (rdoErrorsOnly.Checked)
            {
                level = LoggingLevel.ErrorsOnly;
            }
            else
            {
                level = LoggingLevel.DisableLog;
            }

            Settings.LoggingLevel = level;
            Settings.MaxLogSize   = int.Parse(txtMaxLogSize.Text);
            Settings.IpHostFilter = txtIpHostFilter.Text;

            // Save advanced configuration
            Settings.DisableAutomaticVersionCheck = !chkEnableAutomaticUpdateChecks.Checked;
            Settings.DisableCache = chkDisableCache.Checked;
            Settings.CacheSize    = int.Parse(txtCacheSize.Text);
            Settings.CacheCutSize = int.Parse(txtCacheCutSize.Text);
            Settings.EnableViewStateCompression = chkEnableViewStateCompression.Checked;
            Settings.EnableHttpCompression      = chkEnableHttpCompression.Checked;

            Settings.EndBulkUpdate();

            Content.InvalidateAllPages();
            Content.ClearPseudoCache();

            lblResult.CssClass = "resultok";
            lblResult.Text     = Properties.Messages.ConfigSaved;
        }