protected void rptNamespaces_DataBinding(object sender, EventArgs e) { string currentWiki = DetectWiki(); List <NamespaceInfo> namespaces = Pages.GetNamespaces(currentWiki); List <NamespaceRow> result = new List <NamespaceRow>(namespaces.Count); bool canSetPermissions = AdminMaster.CanManagePermissions(SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames(currentWiki)); PageContent defaultPage = Pages.FindPage(currentWiki, Settings.GetDefaultPage(currentWiki)); // Inject the root namespace as first entry, retrieving the default page in Settings result.Add(new NamespaceRow(new NamespaceInfo(RootName, defaultPage.Provider, defaultPage.FullName), Settings.GetTheme(currentWiki, null), Pages.GetPages(currentWiki, null).Count, Pages.GetCategories(currentWiki, null).Count, canSetPermissions, txtCurrentNamespace.Value == RootName)); foreach (NamespaceInfo ns in namespaces) { result.Add(new NamespaceRow(ns, Settings.GetTheme(currentWiki, ns.Name), Pages.GetPages(currentWiki, ns).Count, Pages.GetCategories(currentWiki, ns).Count, canSetPermissions, txtCurrentNamespace.Value == ns.Name)); } rptNamespaces.DataSource = result; }
/// <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 Page_Load(object sender, EventArgs e) { string currentWiki = Tools.DetectCurrentWiki(); Response.ClearContent(); Response.ContentType = "text/xml;charset=UTF-8"; Response.ContentEncoding = System.Text.UTF8Encoding.UTF8; string mainUrl = Settings.GetMainUrl(currentWiki); string rootDefault = Settings.GetDefaultPage(currentWiki).ToLowerInvariant(); using (XmlWriter writer = XmlWriter.Create(Response.OutputStream)) { writer.WriteStartDocument(); writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9"); writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi", "schemaLocation", null, "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd"); string user = SessionFacade.GetCurrentUsername(); string[] groups = SessionFacade.GetCurrentGroupNames(currentWiki); AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); foreach (PageContent page in Pages.GetPages(currentWiki, null)) { if (authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ReadPage, user, groups)) { WritePage(mainUrl, page.FullName, page.FullName.ToLowerInvariant() == rootDefault, writer); } } foreach (NamespaceInfo nspace in Pages.GetNamespaces(currentWiki)) { string nspaceDefault = nspace.DefaultPageFullName.ToLowerInvariant(); foreach (PageContent page in Pages.GetPages(currentWiki, nspace)) { if (authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ReadPage, user, groups)) { WritePage(mainUrl, page.FullName, page.FullName.ToLowerInvariant() == nspaceDefault, writer); } } } writer.WriteEndElement(); writer.WriteEndDocument(); } }
/// <summary> /// Determines whether a page is the default page of its namespace. /// </summary> /// <param name="pageFullName">The page full name.</param> /// <returns><c>true</c> if the page is the default namespace of its namespace, <c>false</c> otherwise.</returns> private bool IsDefaultPage(string pageFullName) { string localName, nspace; NameTools.ExpandFullName(pageFullName, out nspace, out localName); if (string.IsNullOrEmpty(nspace)) { return(localName.ToLowerInvariant() == Settings.GetDefaultPage(currentWiki).ToLowerInvariant()); } else { NamespaceInfo ns = Pages.FindNamespace(currentWiki, nspace); return(ns.DefaultPageFullName != null && ns.DefaultPageFullName.ToLowerInvariant() == pageFullName.ToLowerInvariant()); } }
/// <summary> /// Detects the correct <see cref="T:PageInfo"/> object associated to the current page using the <b>Page</b>, <b>NS</b> and <b>Wiki</b> parameters in the query string. /// </summary> /// <param name="loadDefault"><c>true</c> to load the default page of the specified namespace when <b>Page</b> is not specified, <c>false</c> otherwise.</param> /// <returns>If <b>Page</b> is specified and exists, the correct <see cref="T:PageInfo"/>, otherwise <c>null</c> if <b>loadDefault</b> is <c>false</c>, /// or the <see cref="T:PageInfo"/> object representing the default page of the specified namespace if <b>loadDefault</b> is <c>true</c>.</returns> public static string DetectCurrentPage(bool loadDefault) { string wiki = DetectCurrentWiki(); string nspace = HttpContext.Current.Request["NS"]; NamespaceInfo nsinfo = nspace != null?Pages.FindNamespace(wiki, nspace) : null; string page = HttpContext.Current.Request["Page"]; if (string.IsNullOrEmpty(page)) { if (loadDefault) { if (nsinfo == null) { page = Settings.GetDefaultPage(wiki); } else { page = nsinfo.DefaultPageFullName != null ? nsinfo.DefaultPageFullName : ""; } } else { return(null); } } string fullName = null; if (!page.StartsWith(nspace + ".")) { fullName = nspace + "." + page; } else { fullName = page; } fullName = fullName.Trim('.'); return(fullName); }
/// <summary> /// Gets the canonical URL tag for a page. /// </summary> /// <param name="requestUrl">The request URL.</param> /// <param name="currentPageFullName">The full name of the current page.</param> /// <param name="nspace">The namespace.</param> /// <returns>The canonical URL, or an empty string if <paramref name="requestUrl"/> is already canonical.</returns> public static string GetCanonicalUrlTag(string requestUrl, string currentPageFullName, NamespaceInfo nspace) { string url = ""; string currentWiki = DetectCurrentWiki(); if (nspace == null && currentPageFullName == Settings.GetDefaultPage(currentWiki)) { url = Settings.GetMainUrl(currentWiki).ToString(); } else { url = Settings.GetMainUrl(currentWiki).ToString().TrimEnd('/') + "/" + currentPageFullName + GlobalSettings.PageExtension; } // Case sensitive if (url == requestUrl) { return(""); } else { return("<link rel=\"canonical\" href=\"" + url + "\" />"); } }
/// <summary> /// Redirects to the default page of the current namespace and wiki. /// </summary> /// <param name="wiki">The wiki.</param> public static void RedirectHome(string wiki) { Redirect(BuildUrl(wiki, Settings.GetDefaultPage(wiki), GlobalSettings.PageExtension)); }
/// <summary> /// Performs all needed startup operations. /// </summary> public static void Startup() { // Load Host Host.Instance = new Host(); // Initialize MimeTypes MimeTypes.Init(); GlobalSettings.CanOverridePublicDirectory = false; // Initialize Collectors Collectors.InitCollectors(); Collectors.FileNames = new Dictionary <string, string>(10); // Load Global Config IGlobalSettingsStorageProviderV60 globalSettingsStorageProvider = ProviderLoader.LoadGlobalSettingsStorageProvider(ApplicationSettings.Instance.GlobalSettingsStorageProvider); Collectors.AddGlobalSettingsStorageProvider(globalSettingsStorageProvider.GetType(), Assembly.GetAssembly(globalSettingsStorageProvider.GetType())); globalSettingsStorageProvider.SetUp(Host.Instance, GetGlobalSettingsStorageProviderConfiguration()); globalSettingsStorageProvider.Dispose(); // Add StorageProviders, from WebConfig, to Collectors and Setup them ProviderLoader.LoadStorageProviders <ISettingsStorageProviderV60>(new List <StorageProvider>() { ApplicationSettings.Instance.SettingProvider }); ProviderLoader.LoadStorageProviders <IFilesStorageProviderV60>(ApplicationSettings.Instance.FilesProviders); ProviderLoader.LoadStorageProviders <IThemesStorageProviderV60>(ApplicationSettings.Instance.ThemesProviders); ProviderLoader.LoadStorageProviders <IUsersStorageProviderV60>(ApplicationSettings.Instance.UsersProviders); ProviderLoader.LoadStorageProviders <IPagesStorageProviderV60>(ApplicationSettings.Instance.PagesProviders); ProviderLoader.LoadStorageProviders <IIndexDirectoryProviderV60>(new List <StorageProvider>() { ApplicationSettings.Instance.IndexDirectoryProvider }); ProviderLoader.LoadAllFormatterProviders(); foreach (Configuration.Wiki wiki in Collectors.CollectorsBox.GlobalSettingsProvider.GetAllWikis()) { ISettingsStorageProviderV60 ssp = Collectors.CollectorsBox.GetSettingsProvider(wiki.WikiName); if (ssp.IsFirstApplicationStart()) { if (ssp.GetMetaDataItem(MetaDataItem.AccountActivationMessage, null) == "") { ssp.SetMetaDataItem(MetaDataItem.AccountActivationMessage, null, Defaults.AccountActivationMessageContent); } if (ssp.GetMetaDataItem(MetaDataItem.EditNotice, null) == "") { ssp.SetMetaDataItem(MetaDataItem.EditNotice, null, Defaults.EditNoticeContent); } if (ssp.GetMetaDataItem(MetaDataItem.Footer, null) == "") { ssp.SetMetaDataItem(MetaDataItem.Footer, null, Defaults.FooterContent); } if (ssp.GetMetaDataItem(MetaDataItem.Header, null) == "") { ssp.SetMetaDataItem(MetaDataItem.Header, null, Defaults.HeaderContent); } if (ssp.GetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null) == "") { ssp.SetMetaDataItem(MetaDataItem.PasswordResetProcedureMessage, null, Defaults.PasswordResetProcedureMessageContent); } if (ssp.GetMetaDataItem(MetaDataItem.Sidebar, null) == "") { ssp.SetMetaDataItem(MetaDataItem.Sidebar, null, Defaults.SidebarContent); } if (ssp.GetMetaDataItem(MetaDataItem.PageChangeMessage, null) == "") { ssp.SetMetaDataItem(MetaDataItem.PageChangeMessage, null, Defaults.PageChangeMessage); } if (ssp.GetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null) == "") { ssp.SetMetaDataItem(MetaDataItem.DiscussionChangeMessage, null, Defaults.DiscussionChangeMessage); } if (ssp.GetMetaDataItem(MetaDataItem.ApproveDraftMessage, null) == "") { ssp.SetMetaDataItem(MetaDataItem.ApproveDraftMessage, null, Defaults.ApproveDraftMessage); } } bool groupsCreated = VerifyAndCreateDefaultGroups(wiki.WikiName); if (groupsCreated) { // It is necessary to set default permissions for file management UserGroup administratorsGroup = Users.FindUserGroup(wiki.WikiName, Settings.GetAdministratorsGroup(wiki.WikiName)); UserGroup anonymousGroup = Users.FindUserGroup(wiki.WikiName, Settings.GetAnonymousGroup(wiki.WikiName)); UserGroup usersGroup = Users.FindUserGroup(wiki.WikiName, Settings.GetUsersGroup(wiki.WikiName)); SetAdministratorsGroupDefaultPermissions(wiki.WikiName, administratorsGroup); SetUsersGroupDefaultPermissions(wiki.WikiName, usersGroup); SetAnonymousGroupDefaultPermissions(wiki.WikiName, anonymousGroup); } // Create the Main Page, if needed if (Pages.FindPage(wiki.WikiName, Settings.GetDefaultPage(wiki.WikiName)) == null) { CreateMainPage(wiki.WikiName); } Log.LogEntry("Wiki " + wiki.WikiName + " is ready", EntryType.General, Log.SystemUsername, null); //Pages.RebuildPageLinks(Pages.GetPages(wiki.WikiName, null)); //foreach(ScrewTurn.Wiki.PluginFramework.NamespaceInfo nspace in Pages.GetNamespaces(wiki.WikiName)) { // Pages.RebuildPageLinks(Pages.GetPages(wiki.WikiName, nspace)); //} } Log.LogEntry("ScrewTurn Wiki is ready", EntryType.General, Log.SystemUsername, null); }
/// <summary> /// Creates the main page for the given wiki. /// </summary> /// <param name="wiki">The wiki.</param> private static void CreateMainPage(string wiki) { Pages.SetPageContent(wiki, null as string, Settings.GetDefaultPage(wiki), "Main Page", Log.SystemUsername, DateTime.UtcNow, "", Defaults.MainPageContent, null, null, SaveMode.Normal); }
/// <summary> /// Activates the page editor. /// </summary> private void ActivatePageEditor() { lblCurrentPage.Text = txtCurrentPage.Value; txtNewName.Text = NameTools.GetLocalName(txtCurrentPage.Value); // Enable/disable page sections PageContent page = Pages.FindPage(currentWiki, txtCurrentPage.Value); NamespaceInfo nspace = Pages.FindNamespace(currentWiki, NameTools.GetNamespace(page.FullName)); string currentUser = SessionFacade.GetCurrentUsername(); string[] currentGroups = SessionFacade.GetCurrentGroupNames(currentWiki); AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); bool canApproveReject = AdminMaster.CanApproveDraft(page.Provider.CurrentWiki, page.FullName, currentUser, currentGroups); bool canDeletePages = authChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.DeletePages, currentUser, currentGroups); bool canManageAllPages = authChecker.CheckActionForNamespace(nspace, Actions.ForNamespaces.ManagePages, currentUser, currentGroups); bool canManagePage = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManagePage, currentUser, currentGroups); bool canManageDiscussion = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManageDiscussion, currentUser, currentGroups); bool namespaceAvailable = PopulateTargetNamespaces(page); // Approve/reject // Rename // Migrate // Rollback // Delete Backups // Clear discussion // Delete pnlApproveRevision.Enabled = canApproveReject; pnlRename.Enabled = canDeletePages; pnlMigrate.Enabled = canManageAllPages && namespaceAvailable; pnlRollback.Enabled = canManagePage; pnlDeleteBackups.Enabled = canManagePage; pnlClearDiscussion.Enabled = canManageDiscussion; pnlDelete.Enabled = canDeletePages; // Disable rename, migrate, delete for default page NamespaceInfo currentNamespace = Pages.FindNamespace(currentWiki, lstNamespace.SelectedValue); string currentDefaultPage = currentNamespace != null ? currentNamespace.DefaultPageFullName : Settings.GetDefaultPage(currentWiki); if (txtCurrentPage.Value == currentDefaultPage) { btnRename.Enabled = false; btnMigrate.Enabled = false; btnDeletePage.Enabled = false; } LoadDraft(txtCurrentPage.Value); LoadBackups(txtCurrentPage.Value); btnRollback.Enabled = lstRevision.Items.Count > 0; btnDeleteBackups.Enabled = lstBackup.Items.Count > 0; pnlList.Visible = false; pnlEditPage.Visible = true; ClearResultLabels(); }
/// <summary> /// Loads the available pages and selects the current one. /// </summary> private void LoadDefaultPages() { // Populate default page, if there is a namespace selected if (!string.IsNullOrEmpty(txtCurrentNamespace.Value)) { string currentWiki = DetectWiki(); NamespaceInfo nspace = Pages.FindNamespace( currentWiki, txtCurrentNamespace.Value != RootName ? txtCurrentNamespace.Value : null); List <PageContent> pages = Pages.GetPages(currentWiki, nspace); string currentDefaultPage = nspace != null ? nspace.DefaultPageFullName : Settings.GetDefaultPage(currentWiki); lstDefaultPage.Items.Clear(); foreach (PageContent page in pages) { ListItem item = new ListItem(NameTools.GetLocalName(page.FullName), page.FullName); if (page.FullName == currentDefaultPage) { item.Selected = true; } lstDefaultPage.Items.Add(item); } } }