private static PageBE PopulateOld(IDataRecord dr) { PageBE old = new PageBE(); old.ID = DbUtils.Convert.To <ulong>(dr["rev_id"]).Value; old._Namespace = DbUtils.Convert.To <ushort>(dr["page_namespace"]).Value; old._Title = GetUTF8String(dr, "page_title"); old.SetText(GetUTF8String(dr, "old_text")); old.Comment = GetUTF8String(dr, "rev_comment"); if (MediaWikiConverterContext.Current.Merge) { old.UserID = MediaWikiConverterContext.Current.MergeUserId; } else { old.UserID = DbUtils.Convert.To <uint>(dr["rev_user"]).Value; } old.TimeStamp = DbUtils.ToDateTime(GetUTF8String(dr, "rev_timestamp")); old.MinorEdit = DbUtils.Convert.To <bool>(dr["rev_minor_edit"]).Value; old.ContentType = DekiMimeType.MEDIAWIKI_TEXT; if (MediaWikiConverterContext.Current.AttributeViaPageRevComment) { //Add the original revision username to the comment string username = GetUTF8String(dr, "rev_user_text"); if (!string.IsNullOrEmpty(username)) { old.Comment = string.Format(MediaWikiConverterContext.Current.AttributeViaPageRevCommentPattern, old.Comment, username); } } return(old); }
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)); } }
private static PageBE PopulatePage(IDataRecord dr) { PageBE page = new PageBE(); page.ID = DbUtils.Convert.To <ulong>(dr["page_id"]).Value; page._Namespace = DbUtils.Convert.To <ushort>(dr["page_namespace"]).Value; page._Title = GetUTF8String(dr, "page_title"); string restrictions = GetUTF8String(dr, "page_restrictions"); if ((restrictions == "sysop") || (restrictions == "move=sysop:edit=sysop")) { page.RestrictionID = 2; } page.IsRedirect = DbUtils.Convert.To <bool>(dr["page_is_redirect"]).Value; page.IsNew = DbUtils.Convert.To <bool>(dr["page_is_new"]).Value; page.Touched = DbUtils.ToDateTime(GetUTF8String(dr, "page_touched")); if (MediaWikiConverterContext.Current.Merge) { page.UserID = MediaWikiConverterContext.Current.MergeUserId; } else { page.UserID = DbUtils.Convert.To <uint>(dr["rev_user"]).Value; } page.TimeStamp = DbUtils.ToDateTime(GetUTF8String(dr, "rev_timestamp")); page.MinorEdit = DbUtils.Convert.To <bool>(dr["rev_minor_edit"]).Value; page.Comment = GetUTF8String(dr, "rev_comment"); page.SetText(GetUTF8String(dr, "old_text")); page.ContentType = DekiMimeType.MEDIAWIKI_TEXT; page.TIP = String.Empty; if (MediaWikiConverterContext.Current.AttributeViaPageRevComment) { //Add the original revision username to the comment string username = GetUTF8String(dr, "rev_user_text"); if (!string.IsNullOrEmpty(username)) { page.Comment = string.Format(MediaWikiConverterContext.Current.AttributeViaPageRevCommentPattern, page.Comment, username); } } return(page); }
private static void RestorePageRevisionsForPage(ArchiveBE[] archivedRevs, Title newTitle, uint transactionId, bool minorChange, DateTime utcTimestamp) { // add the most recent archive entry to the pages table // NOTE: this will preserve the page id if it was saved with the archive or create a new page id if it is not available ArchiveBE mostRecentArchiveRev = archivedRevs[archivedRevs.Length - 1]; PageBE restoredPage = null; if (0 < archivedRevs.Length) { restoredPage = new PageBE(); restoredPage.Title = newTitle; restoredPage.Revision = mostRecentArchiveRev.Revision; restoredPage.MinorEdit = mostRecentArchiveRev.MinorEdit; bool conflict; PageBL.Save(restoredPage, null, mostRecentArchiveRev.Comment, mostRecentArchiveRev.Text, mostRecentArchiveRev.ContentType, mostRecentArchiveRev.Title.DisplayName, mostRecentArchiveRev.Language, -1, null, mostRecentArchiveRev.TimeStamp, mostRecentArchiveRev.LastPageId, false, false, null, false, out conflict); RecentChangeBL.AddRestorePageRecentChange(utcTimestamp, restoredPage, DekiContext.Current.User, DekiResources.UNDELETED_ARTICLE(restoredPage.Title.AsPrefixedUserFriendlyPath()), minorChange, transactionId); } // add all other archive entries to the old table // NOTE: this will preserve the old ids if they were saved with the archive or create new old ids if not available for (int i = 0; i < archivedRevs.Length - 1; i++) { ArchiveBE archivedRev = archivedRevs[i]; PageBE currentPage = new PageBE(); currentPage.Title = newTitle; if (i < archivedRevs.Length - 1) { ParserResult parserResult = DekiXmlParser.ParseSave(currentPage, archivedRev.ContentType, currentPage.Language, archivedRev.Text, -1, null, false, null); currentPage.SetText(parserResult.BodyText); currentPage.ContentType = parserResult.ContentType; currentPage.UserID = archivedRev.UserID; currentPage.TimeStamp = archivedRev.TimeStamp; currentPage.MinorEdit = archivedRev.MinorEdit; currentPage.Comment = archivedRev.Comment; currentPage.Language = archivedRev.Language; currentPage.IsHidden = archivedRev.IsHidden; currentPage.Revision = archivedRev.Revision; currentPage.ID = restoredPage.ID; PageBL.InsertOld(currentPage, archivedRev.OldId); } } }