public TopicChange(QualifiedTopicRevision topic, DateTime created, DateTime modified, string author) { _topic = topic; _author = author; _created = created; _modified = modified; }
private void Page_Load(object sender, System.EventArgs e) { _topicString = Request.QueryString["topic"]; try { _diff = Convert.ToInt32(Request.QueryString["diff"]); } catch {} try { _oldid = Convert.ToInt32(Request.QueryString["oldid"]); } catch {} try { _requestedTopic = new QualifiedTopicRevision(_topicString); } catch {} if (_requestedTopic == null || _diff >= _oldid) { Response.Redirect("default.aspx"); } }
public void ControlPageTitle() { QualifiedTopicRevision top = new QualifiedTopicRevision("TitledTopic", Federation.DefaultNamespaceManager.Namespace); string t = TheLinkMaker.LinkToTopic(top); DocumentElement doc = TheBrowser.Navigate(t, true); Assert.AreEqual("This fat hen", doc.Title); }
public void ControlTopicBar() { QualifiedTopicRevision top = new QualifiedTopicRevision("TitledTopic", Federation.DefaultNamespaceManager.Namespace); string t = TheLinkMaker.LinkToTopic(top); DocumentElement doc = TheBrowser.Navigate(t, true); HTMLElement staticTopicBar = (HTMLElement)doc.GetElementByName("StaticTopicBar"); Assert.AreEqual("This fat hen", staticTopicBar.InnerText); }
public void CreateTestPage() { QualifiedTopicRevision top = new QualifiedTopicRevision("DummyPage", Federation.DefaultNamespaceManager.Namespace); bool exists; exists = Federation.TopicExists(top); Assert.IsTrue(!exists); string home = TheLinkMaker.LinkToTopic(top); DocumentElement doc = TheBrowser.Navigate(home, true); Assert.IsTrue(doc.Body.OuterHTML.IndexOf("Formatting Tips") > 0); InputElement text = (InputElement) doc.GetElementByName("Text1"); text.Value = "This is SoCool!"; ButtonElement save = (ButtonElement) doc.GetElementByName("SaveButton"); save.Click(true); // Make sure it actually got saved exists = Federation.TopicExists(top); Assert.IsTrue(exists); }
/// <summary> /// Answer the formatted text for a given topic, formatted using a given OutputFormat and possibly showing diffs /// with a specified revision /// </summary> /// <param name="topic">The topic</param> /// <param name="format">What format</param> /// <param name="showDiffs">true to show diffs</param> /// <param name="accumulator">composite cache rule in which to accumulate cache rules (ignored for diffs)</param> /// <returns></returns> public static string FormattedTopicWithSpecificDiffs(QualifiedTopicRevision topic, OutputFormat format, QualifiedTopicRevision diffWithThisVersion, Federation aFederation, LinkMaker lm) { // Setup a special link maker that knows what to make the edit links return to LinkMaker linker = lm.Clone(); linker.ReturnToTopicForEditLinks = topic; NamespaceManager relativeToBase = aFederation.NamespaceManagerForNamespace(topic.Namespace); WikiOutput output = WikiOutput.ForFormat(format, null); if (diffWithThisVersion != null) { ArrayList styledLines = new ArrayList(); IList leftLines; IList rightLines; using (TextReader srLeft = relativeToBase.TextReaderForTopic(topic.AsUnqualifiedTopicRevision())) { leftLines = MergeBehaviorLines(srLeft.ReadToEnd().Replace("\r", "").Split('\n')); } using (TextReader srRight = relativeToBase.TextReaderForTopic(diffWithThisVersion.AsUnqualifiedTopicRevision())) { rightLines = MergeBehaviorLines(srRight.ReadToEnd().Replace("\r", "").Split('\n')); } IEnumerable diffs = Diff.Compare(leftLines, rightLines); foreach (LineData ld in diffs) { LineStyle style = LineStyle.Unchanged; switch (ld.Type) { case LineType.Common: style = LineStyle.Unchanged; break; case LineType.LeftOnly: style = LineStyle.Add; break; case LineType.RightOnly: style = LineStyle.Delete; break; } styledLines.Add(new StyledLine(ld.Text, style)); } Format(topic, styledLines, output, relativeToBase, linker, relativeToBase.ExternalReferences, 0); } else { using (TextReader sr = relativeToBase.TextReaderForTopic(topic.AsUnqualifiedTopicRevision())) { Format(topic, sr.ReadToEnd(), output, relativeToBase, linker, relativeToBase.ExternalReferences, 0); } } return output.ToString(); }
/// <summary> /// Format a string of wiki content in a given OutputFormat with references all being relative to a given namespace /// </summary> /// <param name="topic">Topic context</param> /// <param name="input">The input wiki text</param> /// <param name="format">The desired output format</param> /// <param name="relativeToContentStore">References will be relative to this namespace</param> /// <param name="lm">Link maker (unless no relativeTo content base is provide)</param> /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param> /// <returns></returns> public static string FormattedString(QualifiedTopicRevision topic, string input, OutputFormat format, NamespaceManager relativeToContentStore, LinkMaker lm) { // TODO -- some of the cases in which this call happens actually *are* nested, even though the false arg // below says that they aren't. This causes scripts to be emitted multiple times -- should clean up. WikiOutput output = WikiOutput.ForFormat(format, null); ExternalReferencesMap ew; if (relativeToContentStore != null) { ew = relativeToContentStore.ExternalReferences; } else { ew = new ExternalReferencesMap(); } Format(topic, input, output, relativeToContentStore, lm, ew, 0); return output.ToString(); }
private string TipForTopic(TopicName topic) { QualifiedTopicRevision revision = new QualifiedTopicRevision(topic.LocalName, topic.Namespace); if (!Federation.HasPermission(revision, TopicPermission.Read)) { return "You do not have read permission on topic " + topic.DottedName; } string answer = Federation.GetTopicPropertyValue(revision, "Summary"); if (answer == "") answer = null; return answer; }
/// <summary> /// Create a new formatter for a string of input content. /// </summary> /// <param name="source">Input wiki string</param> /// <param name="output">Output object to which output is sent</param> /// <param name="namespaceManager">The ContentProviderChain that contains the wiki string text</param> /// <param name="maker">A link maker </param> /// <param name="external">External wiki map</param> /// <param name="headingLevelBase">Relative heading level</param> /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param> /// Formatter(QualifiedTopicRevision topic, string source, WikiOutput output, NamespaceManager namespaceManager, LinkMaker maker, ExternalReferencesMap external, int headingLevelBase) { _topic = topic; _source = SplitStringIntoStyledLines(source, LineStyle.Unchanged); _linkMaker = maker; NamespaceManager = namespaceManager; _output = output; _externalWikiMap = external; _headingLevelBase = headingLevelBase; }
// Constructors public TopicVersionInfo(Federation aFed, QualifiedTopicRevision name) { _topicVersionKey = name; _federation = aFed; }
protected string DoPage() { StringBuilder strBldr = new StringBuilder(); QualifiedTopicRevision newestTopicVersion = null; QualifiedTopicRevision oldTopicVersion = null; int counter = 0; IEnumerable changeList = Federation.GetTopicChanges(RequestedTopic.AsQualifiedTopicName()); strBldr.AppendLine("<div id=\"TopicBody\">"); strBldr.AppendLine("<div id=\"content\">"); strBldr.AppendLine("<a name=\"top\" id=\"contentTop\"></a>"); strBldr.AppendLine("<h1 class=\"firstHeading\">Compare two versions</h1>"); strBldr.AppendLine("<div id=\"bodyContent\">"); foreach (TopicChange change in changeList) { if (counter == _diff) { string newLocalName = change.DottedName.Substring(change.DottedName.IndexOf(".") + 1); string newNamespace = change.DottedName.Substring(0, change.DottedName.IndexOf(".")); newestTopicVersion = new QualifiedTopicRevision(newLocalName, newNamespace, change.Version); } else if (counter == _oldid) { string oldLocalName = change.DottedName.Substring(change.DottedName.IndexOf(".") + 1); string oldNamespace = change.DottedName.Substring(0, change.DottedName.IndexOf(".")); oldTopicVersion = new QualifiedTopicRevision(oldLocalName, oldNamespace, change.Version); break; } counter++; } if (newestTopicVersion != null && oldTopicVersion != null) { strBldr.AppendLine(@"<div id=""MainRegion"" class=""TopicBody""> <form method=""post"" action=""" + TheLinkMaker.LinkToQuicklink() + @"?QuickLinkNamespace=" + RequestedTopic.Namespace + @""" name=""QuickLinkForm""> <div id=""TopicBar"" title=""Click here to quickly jump to or create a topic"" class=""TopicBar"" onmouseover=""javascript:TopicBarMouseOver()"" onclick=""javascript:TopicBarClick(event)"" onmouseout=""javascript:TopicBarMouseOut()""> <div id=""StaticTopicBar"" class=""StaticTopicBar"" style=""display: block"">" + GetTitle() + @"</div> <div id=""DynamicTopicBar"" class=""DynamicTopicBar"" style=""display: none""> <!-- <input id=""TopicBarNamespace"" style=""display: none"" type=""text"" name=""QuickLinkNamespace""/> --> <input id=""TopicBarInputBox"" title=""Enter a topic here to go to or create"" class=""QuickLinkInput"" type=""text"" name=""QuickLink""/> <div class=""DynamicTopicBarHelp"">Enter a topic name to show or a new topic name to create; then press Enter</div> </div> </div> </form> "); string formattedBody = Federation.GetTopicFormattedContent(newestTopicVersion, oldTopicVersion); strBldr.AppendLine(formattedBody); strBldr.AppendLine("</div>"); } strBldr.AppendLine("</div>"); strBldr.AppendLine("</div>"); return strBldr.ToString(); }
private void FormatTest(string inputString, string outputString, QualifiedTopicRevision top) { string o1 = FormattedTestText(inputString, top); string o2 = outputString.Replace("\r", ""); if (o1 != o2) { Console.Error.WriteLine("Got : " + o1); Console.Error.WriteLine("Expected: " + o2); } Assert.AreEqual(o2, o1); }
private void FormattedTopicContainsTest(QualifiedTopicRevision top, string find) { FormatTestContains(FormattedTopic(top), find); }
private string FormattedTopic(QualifiedTopicRevision top) { return FormattedTestText(Federation.NamespaceManagerForTopic(top).Read(top.LocalName), top); }
private string FormattedTestText(string inputString, QualifiedTopicRevision top) { WikiOutput output = WikiOutput.ForFormat(OutputFormat.Testing, null); Formatter.Format(top, inputString, output, _namespaceManager, _lm, _externals, 0); string o = output.ToString(); string o1 = o.Replace("\r", ""); return o1; }
private string InternalGetHtmlForTopic(QualifiedTopicRevision topicName, string version) { if (version != null && version == topicName.Version) { return FlexWiki.Formatting.Formatter.FormattedTopic(topicName, OutputFormat.HTML, null, Federation, TheLinkMaker); } else { IEnumerable changeList; changeList = Federation.NamespaceManagerForTopic(topicName).AllChangesForTopic(topicName.LocalName); foreach (TopicChange change in changeList) { if (change.Version == version) { return FlexWiki.Formatting.Formatter.FormattedTopic(change.TopicRevision, OutputFormat.HTML, null, Federation, TheLinkMaker); } } return FlexWiki.Formatting.Formatter.FormattedTopic(topicName, OutputFormat.HTML, null, Federation, TheLinkMaker); } }
private void WriteNewTopic(QualifiedTopicRevision theTopic, string postedTopicText, string visitorIdentityString, string version) { QualifiedTopicRevision newVersionName = new QualifiedTopicRevision(theTopic.LocalName, theTopic.Namespace); newVersionName.Version = TopicRevision.NewVersionStringForUser(visitorIdentityString, Federation.TimeProvider); Federation.NamespaceManagerForTopic(newVersionName).WriteTopicAndNewVersion(newVersionName.LocalName, postedTopicText, visitorIdentityString); }
private static TopicChange TopicChangeFromName(QualifiedTopicRevision topic) { try { VersionInfo versionInfo = TopicRevision.ParseVersion(topic.Version); TopicChange change = new TopicChange(topic, versionInfo.Timestamp, versionInfo.Author); return change; } catch (Exception ex) { throw new Exception("Exception processing topic change " + topic.Version + " - " + ex.ToString()); } }
protected void DoPage() { QualifiedTopicRevision newestTopicVersion = null; QualifiedTopicRevision oldTopicVersion = null; int counter = 0; IEnumerable changeList = Federation.GetTopicChanges(RequestedTopic.AsQualifiedTopicName()); foreach (TopicChange change in changeList) { if (counter == _diff) { newestTopicVersion = new QualifiedTopicRevision(change.DottedName); } else if (counter == _oldid) { oldTopicVersion = new QualifiedTopicRevision(change.DottedName); break; } counter++; } if (newestTopicVersion != null && oldTopicVersion != null) { string script = @" <script type=""text/javascript"" language='javascript'> function TopicBarMouseOver() { TopicBar.className='TopicBarHover'; } function TopicBarMouseOut() { TopicBar.className='TopicBar'; } function IsEditing() { return DynamicTopicBar.style.display == 'block'; } function SetEditing(flag) { var isEditing = IsEditing(); if (isEditing == flag) return; isEditing = flag; if (isEditing) { StaticTopicBar.style.display = 'none'; DynamicTopicBar.style.display = 'block'; } else { StaticTopicBar.style.display = 'block'; DynamicTopicBar.style.display = 'none'; } } function BodyClick() { SetEditing(false); } function TopicBarClick(event) { event.cancelBubble = 'true'; if (IsEditing()) return; // Grab these dimensions before SetEditng() to get them before the control is hidden (thus h=0;w=0!) var staticWide = StaticTopicBar.offsetWidth; var staticHigh = StaticTopicBar.offsetHeight; SetEditing(true); DynamicTopicBar.left = TopicBar.offsetLeft; DynamicTopicBar.top = TopicBar.offsetTop; DynamicTopicBar.width = TopicBar.width; DynamicTopicBar.height = TopicBar.height; var tbi = tbinput(); tbi.left = DynamicTopicBar.left; tbi.top = DynamicTopicBar.top; tbi.width = staticWide; tbi.height = staticHigh; tbi.rawValue = ''; tbi.focus(); tbi.select(); } function tbinput() { return document.getElementById('TopicBarInputBox'); } </script> "; Response.Write(script); Response.Write(@"<div id='MainRegion' class='TopicBody'> <form method='post' action='" + TheLinkMaker.LinkToQuicklink() + @"?QuickLinkNamespace=" + RequestedTopic.Namespace + @"' name='QuickLinkForm'> <div id='TopicBar' title='Click here to quickly jump to or create a topic' class='TopicBar' onmouseover='javascript:TopicBarMouseOver()' onclick='javascript:TopicBarClick(event)' onmouseout='javascript:TopicBarMouseOut()'> <div id='StaticTopicBar' class='StaticTopicBar' style='display: block'>" + GetTitle() + @"</div> <div id='DynamicTopicBar' class='DynamicTopicBar' style='display: none'> <!-- <input id='TopicBarNamespace' style='display: none' type='text' name='QuickLinkNamespace'> --> <input id='TopicBarInputBox' title='Enter a topic here to go to or create' class='QuickLinkInput' type=""text"" name=""QuickLink""> <div class='DynamicTopicBarHelp'>Enter a topic name to show or a new topic name to create; then press Enter</div> </div> </div> </form> "); string formattedBody = Federation.GetTopicFormattedContent(newestTopicVersion, oldTopicVersion); Response.Write(formattedBody); Response.Write("</div>"); } }
/// <summary> /// A list of TopicChanges to a topic since a given date [sorted by date] /// </summary> /// <param name="topic">A given date</param> /// <param name="stamp">A non-null timestamp; changes before this time won't be included in the answer </param> /// <param name="rule">A composite cache rule to fill with rules that represented accumulated dependencies (or null)</param> /// <returns>Enumeration of TopicChanges</returns> public override TopicChangeCollection AllChangesForTopicSince(UnqualifiedTopicName topic, DateTime stamp) { TopicChangeCollection answer = new TopicChangeCollection(); SqlInfoForTopic[] infos = _sqlHelper.GetSqlTopicInfosForTopicSince(Namespace, topic.LocalName, stamp); ArrayList sortable = new ArrayList(); foreach (SqlInfoForTopic each in infos) { sortable.Add(new SqlInfoTopicData(each, Namespace)); } sortable.Sort(new TimeSort()); foreach (TopicData each in sortable) { if (each.LastModificationTime < stamp) { continue; } QualifiedTopicRevision name = new QualifiedTopicRevision(topic.LocalName, Namespace); name.Version = each.Version; TopicChange change = TopicChangeFromName(name); answer.Add(change); } return answer; }
private string IncludedTopic(TopicRevision topic, int headingLevelBase) { // TODO: how do we identify specific versions? [maybe this just works now? since versionids are a formal part of a wikiname???] // TODO: how do we show diffs? string ns = NamespaceManager.UnambiguousTopicNameFor(topic.LocalName).Namespace; NamespaceManager containingNamespaceManager = Federation.NamespaceManagerForNamespace(ns); QualifiedTopicRevision abs = new QualifiedTopicRevision(topic.LocalName, ns); string content = ""; if (containingNamespaceManager.HasPermission(new UnqualifiedTopicName(abs.LocalName), TopicPermission.Read)) { content = containingNamespaceManager.Read(abs.LocalName).TrimEnd(); } WikiOutput output = WikiOutput.ForFormat(_output.Format, Output); Formatter.Format(abs, content, output, NamespaceManager, LinkMaker(), _externalWikiMap, headingLevelBase); return output.ToString().Trim(); }
public string GetHtmlForTopicVersion(WireTypes.AbsoluteTopicName topicName, string version) { QualifiedTopicRevision atn = new QualifiedTopicRevision(topicName.Name, topicName.Namespace); return InternalGetHtmlForTopic(atn, version); }
/// <summary> /// Create a new formatter for an input list of StyledLines /// </summary> /// <param name="source">Input wiki content as a list of StyledLines</param> /// <param name="output">Output object to which output is sent</param> /// <param name="namespaceManager">The ContentProviderChain that contains the wiki string text</param> /// <param name="maker">A link maker </param> /// <param name="external">External wiki map</param> /// <param name="headingLevelBase">Relative heading level</param> /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param> /// Formatter(QualifiedTopicRevision topic, IList source, WikiOutput output, NamespaceManager namespaceManager, LinkMaker maker, ExternalReferencesMap external, int headingLevelBase) { _topic = topic; _source = source; _output = output; _linkMaker = maker; NamespaceManager = namespaceManager; _externalWikiMap = external; _headingLevelBase = headingLevelBase; }
public string GetTextForTopic(WireTypes.AbsoluteTopicName topicName) { string content = null; // OmarS: Do I need to check for Topic existence? QualifiedTopicRevision atn = new QualifiedTopicRevision(topicName.Name, topicName.Namespace); atn.Version = topicName.Version; if (Federation.TopicExists(atn)) { content = Federation.Read(atn); } if (content == null) { content = "[enter your text here]"; } return content; }
/// <summary> /// Format a given input string to the given output /// </summary>pre /// <param name="source">Input wiki content as a list of StyledLines</param> /// <param name="output">Output object to which output is sent</param> /// <param name="namespaceManager">The ContentProviderChain that contains the wiki string text</param> /// <param name="maker">A link maker </param> /// <param name="external">External wiki map</param> /// <param name="headingLevelBase">Relative heading level</param> /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param> /// public static void Format(QualifiedTopicRevision topic, IList source, WikiOutput output, NamespaceManager namespaceManager, LinkMaker maker, ExternalReferencesMap external, int headingLevelBase) { Formatter f = new Formatter(topic, source, output, namespaceManager, maker, external, headingLevelBase); f.Format(); }
public StringCollection GetVersionsForTopic(WireTypes.AbsoluteTopicName topicName) { StringCollection topicVersions = new StringCollection(); QualifiedTopicRevision atn = new QualifiedTopicRevision(topicName.Name, topicName.Namespace); IEnumerable changeList = Federation.NamespaceManagerForTopic(atn).AllChangesForTopic(atn.LocalName); foreach (TopicChange change in changeList) { topicVersions.Add(change.Version); } return topicVersions; }
/// <summary> /// Answer the formatted text for a given topic, formatted using a given OutputFormat and possibly showing diffs with the previous revision /// </summary> /// <param name="topic">The topic</param> /// <param name="format">What format</param> /// <param name="showDiffs">true to show diffs</param> /// <param name="accumulator">composite cache rule in which to accumulate cache rules</param> /// <returns></returns> public static string FormattedTopic(QualifiedTopicRevision topic, OutputFormat format, QualifiedTopicRevision previousVersion, Federation aFederation, LinkMaker lm) { NamespaceManager relativeToBase = aFederation.NamespaceManagerForNamespace(topic.Namespace); return FormattedTopicWithSpecificDiffs(topic, format, previousVersion, aFederation, lm); }
public void RestoreTopic(WireTypes.AbsoluteTopicName topicName, string visitorIdentityString, string version) { if (version != null && version == topicName.Version) { throw new Exception("Version not found"); } else { QualifiedTopicRevision atn = new QualifiedTopicRevision(topicName.Name, topicName.Namespace); IEnumerable changeList = Federation.NamespaceManagerForTopic(atn).AllChangesForTopic(atn.LocalName); foreach (TopicChange change in changeList) { if (change.Version == version) { WriteNewTopic(change.TopicRevision, Federation.Read(change.TopicRevision), visitorIdentityString, version); break; } } } }
public static IWikiToPresentation WikiToPresentation(QualifiedTopicRevision topic, WikiOutput output, NamespaceManager namespaceManager, LinkMaker maker, ExternalReferencesMap external, int headingLevelBase) { ArrayList lines = new ArrayList(); lines.Add(new StyledLine("", LineStyle.Unchanged)); return new Formatter(topic, lines, output, namespaceManager, maker, external, headingLevelBase); }
public void SetTextForTopic(WireTypes.AbsoluteTopicName topicName, string postedTopicText, string visitorIdentityString) { if (WriteAllowed()) { QualifiedTopicRevision atn = new QualifiedTopicRevision(topicName.Name, topicName.Namespace); WriteNewTopic(atn, postedTopicText, GetVisitorIdentity(visitorIdentityString), null); Federation.Application.LogDebug(this.GetType().ToString(), "Allowed - " + Context.Request.UserHostAddress + ": " + Context.Request.Url); } else { Federation.Application.LogDebug(this.GetType().ToString(), "Denied - " + Context.Request.UserHostAddress + ": " + Context.Request.Url); } }