/// <summary>Undoes all last edits of last page contributor, so page text reverts to /// previous contents. The function doesn't affect other operations /// like renaming or protecting.</summary> /// <param name="comment">Revert comment.</param> /// <param name="isMinorEdit">Minor edit mark (pass true for minor edit).</param> /// <returns>Returns true if last edits were undone.</returns> public bool UndoLastEdits(string comment, bool isMinorEdit) { if (string.IsNullOrEmpty(title)) throw new WikiBotException(Bot.Msg("No title specified for page to revert.")); PageList pl = new PageList(site); string lastEditor = ""; for (int i = 50; i <= 5000; i *= 10) { if (Bot.useBotQuery == true && site.botQuery == true && site.botQueryVersions.ContainsKey("ApiQueryRevisions.php")) pl.FillFromPageHistoryEx(title, i, false); else pl.FillFromPageHistory(title, i); lastEditor = pl[0].lastUser; foreach (Page p in pl) if (p.lastUser != lastEditor) { p.Load(); Save(p.text, comment, isMinorEdit); Console.WriteLine( Bot.Msg("Last edits of page \"{0}\" by user {1} were undone."), title, lastEditor); return true; } if (pl.pages.Count < i) break; pl.Clear(); } Console.Error.WriteLine(Bot.Msg("Can't undo last edits of page \"{0}\" by user {1}."), title, lastEditor); return false; }
/// <summary> /// Exclude page controls and data for all pages except for the requested page. /// If the requested page has a summary control. All controls data for other pages will be returned (none will be removed). /// </summary> /// <param name="pageId">The page id passed from the client, which holds special meaning.</param> /// <param name="pages">The list of all pages for the form.</param> /// <returns>The page list to use.</returns> /// <remarks> /// When <paramref name="pageId"/> is <see langword="null"/>, then the return value is all <paramref name="pages"/>. /// When <paramref name="pageId"/> is -1, then the return value is the first page in <paramref name="pages"/>. /// Otherwise the return value is the page that with an id matching <paramref name="pageId"/>. /// </remarks> private PageList RemoveUnecessaryControlsData(int? pageId, PageList pages) { Page currentPage = null; currentPage = !pageId.HasValue || pageId.Value == -1 ? pages[0] : pages.FindByPageId(pageId.Value); if (currentPage == null) { return pages; } if (PageHasSummaryControl(currentPage)) { var summaryControl = currentPage.Controls.FindAllRecursive<SummaryControl>().First(); if (!summaryControl.IncludedControls.All) { foreach (var page in pages) { if (page == currentPage) { continue; } var controls = page.Controls.Where(c => summaryControl.IncludedControls.Controls.Contains(c.Name)); page.Controls = new ControlList(controls); } } } else { pages.Clear(); pages.Add(currentPage); } return pages; }