void OnStateChanged(AsyncApiEdit sender) { if (StateChanged != null) { StateChanged(sender); } }
void OnMaxlagExceeded(AsyncApiEdit sender, double maxlag, int retryAfter) { if (MaxlagExceeded != null) { MaxlagExceeded(sender, maxlag, retryAfter); } }
void OnLoggedOff(AsyncApiEdit sender) { if (LoggedOff != null) { LoggedOff(sender); } }
void OnPreviewComplete(AsyncApiEdit sender, string result) { if (PreviewComplete != null) { PreviewComplete(sender, result); } }
void OnExceptionCaught(AsyncApiEdit sender, Exception ex) { if (ExceptionCaught != null) { ExceptionCaught(sender, ex); } }
void OnSaveComplete(AsyncApiEdit sender, SaveInfo saveInfo) { if (SaveComplete != null) { SaveComplete(sender, saveInfo); } }
void OnOpenComplete(AsyncApiEdit sender, PageInfo pageInfo) { if (OpenComplete != null) { OpenComplete(sender, pageInfo); } }
// Webcontrol event handlers: private void EditorStatusChanged(AsyncApiEdit sender) { if (PluginManager.AWBForm.TheSession.Editor.IsActive) { LoadArticle(); } }
void OnAborted(AsyncApiEdit sender) { if (Aborted != null) { Aborted(sender); } }
public LogUploader(AsyncApiEdit e) { BotTag = "|}<!--/bottag-->"; // doing it this way OUGHT to allow inherited classes to override TableHeaderUserName = "******"; TableHeaderNoUserName = "******"; editor = e.Clone(); }
internal void Init(AsyncApiEdit e, Label etaLabel, PluginSettingsControl.Stats stats) { if (!TimerEnabled) { ResetVars(); _etaLabel = etaLabel; TimerEnabled = true; _stats = stats; _stats.SkipMisc += StatsSkipMisc; Timer1_Tick(null, null); } }
// AWB processing stopped/started: internal void AWBProcessingStart(AsyncApiEdit editor) { foreach (Label lbl in StatLabels) { if (string.IsNullOrEmpty(lbl.Text)) { lbl.Text = "0"; } } TimerStats1.Visible = true; TimerStats1.Init(editor, ETALabel, PluginStats); PluginManager.StatusText.Text = "Started"; }
internal void Init(AsyncApiEdit e, Label ETALabel, PluginSettingsControl.Stats Stats) { if (!TimerEnabled) { ResetVars(); mETALabel = ETALabel; TimerEnabled = true; mStats = Stats; mStats.SkipMisc += mStats_SkipMisc; Timer1_Tick(null, null); } }
private AsyncApiEdit CreateEditor(string url) { AsyncApiEdit edit = new AsyncApiEdit(url, parentControl) { NewMessageThrows = false }; edit.OpenComplete += OnOpenComplete; edit.SaveComplete += OnSaveComplete; edit.PreviewComplete += OnPreviewComplete; edit.ExceptionCaught += OnExceptionCaught; edit.MaxlagExceeded += OnMaxlagExceeded; edit.LoggedOff += OnLoggedOff; edit.StateChanged += OnStateChanged; edit.Aborted += OnAborted; return(edit); }
private static void EditorStatusChanged(AsyncApiEdit sender) { if (AWBForm.TheSession.Editor.IsActive) { if (ActivePlugins.Count > 0) { _pluginSettings.AWBProcessingStart(sender); } } else { DefaultStatusText(); // If AWB has stopped and the list is empty we assume the job is finished, so close the log and upload: if (AWBForm.ListMaker.Count == 0) { AWBForm.TraceManager.Close(); } } }
public Session(string url) { Editor = new AsyncApiEdit(url); LoadProjectOptions(); Update(); }
internal void IncrementSavedEdits(AsyncApiEdit sender, SaveInfo save) { IncrementSavedEdits(); }
/// <summary> /// Checks log in status, registered and version. /// </summary> private WikiStatusResult UpdateWikiStatus() { try { string typoPostfix = ""; IsBot = false; //TODO: login? Site = new SiteInfo(Editor); //load version check page BackgroundRequest versionRequest = new BackgroundRequest(); versionRequest.GetHTML( "http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw"); //load check page string url; if (Variables.IsWikia) { url = "http://www.wikia.com/wiki/index.php?title=Wikia:AutoWikiBrowser/CheckPage&action=edit"; } else if ((Variables.Project == ProjectEnum.wikipedia) && (Variables.LangCode == LangCodeEnum.ar)) { url = "http://ar.wikipedia.org/w/index.php?title=%D9%88%D9%8A%D9%83%D9%8A%D8%A8%D9%8A%D8%AF%D9%8A%D8%A7:%D8%A7%D9%84%D8%A3%D9%88%D8%AA%D9%88%D9%88%D9%8A%D9%83%D9%8A_%D8%A8%D8%B1%D8%A7%D9%88%D8%B2%D8%B1/%D9%85%D8%B3%D9%85%D9%88%D8%AD&action=edit"; } else { url = Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=edit"; } string strText = Editor.SynchronousEditor.HttpGet(url); Variables.RTL = Site.IsRightToLeft; if (Variables.IsCustomProject || Variables.IsWikia) { try { Variables.LangCode = Variables.ParseLanguage(Site.Language); } catch { // use English if language not recognized Variables.LangCode = LangCodeEnum.en; } } if (Variables.IsWikia) { //this object loads a local checkpage on Wikia //it cannot be used to approve users, but it could be used to set some settings //such as underscores and pages to ignore AsyncApiEdit editWikia = (AsyncApiEdit)Editor.Clone(); SiteInfo wikiaInfo = new SiteInfo(); string s = editWikia.SynchronousEditor.Open("Project:AutoWikiBrowser/CheckPage"); typoPostfix = "-" + Variables.LangCode; // selectively add content of the local checkpage to the global one strText += Message.Match(s).Value /*+ Underscores.Match(s).Value*/ + WikiRegexes.NoGeneralFixes.Match(s); } versionRequest.Wait(); string strVersionPage = (string)versionRequest.Result; //see if this version is enabled if (!strVersionPage.Contains(AWBVersion + " enabled")) { return(WikiStatusResult.OldVersion); } //TODO: // else //if (!WeAskedAboutUpdate && strVersionPage.Contains(AWBVersion + " enabled (old)")) //{ // WeAskedAboutUpdate = true; // if ( // MessageBox.Show( // "This version has been superceeded by a new version. You may continue to use this version or update to the newest version.\r\n\r\nWould you like to automatically upgrade to the newest version?", // "Upgrade?", MessageBoxButtons.YesNo) == DialogResult.Yes) // { // Match version = Regex.Match(strVersionPage, @"<!-- Current version: (.*?) -->"); // if (version.Success && version.Groups[1].Value.Length == 4) // { // System.Diagnostics.Process.Start(Path.GetDirectoryName(Application.ExecutablePath) + // "\\AWBUpdater.exe"); // } // else if ( // MessageBox.Show("Error automatically updating AWB. Load the download page instead?", // "Load download page?", MessageBoxButtons.YesNo) == DialogResult.Yes) // { // Tools.OpenURLInBrowser("http://sourceforge.net/project/showfiles.php?group_id=158332"); // } // } //} CheckPageText = strText; // don't run GetInLogInStatus if we don't have the username, we sometimes get 2 error message boxes otherwise bool loggedIn = Editor.User.IsRegistered; if (!loggedIn) { return(WikiStatusResult.NotLoggedIn); } // check if username is globally blacklisted foreach ( Match m3 in Regex.Matches(strVersionPage, @"badname:\s*(.*)\s*(:?|#.*)$", RegexOptions.IgnoreCase)) { if (!string.IsNullOrEmpty(m3.Groups[1].Value.Trim()) && !string.IsNullOrEmpty(Editor.User.Name) && Regex.IsMatch(Editor.User.Name, m3.Groups[1].Value.Trim(), RegexOptions.IgnoreCase | RegexOptions.Multiline)) { return(WikiStatusResult.NotRegistered); } } //see if there is a message Match m = Message.Match(strText); if (m.Success && m.Groups[1].Value.Trim().Length > 0) { MessageBox.Show(m.Groups[1].Value, "Automated message", MessageBoxButtons.OK, MessageBoxIcon.Information); } //see if there is a version-specific message m = VersionMessage.Match(strText); if (m.Success && m.Groups[1].Value.Trim().Length > 0 && m.Groups[1].Value == AWBVersion) { MessageBox.Show(m.Groups[2].Value, "Automated message", MessageBoxButtons.OK, MessageBoxIcon.Information); } m = Regex.Match(strText, "<!--[Tt]ypos" + typoPostfix + ":(.*?)-->"); if (m.Success && m.Groups[1].Value.Trim().Length > 0) { Variables.RetfPath = m.Groups[1].Value.Trim(); } List <string> us = new List <string>(); foreach (Match m1 in Underscores.Matches(strText)) { if (m1.Success && m1.Groups[1].Value.Trim().Length > 0) { us.Add(m1.Groups[1].Value.Trim()); } } if (us.Count > 0) { Variables.LoadUnderscores(us.ToArray()); } //don't require approval if checkpage does not exist. if (strText.Length < 1) { IsBot = true; return(WikiStatusResult.Registered); } if (strText.Contains("<!--All users enabled-->")) { //see if all users enabled IsBot = true; return(WikiStatusResult.Registered); } //see if we are allowed to use this softare strText = Tools.StringBetween(strText, "<!--enabledusersbegins-->", "<!--enabledusersends-->"); string strBotUsers = Tools.StringBetween(strText, "<!--enabledbots-->", "<!--enabledbotsends-->"); Regex username = new Regex(@"^\*\s*" + Tools.CaseInsensitive(Editor.User.Name) + @"\s*$", RegexOptions.Multiline); if (IsSysop) { IsBot = username.IsMatch(strBotUsers); return(WikiStatusResult.Registered); } if (!string.IsNullOrEmpty(Editor.User.Name) && username.IsMatch(strText)) { //enable bot mode IsBot = username.IsMatch(strBotUsers); return(WikiStatusResult.Registered); } return(WikiStatusResult.NotRegistered); } catch (Exception ex) { Tools.WriteDebug(ToString(), ex.Message); Tools.WriteDebug(ToString(), ex.StackTrace); IsBot = false; return(WikiStatusResult.Error); } }
private static void EditorAborted(AsyncApiEdit sender) { _pluginSettings.AWBProcessingAborted(); }
public string ProcessArticle(IAutoWikiBrowser sender, IProcessArticleEventArgs eventargs) { string res; if (ActivePlugins.Count == 0) { return(eventargs.ArticleText); } Article theArticle; StatusText.Text = "Processing " + eventargs.ArticleTitle; AWBForm.TraceManager.ProcessingArticle(eventargs.ArticleTitle, eventargs.NameSpaceKey); foreach (PluginBase p in ActivePlugins) { try { if (!p.AmReady && p.AmGeneric) { MessageBox.Show( "The generic template plugin \"" + p.PluginShortName + "\"isn't properly configured.", "Can't start", MessageBoxButtons.OK, MessageBoxIcon.Error); StopAWB(); goto SkipOrStop; } } catch { StopAWB(); goto SkipOrStop; } } switch (eventargs.NameSpaceKey) { case Namespace.Article: if (_pluginSettings.ManuallyAssess) { if (eventargs.Exists == Exists.Yes) { StatusText.Text += ": Click Preview to read the article; " + "click Save or Ignore to load the assessments form"; _assessmentsObject.ProcessMainSpaceArticle(eventargs.ArticleTitle); eventargs.EditSummary = "Clean up"; goto SkipOrStop; } //FIXME var eaArticleES = eventargs.EditSummary; var eaArticleSkip = eventargs.Skip; res = Skipping(ref eaArticleES, "", SkipReason.ProcessingMainArticleDoesntExist, eventargs.ArticleText, ref eaArticleSkip); eventargs.EditSummary = eaArticleES; eventargs.Skip = eaArticleSkip; goto ExitMe; } goto SkipBadNamespace; //break; case Namespace.Talk: AsyncApiEdit editor = AWBForm.TheSession.Editor.Clone(); editor.Open(Tools.ConvertFromTalk(eventargs.ArticleTitle), false); editor.Wait(); if (!editor.Page.Exists) { // FIXME var eaNotExistsES = eventargs.EditSummary; var eaNotExistsSkip = eventargs.Skip; res = Skipping(ref eaNotExistsES, "", SkipReason.ProcessingTalkPageArticleDoesntExist, eventargs.ArticleText, ref eaNotExistsSkip, eventargs.ArticleTitle); eventargs.EditSummary = eaNotExistsES; eventargs.Skip = eaNotExistsSkip; } else { theArticle = new Article(eventargs.ArticleText, eventargs.ArticleTitle, eventargs.NameSpaceKey); bool reqPhoto = ReqPhotoParamNeeded(theArticle); if (_pluginSettings.ManuallyAssess) { // reqphoto byref if (!_assessmentsObject.ProcessTalkPage(theArticle, _pluginSettings, ref reqPhoto)) { eventargs.Skip = true; goto SkipOrStop; } } else { reqPhoto = ProcessTalkPageAndCheckWeAddedReqPhotoParam(theArticle, reqPhoto); // We successfully added a reqphoto param } // FIXME var eaTalkSkip = eventargs.Skip; var eaTalkES = eventargs.EditSummary; res = FinaliseArticleProcessing(theArticle, ref eaTalkSkip, ref eaTalkES, eventargs.ArticleText, reqPhoto); eventargs.Skip = eaTalkSkip; eventargs.EditSummary = eaTalkES; } break; case Namespace.CategoryTalk: case 101: //101 is Portal Talk case Namespace.ProjectTalk: case Namespace.TemplateTalk: case Namespace.FileTalk: if (_pluginSettings.ManuallyAssess) { MessageBox.Show( "The plugin has received a non-standard namespace talk page in " + "manual assessment mode. Please remove this item from the list and start again.", "Manual Assessments", MessageBoxButtons.OK, MessageBoxIcon.Error); StopAWB(); goto SkipOrStop; } theArticle = new Article(eventargs.ArticleText, eventargs.ArticleTitle, eventargs.NameSpaceKey); foreach (PluginBase p in ActivePlugins) { p.ProcessTalkPage(theArticle, Classification.Code, Importance.NA, false, false, false, ProcessTalkPageMode.NonStandardTalk, false); if (theArticle.PluginManagerGetSkipResults == SkipResults.SkipBadTag) { break; // TODO: might not be correct. Was : Exit For } } // FIXME var eaMiscSkip = eventargs.Skip; var eaMiscES = eventargs.EditSummary; res = FinaliseArticleProcessing(theArticle, ref eaMiscSkip, ref eaMiscES, eventargs.ArticleText, false); eventargs.Skip = eaMiscSkip; eventargs.EditSummary = eaMiscES; break; default: goto SkipBadNamespace; } if (!eventargs.Skip) { //TempHackInsteadOfDefaultSettings: if (AWBForm.EditSummaryComboBox.Text == "clean up") { AWBForm.EditSummaryComboBox.Text = "Tagging"; } } ExitMe: if (!_pluginSettings.ManuallyAssess) { DefaultStatusText(); } AWBForm.TraceManager.Flush(); return(res); SkipBadNamespace: //FIXME var eaES = eventargs.EditSummary; var eaSkip = eventargs.Skip; res = Skipping(ref eaES, "", SkipReason.BadNamespace, eventargs.ArticleText, ref eaSkip); eventargs.EditSummary = eaES; eventargs.Skip = eaSkip; goto ExitMe; SkipOrStop: res = eventargs.ArticleText; goto ExitMe; }