using System; using System.Configuration; using System.Web; using System.Collections.Generic; using ScrewTurn.Wiki.PluginFramework; namespace ScrewTurn.Wiki { /// /// Contains the Contents. /// public static class Content { /// /// Gets a pseudo cache item value. /// /// The name of the item to retrieve the value of. /// The value of the item, or null. public static string GetPseudoCacheValue(string name) { return Cache.GetPseudoCacheValue(name); } /// /// Sets a pseudo cache item value, only if the content cache is enabled. /// /// The name of the item to store the value of. /// The value of the item. public static void SetPseudoCacheValue(string name, string value) { if(!Settings.DisableCache) { Cache.SetPseudoCacheValue(name, value); } } /// /// Clears the pseudo cache. /// public static void ClearPseudoCache() { Cache.ClearPseudoCache(); Redirections.Clear(); } /// /// Reads the Content of a Page. /// /// The Page. /// Specifies whether the page has to be cached or not. /// The Page Content. public static PageContent GetPageContent(PageInfo pageInfo, bool cached) { PageContent result = Cache.GetPageContent(pageInfo); if(result == null) { result = pageInfo.Provider.GetContent(pageInfo); if(result!= null && !result.IsEmpty()) { if(cached && !pageInfo.NonCached && !Settings.DisableCache) { Cache.SetPageContent(pageInfo, result); } } } // result should NEVER be null if(result == null) { Log.LogEntry("PageContent could not be retrieved for page " + pageInfo.FullName + " - returning empty", EntryType.Error, Log.SystemUsername); result = PageContent.GetEmpty(pageInfo); } return result; } /// /// Gets the formatted Page Content, properly handling content caching and the Formatting Pipeline. /// /// The Page to get the formatted Content of. /// Specifies whether the formatted content has to be cached or not. /// The formatted content. public static string GetFormattedPageContent(PageInfo page, bool cached) { string content = Cache.GetFormattedPageContent(page); if(content == null) { PageContent pg = GetPageContent(page, cached); string[] linkedPages; content = FormattingPipeline.FormatWithPhase1And2(pg.Content, false, FormattingContext.PageContent, page, out linkedPages); pg.LinkedPages = linkedPages; if(!pg.IsEmpty() && cached && !page.NonCached && !Settings.DisableCache) { Cache.SetFormattedPageContent(page, content); } } return FormattingPipeline.FormatWithPhase3(content, FormattingContext.PageContent, page); } /// /// Invalidates the cached Content of a Page. /// /// The Page to invalidate the cached content of. public static void InvalidatePage(PageInfo pageInfo) { Cache.RemovePage(pageInfo); Redirections.WipePageOut(pageInfo); } /// /// Invalidates all the cache Contents. /// public static void InvalidateAllPages() { Cache.ClearPageCache(); Redirections.Clear(); } } }