public bool Matches(Edit _edit) { bool matches = false; // check page name if (_PageRegex != null && _edit._Page != null) { if (_PageRegex.IsMatch(_edit._Page.Name)) { matches = true; } else { return false; } } // check summary if (_SummaryRegex != null && _edit.Summary != null) { if (_SummaryRegex.IsMatch(_edit.Summary)) { matches = true; } else { return false; } } if (_UserRegex != null && _edit.EditUser != null) { if (_UserRegex.IsMatch(_edit.EditUser.UserName)) { matches = true; } else { return false; } } return matches; }
public static void Enqueue(Edit _edit) { lock (All) { foreach (KeyValuePair<string,Queue> x in All) { if (x.Value.Matches(_edit)) { x.Value.Edits.Add(_edit); } } } }
/// <summary> /// Insert an edit to any queue which matches the data /// </summary> /// <param name="_edit"></param> public static void Enqueue(Edit _edit) { lock (All) { foreach (KeyValuePair<string, Queue> x in All) { if (!x.Value.ContainsEdit(_edit)) { if (x.Value.Matches(_edit)) { lock (x.Value.Edits) { x.Value.Edits.Add(_edit); } // Check if this is currently selected queue if (x.Value.MatchesPanel()) { // $fixme$ //x.Value.Panel.Add(_edit); } } } } } }
/// <summary> /// Check if the queue has this edit /// </summary> /// <param name="edit"></param> /// <returns></returns> public bool ContainsEdit(Edit edit) { lock (Edits) { if (edit == null) { throw new Exception("The edit you were about to check is null"); } // performance tweak if (Edits.Contains(edit)) { return true; } foreach (Edit kk in Edits) { if (edit.Id != kk.Id) { continue; } if (edit.Summary != kk.Summary) { continue; } if (edit.Rcid != kk.Rcid) { continue; } if (edit._Page != null && kk._Page != null) { if (edit._Page.Name != kk._Page.Name) { continue; } } if (edit.Oldid != kk.Oldid) { continue; } return true; } } return false; }
public bool Set_Current_Page(Page _page) { Core.History("Set_Current_Page()"); if (_page != null) { if ((_page != _CurrentPage) && DisplayingLast) { if (_page.LastEdit == null) { _CurrentEdit = new Edit(); _CurrentEdit._Page = _page; _CurrentPage = _page; Requests.request_read.history History = new Requests.request_read.history(); History.Page = _page; History.Start(RetrievePageContent); } } if (_page.LastEdit == Core.NullEdit) { CurrentPage.ForeColor = Color.Red; Refresh_Interface(); } if (_CurrentPage == _page && _CurrentEdit.Id != null) { if (Edit.All.ContainsKey(_CurrentEdit.Id)) { historyStrip.NewerEdit = Edit.All[_CurrentEdit.Id]; } } if ( ! CurrentPage.Items.Contains(_page.Name)) { CurrentPage.Items.Add(_page.Name); if (CurrentPage.Items.Count > 20) // this needs to be in config { CurrentPage.Items.RemoveAt(0); } } } return true; }
public void Browser_DisplayPage(Page _Page) { try { if (_Page != null && this.Visible) { if (_Page != _CurrentPage) { _CurrentEdit = _Page.LastEdit; if (_Page.LastEdit == null) { _CurrentEdit = new Edit(); _CurrentEdit._Page = _Page; } Processing.DisplayEdit(_CurrentEdit); if (_Page.LastEdit == Core.NullEdit) { } Refresh_Interface(); } } } catch(Exception B) { Core.ExceptionHandler(B); } }
private void Run() { try { Connect(); while (!SR.EndOfStream) { string data = SR.ReadLine(); Match Edit = line.Match(data); if (line.IsMatch(data) && Edit != null) { string _channel = data.Substring(data.IndexOf("PRIVMSG")); _channel = _channel.Substring(_channel.IndexOf("#")); _channel = _channel.Substring(0, _channel.IndexOf(" ")); if (Edit.Groups.Count > 7) { string page = Edit.Groups[1].Value; string link = Edit.Groups[4].Value; string username = Edit.Groups[6].Value; string change = Edit.Groups[7].Value; string summary = Edit.Groups[8].Value; Edit curr = new Edit(); curr._Change = int.Parse(change); curr.Summary = summary; curr._Page = new Page(page); Queue.Enqueue(curr); Program.MainForm.queuePanel1.Add(curr); } else { Core.WriteLog("Received malformed RC information " + data); } } Thread.Sleep(100); } } catch (ThreadAbortException) { Core.WriteLog("IRC thread was requested to stop"); Core.Threading.KillThread(pt); Connected = false; return; } catch (Exception fail) { Connected = false; Core.ExceptionHandler(fail); } }
/// <summary> /// This function is used for processing of new edits /// </summary> /// <param name="_Edit"></param> /// <returns></returns> public static bool ProcessNewEdit(Edit _Edit) { Core.History("Processing.ProcessEdit( _Edit )"); if (_Edit._User == null || _Edit._Page == null) { return false; } bool Redraw = false; if ( _Edit._Page.LastEdit != null ) { _Edit.Prev.Next = _Edit; _Edit.Prev = _Edit._Page.LastEdit; if ( _Edit.Prev.Size >= 0 && _Edit._Change != 0 ) { _Edit.Size = _Edit.Prev.Size + _Edit._Change; } if (_Edit._Change != 0 && _Edit.Size >= 0) { _Edit.Prev.Size = _Edit.Size - _Edit._Change; } } if ( _Edit._User == null ) { _Edit._User = _Edit._Page.LastEdit._User; } if (_Edit._User.LastEdit != null) { _Edit.PrevByUser = _Edit._User.LastEdit; _Edit.PrevByUser.NextByUser = _Edit; } _Edit._Page.Exists = true; _Edit._Page.Text = null; _Edit._Page.SpeedyCrit = null; _Edit._Page.LastEdit = _Edit; _Edit._User.LastEdit = _Edit; return true; }
public static int Process_NewEdit(Edit _Edit) { Core.History("Processing.ProcessNewEdit()"); try { bool Redraw = false; if (_Edit._Page.LastEdit != null) { _Edit.Prev = _Edit._Page.LastEdit; _Edit.Prev.Next = _Edit; if (_Edit.Prev.Size >= 0 && _Edit._Change != 0) { _Edit.Size = _Edit.Prev.Size + _Edit._Change; } } } catch (Exception A) { Core.ExceptionHandler(A); } return 0; }
public static void Process_Revert(Edit Edit, string Summary = "", bool Rollback = true, bool Undo = false, bool Currentonly = false) { Core.History("Processing.Process_Revert()"); if (Edit == null) return; user LastUser = null; if (Edit._Page.LastEdit != null) { LastUser = Edit._Page.LastEdit._User; } if (Config.ConfirmSelfRevert && !Undo) { } }
/// <summary> /// Display edit /// </summary> /// <param name="_edit"></param> /// <param name="BrowsingHistory"></param> /// <param name="browser"></param> public static void DisplayEdit(Edit _edit, bool BrowsingHistory = false, Controls.SpecialBrowser browser = null, bool ChangeEdit = true) { Core.History("Processing.DisplayEdit()"); try { if (browser == null) { browser = main._CurrentBrowser; } if (_edit != null) { if (_edit._Page != null) { if (BrowsingHistory != true && browser.History.Count == 0 || (browser.History[0].Edit is Edit) == false) { browser.AddToHistory(new Core.HistoryItem(_edit)); } } if (main._CurrentBrowser == browser && ChangeEdit == true) { browser.Edit = _edit; Program.MainForm.Set_Current_User(_edit._User); Program.MainForm.Set_Current_Page(_edit._Page); } if (_edit._Deleted) { } else if (_edit.Prev == Core.NullEdit) { Requests.request_read.browser_html_data BrowserRequest = new Requests.request_read.browser_html_data(); BrowserRequest.address = Core.SitePath() + "index.php?title=" + System.Web.HttpUtility.UrlEncode(_edit._Page.Name) + "&id=" + _edit.Id; BrowserRequest.browser = browser; BrowserRequest.Start(); } else { if (_edit.DiffCacheState == Edit.CacheState.Viewed || _edit.DiffCacheState == Edit.CacheState.Cached) { if (_edit.Diff != null) { string DocumentText = "", DiffText = ""; DiffText = _edit.Diff; DiffText = DiffText.Replace("href=\"/wiki/", "href=\"" + Config.Projects[Config.Project] + "wiki/"); DiffText = DiffText.Replace("href='/wiki/", "href='" + Config.Projects[Config.Project] + "wiki/"); DiffText = DiffText.Replace("href=\"/w/", "href=\"" + Config.Projects[Config.Project] + "w/"); DiffText = DiffText.Replace("href='/w/", "href='" + Config.Projects[Config.Project] + "w/"); DocumentText = huggle3.Properties.Resources.header; DocumentText += DiffText; DocumentText += huggle3.Properties.Resources.footer; browser.DocumentText = DocumentText; } _edit.DiffCacheState = Edit.CacheState.Viewed; } } if (_edit.DiffCacheState == Edit.CacheState.Uncached) { _edit.DiffCacheState = Edit.CacheState.Caching; Requests.request_read.diff Request = new Requests.request_read.diff(); Request._Edit = _edit; Request.browsertab = browser; Request.Start(); } Program.MainForm.Refresh_Interface(); } } catch (Exception ex) { Core.ExceptionHandler( ex ); } }
/// <summary> /// History /// </summary> /// <param name="Result"></param> /// <param name="Page"></param> public static void Process_History(string Result, Page Page) { try { Core.History("Processing.Process_History()"); if (Result == null) return; System.Text.RegularExpressions.MatchCollection History = new System.Text.RegularExpressions.Regex("<rev revid=\"([^\"]+)\" parentid=\"([^\"]+)\" user=\"([^\"]+)\" (anon=\"\" )?timestamp=\"([^\"]+)\"( comment=\"([^\"]+)\")?(>([^<]*)</)?", System.Text.RegularExpressions.RegexOptions.Compiled).Matches(Result); if (History.Count == 0) { if (Page.LastEdit == null) { Page.LastEdit = Core.NullEdit; } } Edit NextEdit = null; for (int i = 0; i < History.Count - 1; i++) { Edit _Edit = new Edit(); string Content = History[i].Groups[1].Value; if (Edit.All.ContainsKey(Content)) { _Edit = Edit.All[Content]; } _Edit.Id = Content; if (_Edit.Oldid == null) { _Edit.Oldid = "prev"; } _Edit._Page = Page; if (History[i].Groups[8].Value != "") { _Edit._Text = System.Web.HttpUtility.HtmlDecode(History[i].Groups[9].Value); } _Edit._User = Core.GetUser(System.Web.HttpUtility.HtmlDecode(History[i].Groups[3].Value)); if (_Edit.Summary == null) { _Edit.Summary = System.Web.HttpUtility.HtmlDecode(History[i].Groups[7].Value); } if (_Edit._Time == DateTime.MinValue) { _Edit._Time = DateTime.Parse(History[i].Groups[5].Value); } if (Page.LastEdit == null) { Page.LastEdit = _Edit; } else if (NextEdit != null) { _Edit.Next = NextEdit; NextEdit.Prev = _Edit; _Edit.Next.Oldid = _Edit.Id; } NextEdit = _Edit; ProcessEdit(_Edit); } if (Result.Contains("<revisions rvstartid=\"")) { Page.HistoryOffset = NextEdit.Id; } else { Page.HistoryOffset = null; if (NextEdit != null) { NextEdit.Prev = Core.NullEdit; Page.FirstEdit = NextEdit; } } Program.MainForm.Draw_History(); } catch (Exception B) { Core.ExceptionHandler(B); } }
/// <summary> /// Process diff /// </summary> /// <param name="_E"></param> /// <param name="Diff"></param> /// <param name="browser"></param> public static void Process_Diff(Edit _E, string Diff, Controls.SpecialBrowser browser) { Core.History("Processing.Process_Diff()"); if (_E._Multiple == false) { if (Diff.Contains("<span class=\"mw-rollback-link\">")) { string RollbackToken = Diff.Substring(Diff.IndexOf("span class=\"mw-rollback-link\">")); _E.RollbackToken = System.Web.HttpUtility.HtmlDecode(Core.FindString(RollbackToken, "<a href=\"", "&token=", "\"")); } else { _E.RollbackToken = null; } if (_E.Id == "next" | _E.Id == "cur" && Diff.Contains("<div id=\"mw-diff-ntitle1\">")) { _E.Id = Core.FindString(Diff, "<div id=\"mw-diff-ntitle1\"><strong><a", "oldid=", "'"); } if (_E.Id != "cur" && Edit.All.ContainsKey(_E.Id)) { _E = Edit.All[_E.Id]; } if (_E.Oldid == "prev" && Diff.Contains("<div id=\"mw-diff-otitle1\">")) { _E.Oldid = Core.FindString(Diff, "<div id=\"mw-diff-otitle1\"><strong><a", "oldid=", "'"); } if (Diff.Contains("<div id=\"mw-diff-ntitle2\">") && _E._User != null) { string D_User = Core.FindString(Diff, "<div id=\"mw-diff-ntitle2\">", ">", "<"); D_User = System.Web.HttpUtility.HtmlDecode(D_User.Replace(" (page does not exist)", "")); _E._User = Core.GetUser(D_User); } if (_E.Prev != null) { //ok } else { _E.Prev = new Edit(); _E.Prev._Page = _E._Page; _E.Prev.Next = _E; _E.Prev.Id = _E.Oldid; _E.Prev.Oldid = "prev"; } if (Diff.Contains("<div id=\"mw-diff-ntitle1\">") && _E._Time == DateTime.MinValue) { string et = Core.FindString(Diff, "<div id=\"mw-diff-ntitle1\">", "</div>"); if (et.Contains("Revision as of")) { et = Core.FindString(et, "Revision as of"); if ( DateTime.TryParse(et, out _E._Time) ) { _E._Time = DateTime.SpecifyKind(DateTime.Parse(et), DateTimeKind.Local).ToUniversalTime(); } } else if (et.Contains("Current revision")) { et = Core.FindString(et, "Current revision</a>", "("); if (DateTime.TryParse(et, out _E._Time)) { _E._Time = DateTime.SpecifyKind(DateTime.Parse(et), DateTimeKind.Local).ToUniversalTime(); } } if (Diff.Contains("<div id=\"mw-diff-otitle1\">") && _E.Prev._Time == DateTime.MinValue) { string etime = Core.FindString(Diff, "<div id=\"mw-diff-otitle1\">", "</div>"); etime = etime.Substring(etime.IndexOf(":") - 2); if (DateTime.TryParse(etime, out _E._Time)) { _E._Time = DateTime.SpecifyKind(DateTime.Parse(etime), DateTimeKind.Local).ToUniversalTime(); } } } if (Diff.Contains("<div id=\"mw-diff-otitle2\">") && _E.Prev._User == null) { string username = System.Web.HttpUtility.HtmlDecode(Core.FindString(Diff, "<div id=\"mw-diff-otitle2\">", ">", "</a>")); } if (_E.Prev.Summary == null) { if (Diff.Contains("<div id=\"mw-diff-otitle3\">")) { string esummary = Core.FindString(Diff, "<div id=\"mw-diff-otitle3\">"); if (esummary.Contains("<div id=\"mw-diff-ntitle3\">")) { esummary = esummary.Substring(0, esummary.IndexOf("<div id=\"mw-diff-ntitle3\">")); } if (esummary.Contains("<span class=\"comment\">")) { if (esummary.Contains("</span></div>")) { esummary = Core.FindString(esummary, "<span class=\"comment\">", "</span></div>"); } else if (esummary.Contains("</span> ")) { esummary = Core.FindString(esummary, "<span class=\"comment\">", "</span> "); } esummary = Core.HtmltoWikitext(esummary); _E.Prev.Summary = esummary; } else { _E.Prev.Summary = ""; } } if (Config.PageCreatedPattern != null && Config.PageCreatedPattern.IsMatch(_E.Prev.Summary)) { _E.Prev.Prev = Core.NullEdit; _E._Page.FirstEdit = _E.Prev; } if (Diff.Contains("<div id=\"mw-diff-ntitle4\"> </div>")) { _E._Page.LastEdit = _E; } if (_E.Prev.Processed == false) { ProcessEdit(_E.Prev); } //_E.ChangedContent = } } _E.Diff = Diff; _E.DiffCacheState = Edit.CacheState.Cached; if (browser != null) { if ((browser.Edit.Next == _E) || browser.Edit == _E) { DisplayEdit(_E, false, browser); } } }
public bool Matches(Edit _edit) { return true; }
/// <summary> /// Called when needed to render stuff /// </summary> public void RetrievePageContent() { Core.History("RetrievePageContent()"); if (_CurrentPage.LastEdit != null) { _CurrentEdit = _CurrentPage.LastEdit; Processing.DisplayEdit(_CurrentPage.LastEdit); } }
/// <summary> /// Creates a new object /// </summary> /// <param name="_edit">Edit</param> public HistoryItem(Edit _edit) { this._Edit = _edit; }
public static int ProcessEdit(Edit _Edit) { Core.History("Processing.ProcessEdit(new edit)"); if (_Edit == null) { return 1; } if (_Edit._Time == DateTime.MinValue) { _Edit._Time = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); } if (_Edit.Oldid == null) { _Edit.Oldid = "prev"; } if (_Edit._Bot == true) { _Edit._User.Bot = true; } if (Config.PageBlankedPattern != null) { if (Config.PageBlankedPattern.IsMatch(_Edit.Summary) || _Edit.Size == 0) { _Edit._Type = Edit.EditType.Blanked; } } if (Config.PageRedirectedPattern != null) { if (Config.PageRedirectedPattern.IsMatch(_Edit.Summary)) { _Edit._Type = Edit.EditType.Redirect; } } if (Config.PageReplacedPattern != null) { if (Config.PageReplacedPattern.IsMatch(_Edit.Summary) || (_Edit.Size >= 0 && _Edit._Change <= -200)) { _Edit._Type = Edit.EditType.ReplacedWith; } } if (Config.Summary != "" && _Edit.Summary.EndsWith(Config.Summary) && _Edit.Summary != "") { _Edit._Assisted = true; } foreach (string item in Config.AssistedSummaries) { if (_Edit.Summary.Contains(item)) { _Edit._Assisted = true; break; } } if (_Edit._User != null && _Edit._Page != null) { if (_Edit.NewPage) { _Edit._Page.FirstEdit = _Edit; _Edit.Prev = Core.NullEdit; } if (_Edit.Summary == Config.UndoSummary + " " + Config.Summary) { _Edit._Type = Edit.EditType.Revert; } if (_Edit._Type == Edit.EditType.Revert && _Edit.Summary.ToLower().Contains("[[special:contributions/")) { string userName = _Edit.Summary.Substring(_Edit.Summary.ToLower().IndexOf("[[special:contributions/") + 24); if (userName.Contains("]]") || userName.Contains("|")) { if (userName.Contains("|")) userName = userName.Substring(0, userName.IndexOf("|")); if (userName.Contains("]]")) { userName = userName.Substring(0, userName.IndexOf("]]")); } user RevertedUser = Core.GetUser(userName); if (RevertedUser != _Edit._User && RevertedUser.User_Level == user.UserLevel.None) { RevertedUser.User_Level = user.UserLevel.Reverted; } } } if (_Edit.Next != null) { if (_Edit.Next._Type == Edit.EditType.Revert && _Edit._User.User_Level == user.UserLevel.None) { _Edit._User.User_Level = user.UserLevel.Reverted; } if (_Edit._Space == Space.UserTalk && _Edit._Page.IsSubpage) { user.UserLevel Summary_Level; } } } if (_Edit.Id != null) if (Edit.All.ContainsKey(_Edit.Id)) { Edit.All.Add(_Edit.Id, _Edit); } _Edit.Processed = true; return 0; }