Example #1
0
        public Dictionary <string, string> GetTypos()
        {
            Dictionary <string, string> typoStrings = new Dictionary <string, string>();

            try
            {
                string text = "";
                try
                {
                    text = Tools.GetHTML(Url, Encoding.UTF8);
                }
                catch
                {
                    if (string.IsNullOrEmpty(text))
                    {
                        if (MessageBox.Show("No list of typos was found. Would you like to use the list of typos from the English Wikipedia?\r\nOnly choose 'Yes' if this is an English wiki.", "Load from English Wikipedia?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            try
                            {
                                text = Tools.GetHTML("http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/Typos&action=raw", Encoding.UTF8);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("There was a problem loading the list of typos: " + ex.Message);
                            }
                        }
                        else
                        {
                            text = "";
                        }
                    }
                }

                if (string.IsNullOrEmpty(text))
                {
                    return(typoStrings); // Currently an empty dictionary
                }
                foreach (Match m in TypoRegex.Matches(text))
                {
                    try
                    {
                        typoStrings.Add(m.Groups[2].Value, m.Groups[3].Value);
                    }
                    catch (ArgumentException)
                    {
                        RegExTypoFix.TypoError("Duplicate typo rule '" + m.Groups[2].Value + "' found.");
                        return(new Dictionary <string, string>());
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.Handle(ex);
                // refuse to accept malformed typo lists to encourage people to correct errors
                return(new Dictionary <string, string>());
            }

            return(typoStrings);
        }
Example #2
0
        private string FixTypos(string articleText, string articleTitle)
        {
            if (Retf == null)
            {
                if (Typos.Count == 0) throw new Exception("You forgot to provide a list of typos!");
                Retf = new RegExTypoFix(false, new TypoList(Typos));
            }

            bool noChange;
            return Retf.PerformTypoFixes(articleText, out noChange, out Summary, articleTitle);
        }
Example #3
0
        private void createRetfRuleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = dataGridView1.CurrentRow;

            if (row == null)
            {
                return;
            }

            string typoName = (string)row.Cells["Comment"].Value;

            if (string.IsNullOrEmpty(typoName))
            {
                typoName = "<enter a name>";
            }

            Tools.CopyToClipboard(RegExTypoFix.CreateRule((string)row.Cells["find"].Value, (string)row.Cells["replace"].Value, typoName));
        }
        /// <summary>
        /// Adds one typo regex to the list
        /// </summary>
        public void Add(string typo, string replacement)
        {
            if (!IsSuitableTypo(typo))
            {
                throw new ArgumentException("Typo \"" + typo + "\" is not suitable for this group.");
            }
            Regex r;

            try
            {
                r = new Regex(typo, RegexOptions.Compiled);
            }
            catch (Exception ex)
            {
                RegExTypoFix.TypoError("Error in typo '" + typo + "': " + ex.Message);
                throw new TypoException();
            }

            Typos.Add(new KeyValuePair <Regex, string>(r, replacement));
        }
Example #5
0
        private void RegexTyposComplete(BackgroundRequest req)
        {
            if (InvokeRequired)
            {
                Invoke(new BackgroundRequestComplete(RegexTyposComplete), new object[] { req });
                return;
            }

            chkRegExTypo.Checked = chkSkipIfNoRegexTypo.Enabled = RegexTypos.TyposLoaded;

            if (RegexTypos.TyposLoaded)
            {
                StatusLabelText = RegexTypos.TypoCount + " typos loaded";
                if (!EditBoxTab.TabPages.Contains(tpTypos)) EditBoxTab.TabPages.Add(tpTypos);
                ResetTypoStats();
            }
            else
            {
                RegexTypos = null;
                if (EditBoxTab.TabPages.Contains(tpTypos)) EditBoxTab.TabPages.Remove(tpTypos);
            }

            _loadingTypos = false;
        }
Example #6
0
        private void LoadTypos(bool reload)
        {
            if (chkRegExTypo.Checked && (RegexTypos == null || reload))
            {
                _loadingTypos = true;
                chkRegExTypo.Checked = false;

                StatusLabelText = "Loading typos";

                #if !DEBUG
                string message = @"1. Check each edit before you make it. Although this has been built to be very accurate there will be errors.

2. Optional: Select [[WP:AWB/T|Typo fixing]] as the edit summary. This lets everyone know where to bring issues with the typo correction.";

                if (RegexTypos == null)
                {
                    string s = Variables.RetfPath;

                    if (!s.StartsWith("http:"))
                        s = Variables.URL + "/wiki/" + s;

                    message += "\r\n\r\nThe newest typos will now be downloaded from " + s + " when you press OK.";
                }

                MessageBox.Show(message, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                #endif

                RegexTypos = new RegExTypoFix();
                RegexTypos.Complete += RegexTyposComplete;
            }
        }
Example #7
0
        private void RegexTypos_Complete()
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new RegexTypoDone(RegexTypos_Complete));
                return;
            }

            chkRegExTypo.Checked = chkSkipIfNoRegexTypo.Enabled = RegexTypos.TyposLoaded;

            if (RegexTypos.TyposLoaded)
            {
                StatusLabelText = RegexTypos.TyposCount.ToString() + " typos loaded";
                if (!EditBoxTab.TabPages.Contains(tpTypos)) EditBoxTab.TabPages.Add(tpTypos);
                ResetTypoStats();
            }
            else
            {
                RegexTypos = null;
                if (EditBoxTab.TabPages.Contains(tpTypos)) EditBoxTab.TabPages.Remove(tpTypos);
            }

            loadingTypos = false;
        }
Example #8
0
        public void LoadTypos(bool reload)
        {
            // during change of user settings to settings with typos enabled, LoadTypos will be called more than once
            // from LoadPrefs...SetProject with RETF to say reload is needed when RETF next used, and then again from LoadPrefs with RETF enabled
            // so set RegexTypos to null if reload, even if RETF not enabled at the time
            // This logic is needed to support use of SetProject in other scenarios
            if(reload)
                RegexTypos = null;

            if (chkRegExTypo.Checked && RegexTypos == null)
            {
                _loadingTypos = true;
                chkRegExTypo.Checked = false;

                StatusLabelText = "Loading typos";

                // if not logged in will be using default Typos page location so look up any custom page from CheckPage info
                if(!TheSession.User.IsLoggedIn && !Variables.IsWikipediaEN && Variables.RetfPath.EndsWith("AutoWikiBrowser/Typos"))
                {
                    string url = Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=raw";

                    string checkPageText = Tools.GetHTML(url);

                    WikiFunctions.Session.HasTypoLink(checkPageText);
                }

                #if !DEBUG
                string message = @"Check each edit before you make it. Although this has been built to be very accurate there will be errors.";

                if (RegexTypos == null)
                {
                    string s = Variables.RetfPath;

                    if (!s.StartsWith("http:"))
                        s = Variables.URL + "/wiki/" + s;

                    message += "\r\n\r\nThe newest typos will now be downloaded from " + s + " when you press OK.";
                }

                MessageBox.Show(message, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                #endif

                RegexTypos = new RegExTypoFix();
                RegexTypos.Complete += RegexTyposComplete;
            }
        }
Example #9
0
 public void SetUp()
 {
     Typos.Clear();
     Retf = null;
 }
Example #10
0
        public void LoadTypos(bool reload)
        {
            // during change of user settings to settings with typos enabled, LoadTypos will be called more than once
            // from LoadPrefs...SetProject with RETF to say reload is needed when RETF next used, and then again from LoadPrefs with RETF enabled
            // so set RegexTypos to null if reload, even if RETF not enabled at the time
            // This logic is needed to support use of SetProject in other scenarios
            if(reload)
                RegexTypos = null;

            if (chkRegExTypo.Checked && RegexTypos == null)
            {
                _loadingTypos = true;
                chkRegExTypo.Checked = false;

                StatusLabelText = "Loading typos";

                #if !DEBUG
                string message = @"Check each edit before you make it. Although this has been built to be very accurate there will be errors.";

                if (RegexTypos == null)
                {
                    string s = Variables.RetfPath;

                    if (!s.StartsWith("http:"))
                        s = Variables.URL + "/wiki/" + s;

                    message += "\r\n\r\nThe newest typos will now be downloaded from " + s + " when you press OK.";
                }

                MessageBox.Show(message, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                #endif

                RegexTypos = new RegExTypoFix();
                RegexTypos.Complete += RegexTyposComplete;
            }
        }
Example #11
0
 public void SetUp()
 {
     typos.Clear();
     retf = null;
 }
Example #12
0
        private bool DetectTypo(string articleText, string articleTitle)
        {
            if (Retf == null)
            {
                if (Typos.Count == 0) throw new Exception("You forgot to provide a list of typos!");
                Retf = new RegExTypoFix(false, new TypoList(Typos));
            }

            return Retf.DetectTypo(articleText, articleTitle);
        }
Example #13
0
        private void LoadTypos(bool Reload)
        {
            if (chkRegExTypo.Checked)
            {
                StatusLabelText = "Loading typos";

                string s = Variables.RETFPath;

                if (!s.StartsWith("http:")) s = Variables.URL + "/wiki/" + s;

#if !DEBUG
                string message = @"1. Check each edit before you make it. Although this has been built to be very accurate there will be errors.

2. Optional: Select [[WP:AWB/T|Typo fixing]] as the edit summary. This lets everyone know where to bring issues with the typo correction.";

                if (RegexTypos == null)
                    message += "\r\n\r\nThe newest typos will now be downloaded from " + s + " when you press OK.";

                MessageBox.Show(message, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
#endif

                if (RegexTypos == null || Reload)
                {
                    RegexTypos = new RegExTypoFix();
                    if (RegexTypos.TyposLoaded)
                    {
                        StatusLabelText = RegexTypos.TyposCount.ToString() + " typos loaded";
                    }
                    else
                    {
                        chkRegExTypo.Checked = chkSkipIfNoRegexTypo.Enabled = false;
                        RegexTypos = null;
                    }
                }

                ResetTypoStats();
            }
        }