Example #1
0
        /// <summary>
        /// Applies a series of defined find and replacements to the supplied article text.
        /// </summary>
        /// <param name="articleText">The wiki text of the article.</param>
        /// <param name="editSummary"></param>
        /// <param name="strTitle"></param>
        /// <param name="beforeOrAfter">False if "before", true if "after"</param>
        /// <param name="majorChangesMade"></param>
        /// <returns>The modified article text.</returns>
        public string MultipleFindAndReplace(string articleText, string strTitle, bool beforeOrAfter, ref string editSummary, out bool majorChangesMade)
        {
            majorChangesMade = false;

            if (!HasReplacements)
            {
                return(articleText);
            }

            ReplacedSummary = "";
            RemovedSummary  = "";

            if (chkIgnoreMore.Checked)
            {
                articleText = _remove.HideMore(articleText);
            }
            else if (chkIgnoreLinks.Checked)
            {
                articleText = _remove.Hide(articleText);
            }

            foreach (Replacement rep in _replacementList)
            {
                if (!rep.Enabled || rep.BeforeOrAfter != beforeOrAfter)
                {
                    continue;
                }

                bool changeMade;
                articleText = PerformFindAndReplace(rep, articleText, strTitle, out changeMade);

                if (changeMade && !rep.Minor)
                {
                    majorChangesMade = true;
                }
            }

            if (chkIgnoreMore.Checked)
            {
                // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs#FormatException_in_HideText.AddBackMore
                // FIXME: Usages of IgnoreMore with number (or M) replacement done in the FindAndReplace can cause corruption
                // e.g. Replacing 2 with "" ⌊⌊⌊⌊M2⌋⌋⌋⌋ becomes ⌊⌊⌊⌊M⌋⌋⌋⌋
                // This cannot then be added back
                articleText = _remove.AddBackMore(articleText);
            }
            else if (chkIgnoreLinks.Checked)
            {
                articleText = _remove.AddBack(articleText);
            }

            if (chkAddToSummary.Checked)
            {
                if (!string.IsNullOrEmpty(ReplacedSummary))
                {
                    if (Variables.LangCode.Equals("ar"))
                    {
                        editSummary = "استبدل: " + ReplacedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("arz"))
                    {
                        editSummary = "غير: " + ReplacedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("el"))
                    {
                        editSummary = "αντικατέστησε: " + ReplacedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("eo"))
                    {
                        editSummary = "anstataŭigis: " + ReplacedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("fr"))
                    {
                        editSummary = "remplacement: " + ReplacedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("hy"))
                    {
                        editSummary = "փոխարինվեց: " + ReplacedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("tr"))
                    {
                        editSummary = "değiştirildi: " + ReplacedSummary.Trim();
                    }
                    else
                    {
                        editSummary += "replaced: " + ReplacedSummary.Trim();
                    }
                }

                if (!string.IsNullOrEmpty(RemovedSummary))
                {
                    if (!string.IsNullOrEmpty(editSummary))
                    {
                        if (Variables.LangCode.Equals("ar") || Variables.LangCode.Equals("arz") || Variables.LangCode.Equals("fa"))
                        {
                            editSummary += "، ";
                        }
                        else
                        {
                            editSummary += ", ";
                        }
                    }

                    if (Variables.LangCode.Equals("ar"))
                    {
                        editSummary += "أزال: " + RemovedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("arz"))
                    {
                        editSummary += "شال: " + RemovedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("el"))
                    {
                        editSummary += "αφαίρεσε: " + RemovedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("eo"))
                    {
                        editSummary += "forigis: " + RemovedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("fr"))
                    {
                        editSummary += "retrait: " + RemovedSummary.Trim();
                    }
                    else if (Variables.LangCode.Equals("hy"))
                    {
                        editSummary += "ջնջվեց: " + RemovedSummary.Trim();
                    }
                    else
                    {
                        editSummary += "removed: " + RemovedSummary.Trim();
                    }
                }
            }

            return(articleText);
        }
        /// <summary>
        /// Applies a series of defined find and replacements to the supplied article text.
        /// </summary>
        /// <param name="articleText">The wiki text of the article.</param>
        /// <param name="editSummary"></param>
        /// <param name="strTitle"></param>
        /// <param name="beforeOrAfter">False if "before", true if "after"</param>
        /// <param name="majorChangesMade"></param>
        /// <returns>The modified article text.</returns>
        public string MultipleFindAndReplace(string articleText, string strTitle, bool beforeOrAfter, ref string editSummary, out bool majorChangesMade)
        {
            majorChangesMade = false;

            if (!HasReplacements)
            {
                return(articleText);
            }

            ReplacedSummary = "";
            RemovedSummary  = "";

            if (chkIgnoreMore.Checked)
            {
                articleText = _remove.HideMore(articleText);
            }
            else if (chkIgnoreLinks.Checked)
            {
                articleText = _remove.Hide(articleText);
            }

            foreach (Replacement rep in _replacementList)
            {
                if (!rep.Enabled || rep.BeforeOrAfter != beforeOrAfter)
                {
                    continue;
                }

                bool changeMade;
                articleText = PerformFindAndReplace(rep, articleText, strTitle, out changeMade);

                if (changeMade && !rep.Minor)
                {
                    majorChangesMade = true;
                }
            }

            if (chkIgnoreMore.Checked)
            {
                articleText = _remove.AddBackMore(articleText);
            }
            else if (chkIgnoreLinks.Checked)
            {
                articleText = _remove.AddBack(articleText);
            }

            if (chkAddToSummary.Checked)
            {
                if (!string.IsNullOrEmpty(ReplacedSummary))
                {
                    editSummary = "replaced: " + ReplacedSummary.Trim();
                }

                if (!string.IsNullOrEmpty(RemovedSummary))
                {
                    if (!string.IsNullOrEmpty(editSummary))
                    {
                        editSummary += ", ";
                    }

                    editSummary += "removed: " + RemovedSummary.Trim();
                }
            }

            return(articleText);
        }