/// <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> public void 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); Bot.LogEvent( Bot.Msg("Last edits of page \"{0}\" by user {1} were undone."), title, lastEditor); return; } pl.Clear(); } Console.Error.WriteLine(Bot.Msg("Can't undo last edits of page \"{0}\" by user {1}."), title, lastEditor); }
/// <summary>Undoes all last edits made by last contributor. /// The function doesn't affect other operations /// like renaming or protecting.</summary> /// <param name="comment">Comment.</param> /// <param name="minorEditByDefault">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) { 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; }