public static DreamMessage BuildDeletedPageContents(uint pageid) { ArchiveBE page = DbUtils.CurrentSession.Archive_GetPageHeadById(pageid); if (page == null) { throw new PageArchiveLogicNotFoundException(pageid); } //HACKHACKHACK MaxM: Copy data to a PageBE object since parser will not work on an ArchiveBE. ArchiveBE needs to go away. PageBE tempP = new PageBE(); tempP.Title = page.Title; tempP.SetText(page.Text); tempP.ContentType = page.ContentType; ParserResult parserResult = DekiXmlParser.Parse(tempP, ParserMode.VIEW_NO_EXECUTE); // TODO (steveb): this code is almost identical to the one in "GET:pages/{pageid}/contents"; consider merging // post process tail DekiXmlParser.PostProcessParserResults(parserResult); // wrap the result in a content tag and return it to the user XDoc result = new XDoc("content").Attr("type", parserResult.ContentType); foreach (XDoc entry in parserResult.Content.Elements) { if (entry.HasName("body")) { result.Start("body").Attr("target", entry["@target"].AsText).Value(entry.ToInnerXHtml()).End(); } else { result.Elem(entry.Name, entry.ToInnerXHtml()); } } // check if we hit a snag, which is indicated by a plain-text response if ((parserResult.ContentType == MimeType.TEXT.FullType) && (page.ContentType != MimeType.TEXT.FullType)) { // something happened during parsing return(new DreamMessage(DreamStatus.NonAuthoritativeInformation, null, result)); } else { return(DreamMessage.Ok(result)); } }
internal static DekiResource GetPageDiffSummary(PageBE page, string before, string beforeMime, string after, string afterMime, int maxDelta) { ParserResult beforeDoc = DekiXmlParser.Parse(page, beforeMime, page.Language, before, ParserMode.EDIT, false, -1, null, null); ParserResult afterDoc = DekiXmlParser.Parse(page, afterMime, page.Language, after, ParserMode.EDIT, false, -1, null, null); Tuplet <ArrayDiffKind, XDocDiff.Token>[] diff = XDocDiff.Diff(beforeDoc.MainBody, afterDoc.MainBody, maxDelta); if (diff == null) { return(DekiResources.PAGE_DIFF_TOO_LARGE()); } // create change summary int added; int removed; int attributes; int structural; return(GetChangeSummary(diff, out added, out removed, out attributes, out structural)); }