Exemplo n.º 1
0
 internal static ArticleEX SwitchToNewArticleObject(ArticleEX old, ArticleEX @new)
 {
     if(old != null && old.LogListener != null)
         Close(); // remove old AWBLogListener from MyTrace collection
     @new.InitialiseLogListener(); // create new listener and add to collection
     return @new;
 }
Exemplo n.º 2
0
 internal static ArticleEX SwitchToNewArticleObject(ArticleEX Old, ArticleEX New)
 {
     if (Old != null && Old.LogListener != null)
     {
         Close();                 // remove old AWBLogListener from MyTrace collection
     }
     New.InitialiseLogListener(); // create new listener and add to collection
     return(New);
 }
Exemplo n.º 3
0
        private void CaseWasLoad(string articleText)
        {
            if (StopProcessing)
                return;

            if (!preParseModeToolStripMenuItem.Checked && !CheckLoginStatus()) return;

            if (Program.MyTrace.HaveOpenFile)
                Program.MyTrace.WriteBulletedLine("AWB started processing", true, true, true);
            else
                Program.MyTrace.Initialise();

            Text = SettingsFileDisplay + " - " + TheArticle.Name;

            bool articleIsRedirect = Tools.IsRedirect(articleText);

            if (chkSkipIfRedirect.Checked && articleIsRedirect)
            {
                SkipPage("Page is a redirect");
                return;
            }

            if (articleIsRedirect)
                Redirects++;
            else
                Redirects = 0;

            //check for redirect
            if (bypassRedirectsToolStripMenuItem.Checked && articleIsRedirect && !PageReload)
            {
                // Warning: Creating an ArticleEX causes a new AWBLogListener to be created and it becomes the active listener in MyTrace; be careful we're writing to the correct log listener
                ArticleEX redirect = new ArticleEX(Tools.RedirectTarget(articleText));

                if (redirect.Name.Trim() != "" && Tools.IsValidTitle(redirect.Name))
                {
                    if (filterOutNonMainSpaceToolStripMenuItem.Checked && (redirect.NameSpaceKey != 0))
                    {
                        listMaker.Remove(TheArticle); // or we get stuck in a loop
                        TheArticle = redirect; // if we didn't do this, we were writing the SkipPage info to the AWBLogListener belonging to the object redirect and resident in the MyTrace collection, but then attempting to add TheArticle's log listener to the logging tab
                        SkipPage("Page is not in mainspace");
                        return;
                    }

                    if (redirect.Name == TheArticle.Name)
                    {//ignore recursive redirects
                        TheArticle = redirect;
                        SkipPage("Recursive redirect");
                        return;
                    }

                    if (ArticleWasRedirected != null)
                        ArticleWasRedirected(TheArticle.Name, redirect.Name);

                    listMaker.ReplaceArticle(TheArticle, new Article(redirect.Name));
                    TheArticle = new ArticleEX(redirect.Name);

                    // don't allow redirects to a redirect as we could go round in circles
                    if (Redirects > 1)
                    {
                        SkipPage("Double redirect");
                        return;
                    }

                    if (preParseModeToolStripMenuItem.Checked)
                        StartAPITextLoad(redirect.Name);
                    else
                        webBrowserEdit.LoadEditPage(redirect.Name);

                    return;
                }
            }

            if (!preParseModeToolStripMenuItem.Checked && webBrowserEdit.EditBoxTag.Contains("readonly=\"readonly\""))
            {
                if (!webBrowserEdit.UserAllowedToEdit())
                {
                    NudgeTimer.Stop();
                    SkipPage("Database is locked");
                    return;
                }
            }

            TheArticle.OriginalArticleText = articleText;

            int.TryParse(webBrowserEdit.GetScriptingVar("wgCurRevisionId"), out ErrorHandler.CurrentRevision);

            if (PageReload)
            {
                PageReload = false;
                GetDiff();
                return;
            }

            if (!preParseModeToolStripMenuItem.Checked && SkipChecks()) // normal mode
                return;

            //check not in use
            if (TheArticle.IsInUse)
                if (chkSkipIfInuse.Checked)
                {
                    SkipPage("Page contains {{inuse}}");
                    return;
                }
                else if (!BotMode && !preParseModeToolStripMenuItem.Checked)
                    MessageBox.Show("This page has the \"Inuse\" tag, consider skipping it");

            if (automaticallyDoAnythingToolStripMenuItem.Checked)
            {
                StatusLabelText = "Processing page";
                Application.DoEvents();

                //FIXME: this position is imprefect, since above there is code that can explode, but this way
                //at least we don't get bogus reports of unrelated pages
                ErrorHandler.CurrentPage = TheArticle.Name;

                ProcessPage(TheArticle, true);

                ErrorHandler.CurrentPage = "";

                UpdateWebBrowserStatus(null, null);
                UpdateCurrentTypoStats();

                if (!Abort)
                {
                    if (TheArticle.SkipArticle)
                    {
                        SkipPageReasonAlreadyProvided(); // Don't send a reason; ProcessPage() should already have logged one
                        return;
                    }

                    if (skippable && (chkSkipNoChanges.Checked || BotMode) && TheArticle.NoArticleTextChanged)
                    {
                        SkipPage("No change");
                        return;
                    }

                    if (chkSkipWhitespace.Checked && chkSkipCasing.Checked && TheArticle.OnlyWhiteSpaceAndCasingChanged)
                    {
                        SkipPage("Only whitespace/casing changed");
                        return;
                    }

                    if (chkSkipWhitespace.Checked && TheArticle.OnlyWhiteSpaceChanged)
                    {
                        SkipPage("Only whitespace changed");
                        return;
                    }

                    if (chkSkipCasing.Checked && TheArticle.OnlyCasingChanged)
                    {
                        SkipPage("Only casing changed");
                        return;
                    }

                    if (chkSkipMinorGeneralFixes.Checked && chkGeneralFixes.Checked && TheArticle.OnlyMinorGeneralFixesChanged)
                    {
                        SkipPage("Only minor general fix changes");
                        return;
                    }

                    if (chkSkipGeneralFixes.Checked && chkGeneralFixes.Checked && TheArticle.OnlyGeneralFixesChanged)
                    {
                        SkipPage("Only general fix changes");
                        return;
                    }
                }
            }

            // check for {{sic}} tags etc. when doing typo fixes and not in pre-parse mode
            if (chkRegExTypo.Checked && !preParseModeToolStripMenuItem.Checked && TheArticle.HasSicTag)
                MessageBox.Show(@"This page contains a 'sic' tag or template, please take extra care when correcting typos.", "'sic' tag in page", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            if (preParseModeToolStripMenuItem.Checked)
            {
                if (SkipChecks())
                    return;

                // if we reach here the article has valid changes, so move on to next article

                // if user has loaded a settings file, save it every 10 ignored edits
                if (!string.IsNullOrEmpty(SettingsFile) && (NumberOfIgnoredEdits > 5) && (NumberOfIgnoredEdits % 10 == 0))
                    SavePrefs(SettingsFile);

                // request list maker to focus next article in list; if there is a next article process it, otherwise pre-parsing has finished, save settings
                // but don't save when settings have just been saved by logic above
                if (listMaker.NextArticle())
                    Start();
                else
                {
                    Stop();
                    if (!string.IsNullOrEmpty(SettingsFile) && !(NumberOfIgnoredEdits % 10 == 0))
                        SavePrefs(SettingsFile);
                }

                return;
            }

            if (syntaxHighlightEditBoxToolStripMenuItem.Checked)
                txtEdit.Visible = false;
            
            webBrowserEdit.SetArticleText(TheArticle.ArticleText);
            txtEdit.Text = TheArticle.ArticleText;

            //Update statistics and alerts
            if (!BotMode)
                ArticleInfo(false);

            if (chkSkipNoPageLinks.Checked && (lblLinks.Text == "Links: 0"))
            {
                SkipPage("Page contains no links");
                return;
            }

            if (!Abort)
            {
                if (BotMode)
                {
                    StartDelayedAutoSaveTimer();
                    return;
                }

                switch (toolStripComboOnLoad.SelectedIndex)
                {
                    case 0:
                        GetDiff();
                        break;
                    case 1:
                        GetPreview();
                        break;
                    case 2:
                        GuiUpdateAfterProcessing();

                        txtEdit.Focus();
                        txtEdit.SelectionLength = 0;
                        break;
                }

                SetWatchButton(webBrowserEdit.IsWatched());

                txtReviewEditSummary.Text = MakeSummary();

                Variables.Profiler.Profile("Make Edit summary");

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Detect_multiple_DEFAULTSORT
                if (WikiRegexes.Defaultsort.Matches(txtEdit.Text).Count > 1)
                    lblWarn.Text += "Multiple DEFAULTSORTs found\r\n";

                int bracketLength = 0;
                int unbalancedBracket = TheArticle.UnbalancedBrackets(ref bracketLength);
                if(unbalancedBracket > 0)
                    lblWarn.Text += "Unbalanced brackets found\r\n";

                Variables.Profiler.Profile("Unbalanced brackets");

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Some_additional_edits
                if (TheArticle.HasDeadLinks)
                    lblWarn.Text += "Dead links found\r\n";

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Working_with_Alerts
                if (chkSkipIfNoAlerts.Checked && lblWarn.Text.Length == 0)
                {
                    SkipPage("Page has no alerts");
                    return;
                }
                
                // syntax highlighting of edit box based on m:extension:wikEd standards
                if (syntaxHighlightEditBoxToolStripMenuItem.Checked)
                {                    
                    txtEdit.Visible = false;

                    Variables.Profiler.Profile("Alerts");
                    txtEdit = HighlightSyntax(txtEdit);
                    Variables.Profiler.Profile("Syntax highlighting");

                    if (!focusAtEndOfEditTextBoxToolStripMenuItem.Checked)
                    {
                        txtEdit.SetEditBoxSelection(0, 0);
                        txtEdit.Select(0, 0);
                        txtEdit.ScrollToCaret();
                    }

                    txtEdit.Visible = true;
                }

                if (focusAtEndOfEditTextBoxToolStripMenuItem.Checked)
                {
                    txtEdit.Select(txtEdit.Text.Length, 0);
                    txtEdit.ScrollToCaret();
                }
                else
                {
                    if (unbalancedBracket < 0)
                        btnSave.Focus();
                    else if (scrollToUnbalancedBracketsToolStripMenuItem.Checked)
                    {
                        EditBoxTab.SelectedTab = tpEdit;

                        // indexes in articleText and txtEdit.Edit are offset by the number of newlines before the index of the unbalanced brackets
                        // so allow for this when highlighting the unbalanced bracket
                        string a = txtEdit.Text.Substring(0, unbalancedBracket);
                        int b = Regex.Matches(a, "\n").Count;
                        txtEdit.SetEditBoxSelection(unbalancedBracket - b, bracketLength);
                        txtEdit.SelectionBackColor = Color.Red;
                    }
                }
            }
            else
            {
                EnableButtons();
                Abort = false;
            }
        }
Exemplo n.º 4
0
        private void Start()
        {
            if (StopProcessing)
                return;

            try
            {
                Tools.WriteDebug(Name, "Starting");

                Shutdown();

                //check edit summary
                txtEdit.Enabled = true;
                SetEditToolBarEnabled(true);

                if (Variables.Project != ProjectEnum.custom && string.IsNullOrEmpty(cmboEditSummary.Text) && Plugin.Items.Count == 0)
                {
                    MessageBox.Show("Please enter an edit summary.", "Edit summary", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    Stop();
                    return;
                }

                if (!string.IsNullOrEmpty(cmboEditSummary.Text) && !cmboEditSummary.Items.Contains(cmboEditSummary.Text))
                    cmboEditSummary.Items.Add(cmboEditSummary.Text);

                txtReviewEditSummary.Text = "";

                StopDelayedRestartTimer();
                DisableButtons();

                skippable = true;
                txtEdit.Clear();

                ArticleInfo(true);

                if (listMaker.NumberOfArticles < 1)
                {
                    webBrowserEdit.Busy = false;
                    StopSaveInterval();
                    lblTimer.Text = "";
                    StatusLabelText = "No articles in list, you need to use the Make list";
                    Text = Program.NAME;
                    listMaker.MakeListEnabled = true;
                    return;
                }

                webBrowserEdit.Busy = true;

                if (!Tools.IsValidTitle(listMaker.SelectedArticle().Name))
                {
                    SkipPage("Invalid page title");
                    return;
                }

                if (BotMode)
                    NudgeTimer.StartMe();

                TheArticle = new ArticleEX(listMaker.SelectedArticle().Name);

                NewHistory();
                NewWhatLinksHere();

                EditBoxSaveTimer.Enabled = AutoSaveEditBoxEnabled;

                //if (dlg != null && dlg.AutoProtectAll)
                //    webBrowserEdit.ProtectPage(TheArticle.Name, dlg.Summary, dlg.EditProtectionLevel, dlg.MoveProtectionLevel, dlg.ProtectExpiry);

                //Navigate to edit page
                if (preParseModeToolStripMenuItem.Checked)
                    StartAPITextLoad(TheArticle.Name);
                else
                {
                    webBrowserEdit.BringToFront();

                    if (webBrowserEdit.IsBusy)
                        webBrowserEdit.Stop();

                    if (webBrowserEdit.Document != null)
                        webBrowserEdit.Document.Write("");

                    //check we are logged in
                    if (!Variables.User.WikiStatus && !CheckStatus(false))
                        return;

                    webBrowserEdit.Busy = true;

                    //Navigate to edit page
                    webBrowserEdit.LoadEditPage(TheArticle.Name);
                }
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(Name, "Start() error: " + ex.Message);
                StartDelayedRestartTimer(null, null);
            }

            if (Program.MyTrace.StoppedWithConfigError)
            {
                try
                { Program.MyTrace.ValidateUploadProfile(); }
                catch (Exception ex)
                { Program.MyTrace.ConfigError(ex); }
            }
        }
Exemplo n.º 5
0
        private void ReparseEditBox()
        {
            ArticleEX a = new ArticleEX(TheArticle.Name) {OriginalArticleText = txtEdit.Text};

            ErrorHandler.CurrentPage = TheArticle.Name;
            ProcessPage(a, false);
            ErrorHandler.CurrentPage = "";
            UpdateCurrentTypoStats();
            txtEdit.Text = a.ArticleText;
            GetDiff();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        private void PageLoaded(PageInfo page)
        {
            if (!LoadSuccessApi())
                return;

            Retries = 0;

            StopProgressBar();

            if (_stopProcessing)
                return;
            TheArticle = new ArticleEX(page);

            if (!preParseModeToolStripMenuItem.Checked && !CheckLoginStatus()) return;

            if (Program.MyTrace.HaveOpenFile)
                Program.MyTrace.WriteBulletedLine("AWB started processing", true, true, true);
            else
                Program.MyTrace.Initialise();

            Text = _settingsFileDisplay + " - " + page.Title;

            bool articleIsRedirect = Tools.IsRedirect(page.Text);

            if (chkSkipIfRedirect.Checked && articleIsRedirect)
            {
                SkipPage("Page is a redirect");
                return;
            }

            if (articleIsRedirect)
                _redirects++;
            else
                _redirects = 0;

            //check for redirect
            if (bypassRedirectsToolStripMenuItem.Checked && articleIsRedirect && !PageReload)
            {
                // Warning: Creating an ArticleEX causes a new AWBLogListener to be created and it becomes the active listener in MyTrace; be careful we're writing to the correct log listener
                string redirect = Parsers.CanonicalizeTitleAggressively(Tools.RedirectTarget(page.Text));

                if (!String.IsNullOrEmpty(redirect) && Tools.IsValidTitle(redirect))
                {
                    if (filterOutNonMainSpaceToolStripMenuItem.Checked
                        && (Namespace.Determine(redirect) != Namespace.Article))
                    {
                        SkipRedirect(redirect, "Page is not in mainspace");
                        return;
                    }

                    if (redirect == TheArticle.Name)
                    {
                        //ignore recursive redirects
                        SkipRedirect(redirect, "Recursive redirect");
                        return;
                    }

                    if (ArticleWasRedirected != null)
                        ArticleWasRedirected(TheArticle.Name, redirect);

                    listMaker.ReplaceArticle(TheArticle, new Article(redirect));
                    TheArticle = new ArticleEX(redirect, "");

                    // don't allow redirects to a redirect as we could go round in circles
                    if (_redirects > 1)
                    {
                        SkipPage("Double redirect");
                        return;
                    }

                    OpenPage(redirect);

                    return;
                }
            }

            ErrorHandler.CurrentRevision = page.RevisionID;

            if (PageReload)
            {
                PageReload = false;
                GetDiff();
                return;
            }

            if (SkipChecks(!chkSkipAfterProcessing.Checked)) // pre-processing of article
                return;

            //check not in use
            if (TheArticle.IsInUse)
                if (chkSkipIfInuse.Checked)
                {
                    SkipPage("Page contains {{inuse}}");
                    return;
                }
                else if (!BotMode && !preParseModeToolStripMenuItem.Checked)
                    MessageBox.Show("This page has the \"Inuse\" tag, consider skipping it");

            if (automaticallyDoAnythingToolStripMenuItem.Checked)
            {
                StatusLabelText = "Processing page";
                Application.DoEvents();

                //FIXME: this position is imprefect, since above there is code that can explode, but this way
                //at least we don't get bogus reports of unrelated pages
                ErrorHandler.CurrentPage = TheArticle.Name;

                ProcessPage(TheArticle, true);

                ErrorHandler.CurrentPage = "";

                UpdateCurrentTypoStats();

                if (!Abort)
                {
                    if (TheArticle.SkipArticle)
                    {
                        SkipPageReasonAlreadyProvided(); // Don't send a reason; ProcessPage() should already have logged one
                        return;
                    }

                    if (Skippable && (chkSkipNoChanges.Checked || BotMode) && TheArticle.NoArticleTextChanged)
                    {
                        SkipPage("No change");
                        return;
                    }

                    if (chkSkipWhitespace.Checked && chkSkipCasing.Checked && TheArticle.OnlyWhiteSpaceAndCasingChanged)
                    {
                        SkipPage("Only whitespace/casing changed");
                        return;
                    }

                    if (chkSkipWhitespace.Checked && TheArticle.OnlyWhiteSpaceChanged)
                    {
                        SkipPage("Only whitespace changed");
                        return;
                    }

                    if (chkSkipCasing.Checked && TheArticle.OnlyCasingChanged)
                    {
                        SkipPage("Only casing changed");
                        return;
                    }

                    if (chkSkipMinorGeneralFixes.Checked && chkGeneralFixes.Checked && TheArticle.OnlyMinorGeneralFixesChanged)
                    {
                        SkipPage("Only minor general fix changes");
                        return;
                    }

                    if (chkSkipGeneralFixes.Checked && chkGeneralFixes.Checked && TheArticle.OnlyGeneralFixesChanged)
                    {
                        SkipPage("Only general fix changes");
                        return;
                    }

                    if (chkSkipNoPageLinks.Checked
                        && (WikiRegexes.WikiLinksOnly.Matches(TheArticle.ArticleText).Count == 0))
                    {
                        SkipPage("Page contains no links");
                        return;
                    }

                    // post-processing
                    if (chkSkipAfterProcessing.Checked && SkipChecks(true))
                        return;
                }
            }

            // check for {{sic}} tags etc. when doing typo fixes and not in pre-parse mode
            if (chkRegExTypo.Checked && !preParseModeToolStripMenuItem.Checked && TheArticle.HasSicTag)
                MessageBox.Show(@"This page contains a 'sic' tag or template, please take extra care when correcting typos.", "'sic' tag in page", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            if (preParseModeToolStripMenuItem.Checked)
            {
                // if we reach here the article has valid changes, so move on to next article

                // if user has loaded a settings file, save it every 10 ignored edits
                if (!string.IsNullOrEmpty(SettingsFile) && (NumberOfIgnoredEdits > 5) && (NumberOfIgnoredEdits % 10 == 0))
                    SavePrefs(SettingsFile);

                // request list maker to focus next article in list; if there is a next article process it, otherwise pre-parsing has finished, save settings
                // but don't save when settings have just been saved by logic above
                if (listMaker.NextArticle())
                    Start();
                else
                {
                    Stop();
                    if (autoSaveSettingsToolStripMenuItem.Checked && (NumberOfIgnoredEdits % 10 != 0) && !string.IsNullOrEmpty(SettingsFile))
                        SavePrefs(SettingsFile);
                }

                return;
            }

            if (syntaxHighlightEditBoxToolStripMenuItem.Checked)
                txtEdit.Visible = false;

            txtEdit.Text = TheArticle.ArticleText;

            //Update statistics and alerts
            if (!BotMode)
                ArticleInfo(false);

            if (!Abort)
            {
                bool diffInBotMode = (BotMode && doDiffInBotMode);
                if (BotMode)
                {
                    StartDelayedAutoSaveTimer();

                    if (!diffInBotMode)
                        return;
                }

                switch (actionOnLoad)
                {
                    case 0:
                        GetDiff();

                        if (diffInBotMode)
                        {
                            txtReviewEditSummary.Text = MakeSummary();
                            return;
                        }

                        break;
                    case 1:
                        GetPreview();
                        break;
                    case 2:
                        GuiUpdateAfterProcessing();

                        txtEdit.Focus();
                        txtEdit.SelectionLength = 0;
                        break;
                }

                PageWatched = TheSession.Page.IsWatched;

                txtReviewEditSummary.Text = MakeSummary();

                Variables.Profiler.Profile("Make Edit summary");

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Working_with_Alerts
                if (chkSkipIfNoAlerts.Checked && lblWarn.Text.Length == 0)
                {
                    SkipPage("Page has no alerts");
                    return;
                }

                Variables.Profiler.Profile("Alerts");

                // syntax highlighting of edit box based on m:extension:wikEd standards
                if (syntaxHighlightEditBoxToolStripMenuItem.Checked)
                {
                    txtEdit.Visible = false;

                    HighlightSyntax();
                    Variables.Profiler.Profile("Syntax highlighting");

                    if (!focusAtEndOfEditTextBoxToolStripMenuItem.Checked)
                    {
                        txtEdit.SetEditBoxSelection(0, 0);
                        txtEdit.Select(0, 0);
                        txtEdit.ScrollToCaret();
                    }

                    txtEdit.Visible = true;
                }

                if (highlightAllFindToolStripMenuItem.Checked)
                {
                    txtEdit.Visible = false;
                    HighlightAllFind();
                    txtEdit.Visible = true;
                }

                if (focusAtEndOfEditTextBoxToolStripMenuItem.Checked)
                {
                    txtEdit.Select(txtEdit.Text.Length, 0);
                    txtEdit.ScrollToCaret();
                }
                else
                {
                    if (_unbalancedBracket < 0 && badCiteParameters.Count == 0)
                        btnSave.Focus();
                    else if (scrollToUnbalancedBracketsToolStripMenuItem.Checked)
                    {
                        EditBoxTab.SelectedTab = tpEdit;

                        if (_unbalancedBracket >= 0)
                            HighlightUnbalancedBrackets();

                        if (badCiteParameters.Count > 0)
                            HighlightBadCitationParameter();
                        
                        if(deadLinks.Count > 0)
                            HighlightDeadLinks();
                    }
                }

                StatusLabelText = "Ready to save";
            }
            else
            {
                EnableButtons();
                Abort = false;
            }
        }
Exemplo n.º 7
0
 private void SkipRedirect(string redirectTitle, string reason)
 {
     listMaker.Remove(TheArticle); // or we get stuck in a loop
     TheArticle = new ArticleEX(redirectTitle, "");
     // if we didn't do this, we were writing the SkipPage info to the AWBLogListener belonging to the object redirect and resident in the MyTrace collection, but then attempting to add TheArticle's log listener to the logging tab
     SkipPage(reason);
 }
Exemplo n.º 8
0
        /// <summary>
        /// </summary>
        /// <returns>true if it is ok to call again, or false if processing should now stop</returns>
        private void StartArticleProcessing()
        {
            if (_stopProcessing)
                return;

            try
            {
                Tools.WriteDebug(Name, "Starting");

                Shutdown();

                //check edit summary
                txtEdit.Enabled = true;
                SetEditToolBarEnabled(true);

                if (Variables.Project != ProjectEnum.custom && string.IsNullOrEmpty(cmboEditSummary.Text) &&
                    Plugin.AWBPlugins.Count == 0)
                {
                    MessageBox.Show("Please enter an edit summary.", "Edit summary", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    Stop();
                    return;
                }

                if (!string.IsNullOrEmpty(cmboEditSummary.Text) && !cmboEditSummary.Items.Contains(cmboEditSummary.Text))
                    cmboEditSummary.Items.Add(cmboEditSummary.Text);

                txtReviewEditSummary.Text = "";

                StopDelayedRestartTimer();
                DisableButtons();

                Skippable = true;
                txtEdit.Clear();

                ArticleInfo(true);

                if (listMaker.NumberOfArticles < 1)
                {
                    StopSaveInterval();
                    lblTimer.Text = "";
                    StatusLabelText = "No articles in list, you need to use the Make list";
                    Text = Program.Name;
                    listMaker.MakeListEnabled = true;
                    return;
                }

                string title = listMaker.SelectedArticle().Name;

                if (!Tools.IsValidTitle(title))
                {
                    SkipPage("Invalid page title");
                    return;
                }

                string fixedTitle = Parsers.CanonicalizeTitleAggressively(title);
                if (fixedTitle != title)
                {
                    listMaker.ReplaceArticle(listMaker.SelectedArticle(), new Article(fixedTitle));
                    title = fixedTitle;
                }

                if (BotMode)
                    NudgeTimer.StartMe();

                TheArticle = new ArticleEX(title, "");

                //http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs#.27Find.27_sometimes_fails_to_use_the_search_key
                txtEdit.ResetFind();

                NewHistory(title);
                NewWhatLinksHere(title);

                EditBoxSaveTimer.Enabled = _autoSaveEditBoxEnabled;

                //if (dlg != null && dlg.AutoProtectAll)
                //    TheArticle.Protect(TheSession);

                StartProgressBar();

                //Navigate to edit page
                OpenPage(title);
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(Name, "Start() error: " + ex.Message);
                StartDelayedRestartTimer();
            }

            if (Program.MyTrace.StoppedWithConfigError)
            {
                try
                { Program.MyTrace.ValidateUploadProfile(); }
                catch (Exception ex)
                { Program.MyTrace.ConfigError(ex); }
            }
        }
Exemplo n.º 9
0
        private void ReparseEditBox()
        {
            if (TheArticle == null)
                return;

            ArticleEX a = new ArticleEX(TheArticle.Name, txtEdit.Text);
            ArticleEX theArtricleOriginal = TheArticle;
            ErrorHandler.CurrentPage = TheArticle.Name;
            ProcessPage(a, false);
            ErrorHandler.CurrentPage = "";
            UpdateCurrentTypoStats();

            // provide article statistics based on new article, not the existing one
            TheArticle = a;
            ArticleInfo(false);
            TheArticle = theArtricleOriginal;

            txtEdit.Text = a.ArticleText;

            if (highlightAllFindToolStripMenuItem.Checked)
                HighlightAllFind();

            if (scrollToUnbalancedBracketsToolStripMenuItem.Checked)
            {
                if (_unbalancedBracket >= 0)
                    HighlightUnbalancedBrackets();

                if (badCiteParameters.Count > 0)
                    HighlightBadCitationParameter();
            }

            if (syntaxHighlightEditBoxToolStripMenuItem.Checked)
            {
                txtEdit.Visible = false;
                HighlightSyntax();
                txtEdit.Visible = true;
            }

            GetDiff();
        }
Exemplo n.º 10
0
        private void CaseWasLoad(object sender, EventArgs e)
        {
            if (!LoadSuccess()) return;

            if (!CheckLoginStatus()) return;

            if (Program.MyTrace.HaveOpenFile)
                Program.MyTrace.WriteBulletedLine("AWB started processing", true, true, true);
            else
                Program.MyTrace.Initialise();

            string strTemp = webBrowserEdit.GetArticleText();

            this.Text = SettingsFileDisplay + " - " + TheArticle.Name;

            //check for redirect
            if (bypassRedirectsToolStripMenuItem.Checked && Tools.IsRedirect(strTemp) && !PageReload)
            {
                // Warning: Creating an ArticleEX causes a new AWBLogListener to be created and it becomes the active listener in MyTrace; be careful we're writing to the correct log listener
                ArticleEX redirect = new ArticleEX(Tools.RedirectTarget(strTemp));

                if (filterOutNonMainSpaceToolStripMenuItem.Checked && (redirect.NameSpaceKey != 0))
                {
                    listMaker.Remove(TheArticle); // or we get stuck in a loop
                    TheArticle = redirect; // if we didn't do this, we were writing the SkipPage info to the AWBLogListener belonging to the object redirect and resident in the MyTrace collection, but then attempting to add TheArticle's log listener to the logging tab
                    SkipPage("Page is not in mainspace");
                    return;
                }

                if (redirect.Name == TheArticle.Name)
                {//ignore recursive redirects
                    TheArticle = redirect;
                    SkipPage("Recursive redirect");
                    return;
                }
                if (ArticleWasRedirected != null)
                    ArticleWasRedirected(TheArticle.Name, redirect.Name);

                listMaker.ReplaceArticle(TheArticle, new Article(redirect.Name));
                TheArticle = new ArticleEX(redirect.Name);

                webBrowserEdit.LoadEditPage(redirect.Name);
                return;
            }

            if (webBrowserEdit.EditBoxTag.Contains("readonly=\"readonly\""))
            {
                if (!webBrowserEdit.UserAllowedToEdit())
                {
                    NudgeTimer.Stop();
                    SkipPage("Page is protected");
                    return;
                }
                //TODO: are every other cases related to DB lock?
            }

            TheArticle.OriginalArticleText = strTemp;

            int.TryParse(webBrowserEdit.GetScriptingVar("wgCurRevisionId"), out ErrorHandler.CurrentRevision);

            if (PageReload)
            {
                PageReload = false;
                GetDiff();
                return;
            }

            if (chkSkipIfContains.Checked && TheArticle.SkipIfContains(txtSkipIfContains.Text,
                chkSkipIsRegex.Checked, chkSkipCaseSensitive.Checked, true))
            {
                SkipPage("Page contains: " + txtSkipIfContains.Text);
                return;
            }

            if (chkSkipIfNotContains.Checked && TheArticle.SkipIfContains(txtSkipIfNotContains.Text,
                chkSkipIsRegex.Checked, chkSkipCaseSensitive.Checked, false))
            {
                SkipPage("Page does not contain: " + txtSkipIfNotContains.Text);
                return;
            }

            if (!Skip.SkipIf(TheArticle.OriginalArticleText))
            {
                SkipPage("skipIf custom code");
                return;
            }

            //check not in use
            if (TheArticle.IsInUse)
                if (chkSkipIfInuse.Checked)
                {
                    SkipPage("Page contains {{inuse}}");
                    return;
                }
                else if (!BotMode)
                    MessageBox.Show("This page has the \"Inuse\" tag, consider skipping it");

            if (automaticallyDoAnythingToolStripMenuItem.Checked)
            {
                StatusLabelText = "Processing page";
                Application.DoEvents();

                //FIXME: this position is imprefect, since above there is code that can explode, but this way
                //at least we don't get bogus reports of unrelated pages
                ErrorHandler.CurrentPage = TheArticle.Name;

                ProcessPage(TheArticle, true);

                ErrorHandler.CurrentPage = "";

                UpdateWebBrowserStatus(null, null);
                UpdateCurrentTypoStats();

                if (!Abort)
                {
                    if (TheArticle.SkipArticle)
                    {
                        SkipPageReasonAlreadyProvided(); // Don't send a reason; ProcessPage() should already have logged one
                        return;
                    }

                    if (skippable && chkSkipNoChanges.Checked && TheArticle.NoArticleTextChanged)
                    {
                        SkipPage("No change");
                        return;
                    }

                    if (chkSkipWhitespace.Checked && chkSkipCasing.Checked && TheArticle.OnlyWhiteSpaceAndCasingChanged)
                    {
                        SkipPage("Only whitespace/casing changed");
                        return;
                    }

                    if (chkSkipWhitespace.Checked && TheArticle.OnlyWhiteSpaceChanged)
                    {
                        SkipPage("Only whitespace changed");
                        return;
                    }

                    if (chkSkipCasing.Checked && TheArticle.OnlyCasingChanged)
                    {
                        SkipPage("Only casing changed");
                        return;
                    }

                    if (chkSkipGeneralFixes.Checked && chkGeneralFixes.Checked && TheArticle.OnlyGeneralFixesChanged)
                    {
                        SkipPage("Only general fix changes");
                        return;
                    }
                }
            }

            webBrowserEdit.SetArticleText(TheArticle.ArticleText);
            txtEdit.Text = TheArticle.ArticleText;

            //Update statistics and alerts
            ArticleInfo(false);

            if (chkSkipNoPageLinks.Checked && (lblLinks.Text == "Links: 0"))
            {
                SkipPage("Page contains no Links");
                return;
            }

            if (!Abort)
            {
                switch (toolStripComboOnLoad.SelectedIndex)
                {
                    case 0:
                        GetDiff();
                        break;
                    case 1:
                        GetPreview();
                        break;
                    case 3:
                        {
                            if (BotMode)
                            {
                                StartDelayedAutoSaveTimer();
                                return;
                            }

                            Bleepflash();

                            this.Focus();
                            txtEdit.Focus();
                            txtEdit.SelectionLength = 0;

                            EnableButtons();
                            break;
                        }
                }
                SetWatchButton(webBrowserEdit.IsWatched());

                if (focusAtEndOfEditTextBoxToolStripMenuItem.Checked)
                {
                    txtEdit.Select(txtEdit.Text.Length, 0);
                    txtEdit.ScrollToCaret();
                }
            }
            else
            {
                EnableButtons();
                Abort = false;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Fully processes a page, applying all needed changes
        /// </summary>
        /// <param name="theArticle">Page to process</param>
        /// <param name="mainProcess">True if the page is being processed for save as usual,
        /// otherwise (Re-parse in context menu, prefetch, etc) false</param>
        private void ProcessPage(ArticleEX theArticle, bool mainProcess)
        {
            bool process = true;
            typoStats = null;

#if DEBUG
            Variables.Profiler.Start("ProcessPage(\"" + theArticle.Name + "\")");
#endif

            try
            {
                if (noParse.Contains(theArticle.Name))
                    process = false;

                if (!IgnoreNoBots &&
                    !Parsers.CheckNoBots(theArticle.ArticleText, Variables.User.Name))
                {
                    theArticle.AWBSkip("Restricted by {{bots}}/{{nobots}}");
                    return;
                }

                Variables.Profiler.Profile("Initial skip checks");

                if (cModule.ModuleEnabled && cModule.Module != null)
                {
                    theArticle.SendPageToCustomModule(cModule.Module);
                    if (theArticle.SkipArticle) return;
                }

                Variables.Profiler.Profile("Custom module");

                if (externalProgram.ModuleEnabled)
                {
                    theArticle.SendPageToCustomModule(externalProgram);
                    if (theArticle.SkipArticle) return;
                }

                Variables.Profiler.Profile("External Program");

                if (Plugin.Items.Count > 0)
                {
                    foreach (KeyValuePair<string, IAWBPlugin> a in Plugin.Items)
                    {
                        theArticle.SendPageToPlugin(a.Value, this);
                        if (theArticle.SkipArticle) return;
                    }
                }
                Variables.Profiler.Profile("Plugins");

                // unicodify whole article
                if (chkUnicodifyWhole.Checked && process)
                {
                    theArticle.HideMoreText(RemoveText);
                    Variables.Profiler.Profile("HideMoreText");

                    theArticle.Unicodify(Skip.SkipNoUnicode, parsers);
                    Variables.Profiler.Profile("Unicodify");

                    theArticle.UnHideMoreText(RemoveText);
                    Variables.Profiler.Profile("UnHideMoreText");
                }

                // find and replace before general fixes
                if (chkFindandReplace.Checked && !findAndReplace.AfterOtherFixes)
                {
                    theArticle.PerformFindAndReplace(findAndReplace, substTemplates, replaceSpecial,
                        chkSkipWhenNoFAR.Checked);

                    Variables.Profiler.Profile("F&R");

                    if (theArticle.SkipArticle) return;
                }

                // RegexTypoFix
                if (chkRegExTypo.Checked && RegexTypos != null && !BotMode && !Tools.IsTalkPage(theArticle.NameSpaceKey))
                {
                    theArticle.PerformTypoFixes(RegexTypos, chkSkipIfNoRegexTypo.Checked);
                    Variables.Profiler.Profile("Typos");
                    typoStats = RegexTypos.GetStatistics();
                    if (theArticle.SkipArticle)
                    {
                        if (mainProcess)
                        {   // update stats only if not called from e.g. 'Re-parse' than could be clicked repeatedly
                            OverallTypoStats.UpdateStats(typoStats, true);
                            UpdateTypoCount();
                        }
                        return;
                    }
                }

                // replace/add/remove categories
                if (cmboCategorise.SelectedIndex != 0)
                {
                    theArticle.Categorisation((WikiFunctions.Options.CategorisationOptions)
                        cmboCategorise.SelectedIndex, parsers, chkSkipNoCatChange.Checked, txtNewCategory.Text.Trim(),
                        txtNewCategory2.Text.Trim());
                    if (theArticle.SkipArticle) return;
                    else if (!chkGeneralFixes.Checked) theArticle.AWBChangeArticleText("Fix categories", Parsers.FixCategories(theArticle.ArticleText), true);
                }

                Variables.Profiler.Profile("Categories");

                if (theArticle.CanDoGeneralFixes)
                {
                    // auto tag
                    if (process && chkAutoTagger.Checked)
                    {
                        theArticle.AutoTag(parsers, Skip.SkipNoTag);
                        if (theArticle.SkipArticle) return;
                    }

                    Variables.Profiler.Profile("Auto-tagger");

                    if (process && chkGeneralFixes.Checked)
                    {
                        theArticle.PerformGeneralFixes(parsers, RemoveText, Skip, replaceReferenceTagsToolStripMenuItem.Checked);
                    }
                }
                else if (process && chkGeneralFixes.Checked && theArticle.NameSpaceKey == 3)
                {
                    if (!userTalkWarningsLoaded)
                    {
                        LoadUserTalkWarnings();
                        Variables.Profiler.Profile("loadUserTalkWarnings");
                    }

                    theArticle.PerformUserTalkGeneralFixes(RemoveText, userTalkTemplatesRegex, Skip.SkipNoUserTalkTemplatesSubstd);
                }

                // find and replace after general fixes
                if (chkFindandReplace.Checked && findAndReplace.AfterOtherFixes)
                {
                    theArticle.PerformFindAndReplace(findAndReplace, substTemplates, replaceSpecial,
                        chkSkipWhenNoFAR.Checked);

                    Variables.Profiler.Profile("F&R (2nd)");

                    if (theArticle.SkipArticle) return;
                }

                // append/prepend text
                if (chkAppend.Checked)
                {
                    // customized number of newlines
                    String newlines = "";
                    for (int i = 0; i < (int)udNewlineChars.Value; i++)
                        newlines += "\r\n";

                    if (rdoAppend.Checked)
                        theArticle.AWBChangeArticleText("Appended your message",
                            theArticle.ArticleText + newlines + Tools.ApplyKeyWords(theArticle.Name, txtAppendMessage.Text), false);
                    else
                        theArticle.AWBChangeArticleText("Prepended your message",
                            Tools.ApplyKeyWords(theArticle.Name, txtAppendMessage.Text) + newlines + theArticle.ArticleText, false);
                }

                // replace/remove/comment out images
                if (cmboImages.SelectedIndex != 0)
                {
                    theArticle.UpdateImages((WikiFunctions.Options.ImageReplaceOptions)cmboImages.SelectedIndex,
                        parsers, txtImageReplace.Text, txtImageWith.Text, chkSkipNoImgChange.Checked);
                    if (theArticle.SkipArticle) return;
                }

                Variables.Profiler.Profile("Images");

                // disambiguation
                if (chkEnableDab.Checked && txtDabLink.Text.Trim().Length > 0 &&
                    txtDabVariants.Text.Trim().Length > 0)
                {
                    if (theArticle.Disambiguate(txtDabLink.Text.Trim(), txtDabVariants.Lines, BotMode,
                        (int)udContextChars.Value, chkSkipNoDab.Checked))
                    {
                        if (theArticle.SkipArticle) return;
                    }
                    else
                    {
                        Abort = true;
                        Stop();
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.Handle(ex);
                theArticle.Trace.AWBSkipped("Exception:" + ex.Message);
            }
            finally
            {
                Variables.Profiler.Flush();
            }
        }
Exemplo n.º 12
0
        private void ReparseEditBox()
        {
            ArticleEX a = new ArticleEX(TheArticle.Name) {OriginalArticleText = txtEdit.Text};
            ArticleEX theArtricleOriginal = TheArticle;
            ErrorHandler.CurrentPage = TheArticle.Name;
            ProcessPage(a, false);
            ErrorHandler.CurrentPage = "";
            UpdateCurrentTypoStats();

            // provide article statistics based on new article, not the existing one
            TheArticle = a;
            ArticleInfo(false);
            TheArticle = theArtricleOriginal;

            txtEdit.Text = a.ArticleText;

            if (unbalancedBracket >= 0 && scrollToUnbalancedBracketsToolStripMenuItem.Checked)
            {
                highlightUnbalancedBrackets();
            }

            if (syntaxHighlightEditBoxToolStripMenuItem.Checked)
            {
                txtEdit.Visible = false;
                HighlightSyntax();
                txtEdit.Visible = true;
            }

            GetDiff();
        }
Exemplo n.º 13
0
        private void CaseWasLoad(string articleText)
        {
            if (stopProcessing)
                return;

            if (!CheckLoginStatus()) return;

            if (Program.MyTrace.HaveOpenFile)
                Program.MyTrace.WriteBulletedLine("AWB started processing", true, true, true);
            else
                Program.MyTrace.Initialise();

            Text = SettingsFileDisplay + " - " + TheArticle.Name;

            bool articleIsRedirect = Tools.IsRedirect(articleText);

            if (chkSkipIfRedirect.Checked && articleIsRedirect)
            {
                SkipPage("Page is a redirect");
                return;
            }

            //check for redirect
            if (bypassRedirectsToolStripMenuItem.Checked && articleIsRedirect && !PageReload)
            {
                // Warning: Creating an ArticleEX causes a new AWBLogListener to be created and it becomes the active listener in MyTrace; be careful we're writing to the correct log listener
                ArticleEX redirect = new ArticleEX(Tools.RedirectTarget(articleText));

                if (redirect.Name.Trim() != "" && Tools.IsValidTitle(redirect.Name))
                {
                    if (filterOutNonMainSpaceToolStripMenuItem.Checked && (redirect.NameSpaceKey != 0))
                    {
                        listMaker.Remove(TheArticle); // or we get stuck in a loop
                        TheArticle = redirect; // if we didn't do this, we were writing the SkipPage info to the AWBLogListener belonging to the object redirect and resident in the MyTrace collection, but then attempting to add TheArticle's log listener to the logging tab
                        SkipPage("Page is not in mainspace");
                        return;
                    }

                    if (redirect.Name == TheArticle.Name)
                    {//ignore recursive redirects
                        TheArticle = redirect;
                        SkipPage("Recursive redirect");
                        return;
                    }
                    if (ArticleWasRedirected != null)
                        ArticleWasRedirected(TheArticle.Name, redirect.Name);

                    listMaker.ReplaceArticle(TheArticle, new Article(redirect.Name));
                    TheArticle = new ArticleEX(redirect.Name);

                    if (preParseModeToolStripMenuItem.Checked)
                        StartAPITextLoad(redirect.Name);
                    else
                        webBrowserEdit.LoadEditPage(redirect.Name);

                    return;
                }
            }

            if (!preParseModeToolStripMenuItem.Checked && webBrowserEdit.EditBoxTag.Contains("readonly=\"readonly\""))
            {
                if (!webBrowserEdit.UserAllowedToEdit())
                {
                    NudgeTimer.Stop();
                    SkipPage("Database is locked");
                    return;
                }
            }

            TheArticle.OriginalArticleText = articleText;

            int.TryParse(webBrowserEdit.GetScriptingVar("wgCurRevisionId"), out ErrorHandler.CurrentRevision);

            if (PageReload)
            {
                PageReload = false;
                GetDiff();
                return;
            }

            if (!preParseModeToolStripMenuItem.Checked && SkipChecks()) // normal mode
                return;

            //check not in use
            if (TheArticle.IsInUse)
                if (chkSkipIfInuse.Checked)
                {
                    SkipPage("Page contains {{inuse}}");
                    return;
                }
                else if (!BotMode && !preParseModeToolStripMenuItem.Checked)
                    MessageBox.Show("This page has the \"Inuse\" tag, consider skipping it");

            // check for {{sic}} tags etc. when doing typo fixes and not in pre-parse mode
            if(chkRegExTypo.Checked && !preParseModeToolStripMenuItem.Checked && TheArticle.HasSicTag)
                MessageBox.Show(@"This page contains a 'sic' tag or template, please take extra care when correcting typos.", "'sic' tag in page", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            if (automaticallyDoAnythingToolStripMenuItem.Checked)
            {
                StatusLabelText = "Processing page";
                Application.DoEvents();

                //FIXME: this position is imprefect, since above there is code that can explode, but this way
                //at least we don't get bogus reports of unrelated pages
                ErrorHandler.CurrentPage = TheArticle.Name;

                ProcessPage(TheArticle, true);

                ErrorHandler.CurrentPage = "";

                UpdateWebBrowserStatus(null, null);
                UpdateCurrentTypoStats();

                if (!Abort)
                {
                    if (TheArticle.SkipArticle)
                    {
                        SkipPageReasonAlreadyProvided(); // Don't send a reason; ProcessPage() should already have logged one
                        return;
                    }

                    if (skippable && (chkSkipNoChanges.Checked || BotMode) && TheArticle.NoArticleTextChanged)
                    {
                        SkipPage("No change");
                        return;
                    }

                    if (chkSkipWhitespace.Checked && chkSkipCasing.Checked && TheArticle.OnlyWhiteSpaceAndCasingChanged)
                    {
                        SkipPage("Only whitespace/casing changed");
                        return;
                    }

                    if (chkSkipWhitespace.Checked && TheArticle.OnlyWhiteSpaceChanged)
                    {
                        SkipPage("Only whitespace changed");
                        return;
                    }

                    if (chkSkipCasing.Checked && TheArticle.OnlyCasingChanged)
                    {
                        SkipPage("Only casing changed");
                        return;
                    }
                    
                    if(chkSkipMinorGeneralFixes.Checked && chkGeneralFixes.Checked && TheArticle.OnlyMinorGeneralFixesChanged)
                    {
                        SkipPage("Only minor general fix changes");
                        return;
                    }

                    if (chkSkipGeneralFixes.Checked && chkGeneralFixes.Checked && TheArticle.OnlyGeneralFixesChanged)
                    {
                        SkipPage("Only general fix changes");
                        return;
                    }
                }
            }

            if (preParseModeToolStripMenuItem.Checked)
            {
                if (SkipChecks())
                    return;

                // if we reach here the article has valid changes, so move on to next article

                // if user has loaded a settings file, save it every 10 ignored edits
                if (!string.IsNullOrEmpty(SettingsFile) && (NumberOfIgnoredEdits > 5) && (NumberOfIgnoredEdits % 10 == 0))
                    SavePrefs(SettingsFile);

                // request list maker to focus next article in list; if there is a next article process it, otherwise pre-parsing has finished, save settings
                // but don't save when settings have just been saved by logic above
                if (listMaker.NextArticle())
                    Start();
                else
                {
                    Stop();
                    if (!string.IsNullOrEmpty(SettingsFile) && !(NumberOfIgnoredEdits % 10 == 0))
                        SavePrefs(SettingsFile);
                }

                return;
            }

            webBrowserEdit.SetArticleText(TheArticle.ArticleText);
            txtEdit.Text = TheArticle.ArticleText;

            //Update statistics and alerts
            ArticleInfo(false);

            if (chkSkipNoPageLinks.Checked && (lblLinks.Text == "Links: 0"))
            {
                SkipPage("Page contains no links");
                return;
            }

            if (!Abort)
            {
                if (BotMode)
                {
                    StartDelayedAutoSaveTimer();
                    return;
                }

                switch (toolStripComboOnLoad.SelectedIndex)
                {
                    case 0:
                        GetDiff();
                        break;
                    case 1:
                        GetPreview();
                        break;
                    case 2:
                        GuiUpdateAfterProcessing();

                        txtEdit.Focus();
                        txtEdit.SelectionLength = 0;
                        break;
                }

                SetWatchButton(webBrowserEdit.IsWatched());

                txtReviewEditSummary.Text = MakeSummary();

                if (focusAtEndOfEditTextBoxToolStripMenuItem.Checked)
                {
                    txtEdit.Select(txtEdit.Text.Length, 0);
                    txtEdit.ScrollToCaret();
                }
                else
                    btnSave.Focus();
            }
            else
            {
                EnableButtons();
                Abort = false;
            }
        }
Exemplo n.º 14
0
        private void ReparseEditBox()
        {
            ArticleEX a = new ArticleEX(TheArticle.Name) {OriginalArticleText = txtEdit.Text};
            ArticleEX theArtricleOriginal = TheArticle;
            ErrorHandler.CurrentPage = TheArticle.Name;
            ProcessPage(a, false);
            ErrorHandler.CurrentPage = "";
            UpdateCurrentTypoStats();

            // provide article statistics based on new article, not the existing one
            TheArticle = a;
            ArticleInfo(false);
            TheArticle = theArtricleOriginal;

            txtEdit.Text = a.ArticleText;
            GetDiff();
        }
Exemplo n.º 15
0
        private void CaseWasLoad(object sender, EventArgs e)
        {
            if (!LoadSuccess())
                return;

            if (!CheckLoginStatus()) return;

            if (Program.MyTrace.HaveOpenFile)
                Program.MyTrace.WriteBulletedLine("AWB started processing", true, true, true);
            else
                Program.MyTrace.Initialise();

            string strTemp = webBrowserEdit.GetArticleText();

            this.Text = SettingsFileDisplay + " - " + TheArticle.Name;

            //check for redirect
            if (bypassRedirectsToolStripMenuItem.Checked && Tools.IsRedirect(strTemp) && !PageReload)
            {
                // Warning: Creating an ArticleEX causes a new AWBLogListener to be created and it becomes the active listener in MyTrace; be careful we're writing to the correct log listener
                ArticleEX redirect = new ArticleEX(Tools.RedirectTarget(strTemp));

                if (filterOutNonMainSpaceToolStripMenuItem.Checked && (redirect.NameSpaceKey != 0))
                {
                    listMaker1.Remove(TheArticle); // or we get stuck in a loop
                    TheArticle = redirect; // if we didn't do this, we were writing the SkipPage info to the AWBLogListener belonging to the object redirect and resident in the MyTrace collection, but then attempting to add TheArticle's log listener to the logging tab
                    SkipPage("Article is not in mainspace");
                    return;
                }

                if (redirect.Name == TheArticle.Name)
                {//ignore recursive redirects
                    TheArticle = redirect;
                    SkipPage("Recursive redirect");
                    return;
                }

                listMaker1.ReplaceArticle(TheArticle, redirect);
                TheArticle = new ArticleEX(redirect.Name);

                webBrowserEdit.LoadEditPage(redirect.Name);
                return;
            }

            if (webBrowserEdit.Document.Body.InnerHtml.Contains("readOnly"))
            {
                if (!Variables.User.IsAdmin)
                {
                    NudgeTimer.Stop();
                    SkipPage("Page is protected");
                    return;
                }
            }

            TheArticle.OriginalArticleText = strTemp;

            int.TryParse(webBrowserEdit.GetScriptingVar("wgCurRevisionId"), out ErrorHandler.CurrentRevision);

            if (PageReload)
            {
                PageReload = false;
                GetDiff();
                return;
            }

            if (chkSkipIfContains.Checked && TheArticle.SkipIfContains(txtSkipIfContains.Text,
                chkSkipIsRegex.Checked, chkSkipCaseSensitive.Checked, true))
            {
                SkipPage("Article contains: " + txtSkipIfContains.Text);
                return;
            }

            if (chkSkipIfNotContains.Checked && TheArticle.SkipIfContains(txtSkipIfNotContains.Text,
                chkSkipIsRegex.Checked, chkSkipCaseSensitive.Checked, false))
            {
                SkipPage("Article does not contain: " + txtSkipIfNotContains.Text);
                return;
            }

            if (!Skip.SkipIf(TheArticle.OriginalArticleText))
            {
                SkipPage("skipIf custom code");
                return;
            }

            //check not in use
            if (TheArticle.IsInUse)
                if (chkSkipIfInuse.Checked)
                {
                    SkipPage("Page contains {{inuse}}");
                    return;
                }
                else if (!BotMode)
                    MessageBox.Show("This page has the \"Inuse\" tag, consider skipping it");

            ErrorHandler.CurrentArticle = "";

            if (!doNotAutomaticallyDoAnythingToolStripMenuItem.Checked)
            {
                StatusLabelText = "Processing page";
                Application.DoEvents();

                ProcessPage();

                UpdateWebBrowserStatus(null, null);

                if (!Abort)
                {
                    if (TheArticle.SkipArticle)
                    {
                        SkipPageReasonAlreadyProvided(); // Don't send a reason; ProcessPage() should already have logged one
                        return;
                    }

                    if (skippable && chkSkipNoChanges.Checked &&
    TheArticle.ArticleText == TheArticle.OriginalArticleText)
                    {
                        SkipPage("No change");
                        return;
                    }

                }
                else if (chkSkipWhitespace.Checked &&
                    (string.Compare(Regex.Replace(TheArticle.OriginalArticleText, @"\s+", @""), Regex.Replace(TheArticle.ArticleText, @"\s+", @"")) == 0))
                {
                    SkipPage("Only whitespace changed");
                    return;
                }
            }

            webBrowserEdit.SetArticleText(TheArticle.ArticleText);
            TheArticle.SaveSummary();
            txtEdit.Text = TheArticle.ArticleText;

            //Update statistics and alerts
            ArticleInfo(false);

            if (!Abort)
            {
                if (toolStripComboOnLoad.SelectedIndex == 0)
                    GetDiff();
                else if (toolStripComboOnLoad.SelectedIndex == 1)
                    GetPreview();
                else if (toolStripComboOnLoad.SelectedIndex == 2)
                {
                    if (BotMode)
                    {
                        StartDelayedAutoSaveTimer();
                        return;
                    }

                    Bleepflash();

                    this.Focus();
                    txtEdit.Focus();
                    txtEdit.SelectionLength = 0;

                    EnableButtons();
                }
                SetWatchButton(webBrowserEdit.IsWatched());

                if (focusAtEndOfEditTextBoxToolStripMenuItem.Checked)
                {
                    txtEdit.Select(txtEdit.Text.Length, 0);
                    txtEdit.ScrollToCaret();
                }
            }
            else
            {
                EnableButtons();
                Abort = false;
            }
        }
Exemplo n.º 16
0
        private void reparseEditBox()
        {
            ArticleEX a = new ArticleEX(TheArticle.Name);

            a.OriginalArticleText = txtEdit.Text;
            ErrorHandler.CurrentArticle = TheArticle.Name;
            ProcessPage(a);
            ErrorHandler.CurrentArticle = "";
            txtEdit.Text = a.ArticleText;
            GetDiff();
        }