Exemplo n.º 1
0
        /// <summary>
        /// Loads Formatter Providers from an assembly.
        /// </summary>
        /// <param name="assembly">The path of the Assembly to load the Providers from.</param>
        public static int LoadFormatterProvidersFromAuto(string assembly)
        {
            Type[] forms;
            LoadFormatterProvidersFromAssembly(assembly, out forms);

            int count = 0;

            // Setup and add to the Collectors
            for (int i = 0; i < forms.Length; i++)
            {
                Collectors.AddPlugin(forms[i], Assembly.GetAssembly(forms[i]));
                foreach (Configuration.Wiki wiki in GlobalSettings.Provider.GetAllWikis())
                {
                    try {
                        SetUp <IFormatterProviderV50>(forms[i], Settings.GetProvider(wiki.WikiName).GetPluginConfiguration(forms[i].FullName));
                        SavePluginStatus(wiki.WikiName, forms[i].FullName, true);
                    }
                    catch (InvalidConfigurationException) {
                        SavePluginStatus(wiki.WikiName, forms[i].FullName, false);
                    }
                }
                count++;
            }

            return(count);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prints the header.
        /// </summary>
        public void PrintHeader()
        {
            string h = FormattingPipeline.FormatWithPhase1And2(currentWiki, Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.Header, currentNamespace),
                                                               false, FormattingContext.Header, currentPageFullName);

            lblHeaderDiv.Text = FormattingPipeline.FormatWithPhase3(currentWiki, h, FormattingContext.Header, currentPageFullName);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads all formatter providers from dlls.
        /// </summary>
        public static void LoadAllFormatterProviders()
        {
            string[] pluginAssemblies = GlobalSettings.Provider.ListPluginAssemblies();

            List <Type> forms = new List <Type>(2);

            for (int i = 0; i < pluginAssemblies.Length; i++)
            {
                Type[] f;
                LoadFormatterProvidersFromAssembly(pluginAssemblies[i], out f);
                forms.AddRange(f);
            }

            // Add to the Collectors and Setup
            for (int i = 0; i < forms.Count; i++)
            {
                Collectors.AddPlugin(forms[i], Assembly.GetAssembly(forms[i]));
                foreach (PluginFramework.Wiki wiki in GlobalSettings.Provider.GetAllWikis())
                {
                    try {
                        SetUp <IFormatterProviderV40>(forms[i], Settings.GetProvider(wiki.WikiName).GetPluginConfiguration(forms[i].FullName));
                        SavePluginStatus(wiki.WikiName, forms[i].FullName, true);
                    }
                    catch (InvalidConfigurationException) {
                        SavePluginStatus(wiki.WikiName, forms[i].FullName, false);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Prints the footer.
        /// </summary>
        public void PrintFooter()
        {
            string f = FormattingPipeline.FormatWithPhase1And2(currentWiki, Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.Footer, currentNamespace),
                                                               false, FormattingContext.Footer, null);

            lblFooterDiv.Text = FormattingPipeline.FormatWithPhase3(currentWiki, f, FormattingContext.Footer, null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets all the changes for the given wiki, sorted by date/time ascending.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        public static RecentChange[] GetAllChanges(string wiki)
        {
            RecentChange[] changes = Settings.GetProvider(wiki).GetRecentChanges();

            RecentChange[] myCopy = new RecentChange[changes.Length];
            Array.Copy(changes, myCopy, changes.Length);

            Array.Sort(myCopy, (x, y) => { return(x.DateTime.CompareTo(y.DateTime)); });

            return(myCopy);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Prints the page header and page footer.
        /// </summary>
        public void PrintPageHeaderAndFooter()
        {
            string h = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.PageHeader, currentNamespace);

            h = @"<div id=""PageInternalHeaderDiv"">" + FormattingPipeline.FormatWithPhase1And2(currentWiki, h, false, FormattingContext.PageHeader, currentPageFullName) + "</div>";

            lblPageHeaderDiv.Text = FormattingPipeline.FormatWithPhase3(currentWiki, h, FormattingContext.PageHeader, currentPageFullName);

            h = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.PageFooter, currentNamespace);
            h = @"<div id=""PageInternalFooterDiv"">" + FormattingPipeline.FormatWithPhase1And2(currentWiki, h, false, FormattingContext.PageFooter, currentPageFullName) + "</div>";

            lblPageFooterDiv.Text = FormattingPipeline.FormatWithPhase3(currentWiki, h, FormattingContext.PageFooter, currentPageFullName);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Prints the register notice.
        /// </summary>
        private void PrintRegisterNotice()
        {
            string n = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.RegisterNotice, null);

            if (!string.IsNullOrEmpty(n))
            {
                n = FormattingPipeline.FormatWithPhase1And2(currentWiki, n, false, FormattingContext.Other, null);
            }
            if (!string.IsNullOrEmpty(n))
            {
                lblRegisterDescription.Text = FormattingPipeline.FormatWithPhase3(currentWiki, n, FormattingContext.Other, null);
            }
        }
Exemplo n.º 8
0
        protected void btnCopyFrom_Click(object sender, EventArgs e)
        {
            MetaDataItem item = ButtonMetaDataItemMapping[txtCurrentButton.Value];

            if (Settings.IsMetaDataItemGlobal(item))
            {
                return;
            }

            string newValue = Settings.GetProvider(currentWiki).GetMetaDataItem(item, lstCopyFromNamespace.SelectedValue);

            editor.SetContent(newValue, Settings.GetUseVisualEditorAsDefault(currentWiki));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Finds a provider.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="typeName">The provider type name.</param>
        /// <param name="enabled">A value indicating whether the provider is enabled.</param>
        /// <returns>The provider, or <c>null</c>.</returns>
        public static IProviderV60 FindProvider(string wiki, string typeName, out bool enabled)
        {
            enabled = false;
            IProviderV60 prov = null;

            prov = CollectorsBox.FormatterProviderCollector.GetProvider(typeName, wiki);
            if (prov != null)
            {
                enabled = Settings.GetProvider(wiki).GetPluginStatus(typeName);
                return(prov);
            }

            return(null);
        }
Exemplo n.º 10
0
        protected void rptProviders_DataBinding(object sender, EventArgs e)
        {
            IFormatterProviderV40[] plugins = Collectors.CollectorsBox.FormatterProviderCollector.GetAllProviders(currentWiki);

            List <ProviderRow> result = new List <ProviderRow>(plugins.Length);

            for (int i = 0; i < plugins.Length; i++)
            {
                result.Add(new ProviderRow(plugins[i].Information,
                                           plugins[i].GetType().FullName,
                                           GetUpdateStatus(plugins[i].Information),
                                           !Settings.GetProvider(currentWiki).GetPluginStatus(plugins[i].GetType().FullName),
                                           txtCurrentProvider.Value == plugins[i].GetType().FullName));
            }

            rptProviders.DataSource = result;
        }
Exemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string currentWiki = DetectWiki();

            Page.Title = Properties.Messages.AccessDeniedTitle + " - " + Settings.GetWikiTitle(currentWiki);

            string n = Settings.GetProvider(currentWiki).GetMetaDataItem(MetaDataItem.AccessDeniedNotice, null);

            if (!string.IsNullOrEmpty(n))
            {
                n = FormattingPipeline.FormatWithPhase1And2(currentWiki, n, false, FormattingContext.Other, null);
            }
            if (!string.IsNullOrEmpty(n))
            {
                lblDescription.Text = FormattingPipeline.FormatWithPhase3(currentWiki, n, FormattingContext.Other, null);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Adds a new change.
 /// </summary>
 /// <param name="wiki">The wiki.</param>
 /// <param name="page">The page name.</param>
 /// <param name="title">The page title.</param>
 /// <param name="messageSubject">The message subject.</param>
 /// <param name="dateTime">The date/time.</param>
 /// <param name="user">The user.</param>
 /// <param name="change">The change.</param>
 /// <param name="descr">The description (optional).</param>
 public static void AddChange(string wiki, string page, string title, string messageSubject, DateTime dateTime, string user, Change change, string descr)
 {
     RecentChange[] allChanges = GetAllChanges(wiki);
     if (allChanges.Length > 0)
     {
         RecentChange lastChange = allChanges[allChanges.Length - 1];
         if (lastChange.Page == page && lastChange.Title == title &&
             lastChange.MessageSubject == messageSubject + "" &&
             lastChange.User == user &&
             lastChange.Change == change &&
             (dateTime - lastChange.DateTime).TotalMinutes <= 60)
         {
             // Skip this change
             return;
         }
     }
     Settings.GetProvider(wiki).AddRecentChange(page, title, messageSubject, dateTime, user, change, descr);
 }
Exemplo n.º 13
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            MetaDataItem item = ButtonMetaDataItemMapping[txtCurrentButton.Value];

            string tag = null;

            // These elements are global, all others are are namespace-specific
            if (!Settings.IsMetaDataItemGlobal(item))
            {
                tag = lstNamespace.SelectedValue;
            }

            Log.LogEntry("Metadata file change requested for " + item.ToString() +
                         (tag != null ? ", ns: " + tag : "") + lstNamespace.SelectedValue, EntryType.General, SessionFacade.CurrentUsername, currentWiki);

            Settings.GetProvider(currentWiki).SetMetaDataItem(item, tag, editor.GetContent());

            pnlEditor.Visible = false;
            pnlList.Visible   = true;
        }
Exemplo n.º 14
0
        protected void btn_Click(object sender, EventArgs e)
        {
            Control senderControl = sender as Control;

            txtCurrentButton.Value = senderControl.ID;

            MetaDataItem item = ButtonMetaDataItemMapping[senderControl.ID];

            bool markupOnly = WikiMarkupOnlyItems.Contains(item);

            string content = Settings.GetProvider(currentWiki).GetMetaDataItem(item, lstNamespace.SelectedValue);

            editor.SetContent(content, !markupOnly && Settings.GetUseVisualEditorAsDefault(currentWiki));

            editor.VisualVisible  = !markupOnly;
            editor.PreviewVisible = !markupOnly;
            editor.ToolbarVisible = !markupOnly;

            pnlList.Visible   = false;
            pnlEditor.Visible = true;

            // Load namespaces for content copying
            lstCopyFromNamespace.Items.Clear();
            string currentNamespace = lstNamespace.SelectedValue;

            if (!string.IsNullOrEmpty(currentNamespace))
            {
                lstCopyFromNamespace.Items.Add(new ListItem("<root>", ""));
            }
            List <NamespaceInfo> namespaces = Pages.GetNamespaces(currentWiki);

            foreach (NamespaceInfo ns in namespaces)
            {
                if (currentNamespace != ns.Name)
                {
                    lstCopyFromNamespace.Items.Add(new ListItem(ns.Name, ns.Name));
                }
            }
            pnlInlineTools.Visible = lstCopyFromNamespace.Items.Count > 0 && !Settings.IsMetaDataItemGlobal(item);
        }
Exemplo n.º 15
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (!Settings.UsersCanRegister(currentWiki))
            {
                return;
            }

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

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

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

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

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

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

            lblResult.CssClass  = "resultok";
            lblResult.Text      = "<br /><br />" + Properties.Messages.AccountCreated;
            btnRegister.Enabled = false;
            pnlRegister.Visible = false;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Loads all formatter providers from dlls.
        /// </summary>
        public static void LoadAllFormatterProviders()
        {
            string[] pluginAssemblies = GlobalSettings.Provider.ListPluginAssemblies();

            List <Type> forms = new List <Type>(2);

            for (int i = 0; i < pluginAssemblies.Length; i++)
            {
                Type[] f;
                LoadFormatterProvidersFromAssembly(pluginAssemblies[i], out f);
                forms.AddRange(f);
            }

            // Add to the Collectors and Setup
            for (int i = 0; i < forms.Count; i++)
            {
                Collectors.AddPlugin(forms[i], Assembly.GetAssembly(forms[i]));
                foreach (Configuration.Wiki wiki in GlobalSettings.Provider.GetAllWikis())
                {
                    try
                    {
                        SetUp <IFormatterProviderV50>(forms[i],
                                                      Settings.GetProvider(wiki.WikiName).GetPluginConfiguration(forms[i].FullName));
                        SavePluginStatus(wiki.WikiName, forms[i].FullName, true);
                    }
                    catch (InvalidConfigurationException)
                    {
                        SavePluginStatus(wiki.WikiName, forms[i].FullName, false);
                    }
                    catch (Exception exception)
                    {
                        SavePluginStatus(wiki.WikiName, forms[i].FullName, false);
                        Log.LogEntry(String.Format("Unable to load provider " + forms[i].FullName + " ({0}).", exception.Message), EntryType.Error, Log.SystemUsername, wiki.WikiName);
                    }
                }
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Loads the plugin configuration.
 /// </summary>
 /// <param name="wiki">The wiki.</param>
 /// <param name="typeName">The Type Name of the plugin.</param>
 /// <returns>The configuration string.</returns>
 public static string LoadPluginConfiguration(string wiki, string typeName)
 {
     return(Settings.GetProvider(wiki).GetPluginConfiguration(typeName));
 }
Exemplo n.º 18
0
        /// <summary>
        /// Updates all the providers.
        /// </summary>
        /// <returns>The number of updated DLLs.</returns>
        public int UpdateAll()
        {
            Log.LogEntry("Starting automatic providers update", EntryType.General, Log.SystemUsername, null);

            int updatedDlls = 0;

            foreach (IFormatterProviderV40 plugin in plugins)
            {
                if (string.IsNullOrEmpty(plugin.Information.UpdateUrl))
                {
                    continue;
                }

                string       newVersion;
                string       newDllUrl;
                UpdateStatus status = Tools.GetUpdateStatus(plugin.Information.UpdateUrl,
                                                            plugin.Information.Version, out newVersion, out newDllUrl);

                if (status == UpdateStatus.NewVersionFound && !string.IsNullOrEmpty(newDllUrl))
                {
                    // Update is possible

                    // Case insensitive check
                    if (!visitedUrls.Contains(newDllUrl.ToLowerInvariant()))
                    {
                        string dllName = null;

                        if (!fileNamesForProviders.TryGetValue(plugin.GetType().FullName, out dllName))
                        {
                            Log.LogEntry("Could not determine DLL name for provider " + plugin.GetType().FullName, EntryType.Error, Log.SystemUsername, null);
                            continue;
                        }

                        // Download DLL and install
                        if (DownloadAndUpdateDll(plugin, newDllUrl, dllName))
                        {
                            visitedUrls.Add(newDllUrl.ToLowerInvariant());
                            updatedDlls++;
                            foreach (PluginFramework.Wiki wiki in globalSettingsProvider.GetAllWikis())
                            {
                                ProviderLoader.SetUp <IFormatterProviderV40>(plugin.GetType(), Settings.GetProvider(wiki.WikiName).GetPluginConfiguration(plugin.GetType().FullName));
                            }
                        }
                    }
                    else
                    {
                        // Skip DLL (already updated)
                        Log.LogEntry("Skipping provider " + plugin.GetType().FullName + ": DLL already updated", EntryType.General, Log.SystemUsername, null);
                    }
                }
            }

            Log.LogEntry("Automatic providers update completed: updated " + updatedDlls.ToString() + " DLLs", EntryType.General, Log.SystemUsername, null);

            return(updatedDlls);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Gets all the included files for the HTML Head, such as CSS, JavaScript and Icon pluginAssemblies, for a wiki and namespace.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="nspace">The namespace (<c>null</c> for the root).</param>
        /// <returns>The includes.</returns>
        public static string GetIncludes(string wiki, string nspace)
        {
            StringBuilder result    = new StringBuilder(300);
            string        nameTheme = Settings.GetTheme(wiki, nspace);

            result.Append(GetJavaScriptIncludes());
            List <string> cssList = Themes.ListThemeFiles(wiki, nameTheme, ".css");
            string        firstChunk;

            if (cssList != null)
            {
                foreach (string cssFile in cssList)
                {
                    if (Path.GetFileName(cssFile).IndexOf("_") != -1)
                    {
                        firstChunk = Path.GetFileName(cssFile).Substring(0, Path.GetFileName(cssFile).IndexOf("_")).ToLowerInvariant();
                        if (firstChunk.Equals("screen") || firstChunk.Equals("print") || firstChunk.Equals("all") ||
                            firstChunk.Equals("aural") || firstChunk.Equals("braille") || firstChunk.Equals("embossed") ||
                            firstChunk.Equals("handheld") || firstChunk.Equals("projection") || firstChunk.Equals("tty") || firstChunk.Equals("tv"))
                        {
                            result.Append(@"<link rel=""stylesheet"" media=""" + firstChunk + @""" href=""" + cssFile + @""" type=""text/css"" />" + "\n");
                        }
                        else
                        {
                            result.Append(@"<link rel=""stylesheet"" href=""" + cssFile + @""" type=""text/css"" />" + "\n");
                        }
                    }
                    else
                    {
                        result.Append(@"<link rel=""stylesheet"" href=""" + cssFile + @""" type=""text/css"" />" + "\n");
                    }
                }
            }
            List <string> customEditorCss = Themes.ListThemeFiles(wiki, nameTheme, "Editor.css");

            if (customEditorCss != null && customEditorCss.Count > 0)
            {
                result.AppendFormat(@"<link rel=""stylesheet"" href=""{0}"" type=""text/css"" />" + "\n", customEditorCss[0]);
            }
            else
            {
                result.Append(@"<link rel=""stylesheet"" href=""Themes/Editor.css"" type=""text/css"" />" + "\n");
            }
            // OpenSearch
            result.AppendFormat(@"<link rel=""search"" href=""Search.aspx?OpenSearch=1"" type=""application/opensearchdescription+xml"" title=""{0}"" />", Settings.GetWikiTitle(wiki) + " - Search");

            List <string> jsFiles = Themes.ListThemeFiles(wiki, nameTheme, ".js");

            if (jsFiles != null)
            {
                foreach (string jsFile in jsFiles)
                {
                    result.Append(@"<script src=""" + jsFile + @""" type=""text/javascript""></script>" + "\n");
                }
            }
            List <string> iconsList = Themes.ListThemeFiles(wiki, nameTheme, "Icon.");

            if (iconsList != null)
            {
                string[] icons = iconsList.ToArray();

                if (icons.Length > 0)
                {
                    result.Append(@"<link rel=""shortcut icon"" href=""" + icons[0] + @""" type=""");
                    switch (icons[0].Substring(icons[0].LastIndexOf('.')).ToLowerInvariant())
                    {
                    case ".ico":
                        result.Append("image/x-icon");
                        break;

                    case ".gif":
                        result.Append("image/gif");
                        break;

                    case ".png":
                        result.Append("image/png");
                        break;
                    }
                    result.Append(@""" />" + "\n");
                }
            }
            // Include HTML Head
            result.Append(Settings.GetProvider(wiki).GetMetaDataItem(MetaDataItem.HtmlHead, nspace));
            return(result.ToString());
        }
Exemplo n.º 20
0
        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();
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Returns a value specifying whether or not a Provider is disabled.
 /// </summary>
 /// <param name="wiki">The wiki.</param>
 /// <param name="typeName">The Type Name of the Provider.</param>
 /// <returns>True if the Provider is disabled.</returns>
 public static bool IsPluginDisabled(string wiki, string typeName)
 {
     return(!Settings.GetProvider(wiki).GetPluginStatus(typeName));
 }
Exemplo n.º 22
0
 /// <summary>
 /// Saves the Status of a Provider.
 /// </summary>
 /// <param name="wiki">The wiki.</param>
 /// <param name="typeName">The Type Name of the Provider.</param>
 /// <param name="enabled">A value specifying whether or not the Provider is enabled.</param>
 public static void SavePluginStatus(string wiki, string typeName, bool enabled)
 {
     Settings.GetProvider(wiki).SetPluginStatus(typeName, enabled);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Saves the Configuration data of a Provider.
 /// </summary>
 /// <param name="wiki">The wiki.</param>
 /// <param name="typeName">The Type Name of the Provider.</param>
 /// <param name="config">The Configuration data to save.</param>
 public static void SavePluginConfiguration(string wiki, string typeName, string config)
 {
     Settings.GetProvider(wiki).SetPluginConfiguration(typeName, config);
 }
Exemplo n.º 24
0
        protected void rptProviders_ItemCommand(object sender, CommandEventArgs e)
        {
            txtCurrentProvider.Value = e.CommandArgument as string;

            if (e.CommandName == "Select")
            {
                bool         enabled;
                IProviderV40 provider = GetCurrentProvider(out enabled);

                pnlProviderDetails.Visible = true;
                lblProviderName.Text       = provider.Information.Name + " (" + provider.Information.Version + ")";
                string dll = provider.GetType().Assembly.FullName;
                lblProviderDll.Text         = dll.Substring(0, dll.IndexOf(",")) + ".dll";
                txtConfigurationString.Text = ProviderLoader.LoadPluginConfiguration(currentWiki, provider.GetType().FullName);
                if (provider.ConfigHelpHtml != null)
                {
                    lblProviderConfigHelp.Text = provider.ConfigHelpHtml;
                }
                else
                {
                    lblProviderConfigHelp.Text = Properties.Messages.NoConfigurationRequired;
                }

                lblResult.CssClass = "";
                lblResult.Text     = "";
                rptProviders.DataBind();
            }
            else if (e.CommandName == "Disable")
            {
                bool         enabled;
                IProviderV40 prov = GetCurrentProvider(out enabled);
                Log.LogEntry("Deactivation requested for Provider " + prov.Information.Name, EntryType.General, SessionFacade.CurrentUsername, currentWiki);

                ProviderLoader.SavePluginStatus(currentWiki, txtCurrentProvider.Value, false);

                lblResult.CssClass = "resultok";
                lblResult.Text     = Properties.Messages.ProviderDisabled;

                ResetEditor();
                rptProviders.DataBind();
            }
            else if (e.CommandName == "Enable")
            {
                bool         enabled;
                IProviderV40 prov = GetCurrentProvider(out enabled);
                Log.LogEntry("Activation requested for provider provider " + prov.Information.Name, EntryType.General, SessionFacade.CurrentUsername, currentWiki);

                try {
                    ProviderLoader.SetUp <IFormatterProviderV40>(prov.GetType(), Settings.GetProvider(currentWiki).GetPluginConfiguration(prov.GetType().FullName));
                    ProviderLoader.SavePluginStatus(currentWiki, txtCurrentProvider.Value, true);
                    lblResult.CssClass = "resultok";
                    lblResult.Text     = Properties.Messages.ProviderEnabled;
                }
                catch (InvalidConfigurationException) {
                    ProviderLoader.SavePluginStatus(currentWiki, txtCurrentProvider.Value, false);
                    lblResult.CssClass = "resulterror";
                    lblResult.Text     = Properties.Messages.ProviderRejectedConfiguration;
                }

                ResetEditor();
                rptProviders.DataBind();
            }
        }