コード例 #1
0
        /// <summary>
        /// Process a "find and replace"
        /// </summary>
        /// <param name="findAndReplace">A FindandReplace object</param>
        /// <param name="substTemplates">A SubstTemplates object</param>
        /// <param name="replaceSpecial">An MWB ReplaceSpecial object</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void PerformFindAndReplace(FindandReplace findAndReplace, SubstTemplates substTemplates,
                                          ReplaceSpecial.ReplaceSpecial replaceSpecial, bool SkipIfNoChange)
        {
            if (!findAndReplace.HasReplacements && !replaceSpecial.HasRules && !substTemplates.HasSubstitutions)
            {
                return;
            }

            string strTemp        = mArticleText.Replace("\r\n", "\n"),
                   testText       = strTemp,
                   tmpEditSummary = "";

            strTemp = findAndReplace.MultipleFindAndReplace(strTemp, mName, ref tmpEditSummary);
            strTemp = replaceSpecial.ApplyRules(strTemp, mName);
            strTemp = substTemplates.SubstituteTemplates(strTemp, mName);

            if (testText == strTemp)
            {
                if (SkipIfNoChange)
                {
                    Trace.AWBSkipped("No Find And Replace Changes");
                }
                else
                {
                    return;
                }
            }
            else
            {
                AWBChangeArticleText("Find and replace applied" + tmpEditSummary,
                                     strTemp.Replace("\n", "\r\n"), true);
                EditSummary += tmpEditSummary;
            }
        }
コード例 #2
0
        /// <summary>
        /// Fix header errors
        /// </summary>
        /// <param name="parsers"></param>
        /// <param name="LangCode">The wiki's language code</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        protected void FixHeaderErrors(Parsers parsers, LangCodeEnum LangCode, bool SkipIfNoChange)
        {
            if (LangCode == LangCodeEnum.en)
            {
                string strTemp = Parsers.Conversions(mArticleText);

                strTemp = parsers.FixDates(strTemp);
                strTemp = Parsers.FixLivingThingsRelatedDates(strTemp);
                strTemp = Parsers.LivingPeople(strTemp, out noChange);
                strTemp = Parsers.FixHeadings(strTemp, mName, out noChange);

                if (mArticleText == strTemp)
                {
                    if (SkipIfNoChange)
                    {
                        Trace.AWBSkipped("No header errors");
                    }
                }
                else
                {
                    if (!noChange)
                    {
                        AWBChangeArticleText("Fixed header errors", strTemp, true);
                    }
                    else
                    {
                        AWBChangeArticleText("Fixed minor formatting issues", strTemp, true);
                        if (SkipIfNoChange)
                        {
                            Trace.AWBSkipped("No header errors");
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Disambiguate
        /// </summary>
        /// <returns>True if OK to proceed, false to abort</returns>
        public bool Disambiguate(string dabLinkText, string[] dabVariantsLines, bool botMode, int Context,
                                 bool skipIfNoChange)
        {
            bool noChange;

            Disambiguation.DabForm df = new Disambiguation.DabForm();
            string strTemp            = df.Disambiguate(mArticleText, mName, dabLinkText,
                                                        dabVariantsLines, Context, botMode, out noChange);

            if (df.Abort)
            {
                return(false);
            }

            if (noChange && skipIfNoChange)
            {
                Trace.AWBSkipped("No disambiguation");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("Disambiguated " + dabLinkText, strTemp, false);
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Corrects common formatting errors in dates in external reference citation templates (doesn't link/delink dates)
        /// </summary>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void CiteTemplateDates(Parsers parsers, bool SkipIfNoChange)
        {
            string strTemp = parsers.CiteTemplateDates(mArticleText, out noChange);

            if (SkipIfNoChange && noChange)
            {
                Trace.AWBSkipped("No Citation template dates fixed");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("Citation template dates fixed", strTemp, true);
            }
        }
コード例 #5
0
        /// <summary>
        /// Fix link syntax
        /// </summary>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void FixLinks(bool SkipIfNoChange)
        {
            string strTemp = Parsers.FixLinks(mArticleText, out noChange);

            if (noChange && SkipIfNoChange)
            {
                Trace.AWBSkipped("No bad links");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("Fixed links", strTemp, false);
            }
        }
コード例 #6
0
        /// <summary>
        /// '''Emboldens''' the first occurence of the article title, if not already bold
        /// </summary>
        /// <param name="parsers"></param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void EmboldenTitles(Parsers parsers, bool SkipIfNoChange)
        {
            string strTemp = parsers.BoldTitle(mArticleText, mName, out noChange);

            if (SkipIfNoChange && noChange)
            {
                Trace.AWBSkipped("No Titles to embolden");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("Emboldened titles", strTemp, false);
            }
        }
コード例 #7
0
        /// <summary>
        /// Convert HTML characters in the article to Unicode
        /// </summary>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        /// <param name="parsers">An initialised Parsers object</param>
        public void Unicodify(bool SkipIfNoChange, Parsers parsers)
        {
            string strTemp = parsers.Unicodify(mArticleText, out noChange);

            if (SkipIfNoChange && noChange)
            {
                Trace.AWBSkipped("No Unicodification");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("Page Unicodified", strTemp, false);
            }
        }
コード例 #8
0
        /// <summary>
        /// Add bulletpoints to external links, if necessary
        /// </summary>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void BulletExternalLinks(bool SkipIfNoChange)
        {
            string strTemp = Parsers.BulletExternalLinks(mArticleText, out noChange);

            if (SkipIfNoChange && noChange)
            {
                Trace.AWBSkipped("No missing bulleted links");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("Bulleted external links", strTemp, false);
            }
        }
コード例 #9
0
        /// <summary>
        /// Add, remove or replace a specified category
        /// </summary>
        /// <param name="option">The action to take</param>
        /// <param name="parsers">An initialised Parsers object</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        /// <param name="CategoryText">The category to add or remove; or, when replacing, the name of the old category</param>
        /// <param name="CategoryText2">The name of the replacement category (recat mode only)</param>
        public void Categorisation(CategorisationOptions option, Parsers parsers,
                                   bool SkipIfNoChange, string CategoryText, string CategoryText2)
        {
            bool   noChange = false;
            string strTemp, action = "";

            switch (option)
            {
            case CategorisationOptions.NoAction:
                return;

            case CategorisationOptions.AddCat:
                if (CategoryText.Length < 1)
                {
                    return;
                }
                strTemp = parsers.AddCategory(CategoryText, mArticleText, mName);
                action  = "Added " + CategoryText;
                break;

            case CategorisationOptions.ReCat:
                if (CategoryText.Length < 1 || CategoryText2.Length < 1)
                {
                    return;
                }
                strTemp = parsers.ReCategoriser(CategoryText, CategoryText2, mArticleText, out noChange);
                break;

            case CategorisationOptions.RemoveCat:
                if (CategoryText.Length < 1)
                {
                    return;
                }
                strTemp = parsers.RemoveCategory(CategoryText, mArticleText, out noChange);
                action  = "Removed " + CategoryText;
                break;

            default:
                throw new ArgumentOutOfRangeException("option");
            }

            if (noChange && SkipIfNoChange)
            {
                Trace.AWBSkipped("No Category Changed");
            }
            else if (!noChange)
            {
                AWBChangeArticleText(action, strTemp, false);
            }
        }
コード例 #10
0
        /// <summary>
        /// Fix spelling mistakes
        /// </summary>
        /// <param name="RegexTypos">A RegExTypoFix object</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void PerformTypoFixes(RegExTypoFix RegexTypos, bool SkipIfNoChange)
        {
            string strTemp = RegexTypos.PerformTypoFixes(mArticleText, out noChange, out mPluginEditSummary, mName);

            if (noChange && SkipIfNoChange)
            {
                Trace.AWBSkipped("No typo fixes");
            }
            else if (!noChange)
            {
                AWBChangeArticleText(mPluginEditSummary, strTemp, false);
                AppendPluginEditSummary();
            }
        }
コード例 #11
0
        /// <summary>
        /// "Auto tag" (Adds/removes wikify or stub tags if necessary)
        /// </summary>
        /// <param name="parsers">An initialised Parsers object</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void AutoTag(Parsers parsers, bool SkipIfNoChange)
        {
            bool   noChange; string tmpEditSummary = "";
            string strTemp = parsers.Tagger(mArticleText, mName, out noChange, ref tmpEditSummary);

            if (SkipIfNoChange && noChange)
            {
                Trace.AWBSkipped("No Tag changed");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("Auto tagger changes applied" + tmpEditSummary, strTemp, false);
                EditSummary += tmpEditSummary;
            }
        }
コード例 #12
0
        /// <summary>
        /// Sets Default Sort on Article if Necessary / clean diacritics
        /// </summary>
        /// <param name="LangCode">The wiki's language code</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void SetDefaultSort(LangCodeEnum LangCode, bool SkipIfNoChange)
        {
            if (LangCode == LangCodeEnum.en)
            {
                string strTemp = Parsers.ChangeToDefaultSort(mArticleText, mName, out noChange);

                if (SkipIfNoChange && noChange)
                {
                    Trace.AWBSkipped("No DefaultSort Added");
                }
                else if (!noChange)
                {
                    AWBChangeArticleText("DefaultSort Added/Diacritics cleaned", strTemp, true);
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Sets Default Sort on Article if Necessary
        /// </summary>
        /// <param name="parsers">An initialised Parsers object</param>
        /// <param name="LangCode">The wiki's language code</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void SetDefaultSort(Parsers parsers, LangCodeEnum LangCode, bool SkipIfNoChange)
        {
            if (LangCode == LangCodeEnum.en)
            {
                bool   noChange;
                string strTemp = parsers.ChangeToDefaultSort(mArticleText, mName, out noChange);

                if (SkipIfNoChange && noChange)
                {
                    Trace.AWBSkipped("No DefaultSort Added");
                }
                else if (!noChange)
                {
                    this.AWBChangeArticleText("DefaultSort Added", strTemp, true);
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Remove, replace or comment out a specified image
        /// </summary>
        /// <param name="option">The action to take</param>
        /// <param name="parsers">An initialised Parsers object</param>
        /// <param name="ImageReplaceText">The text (image name) to look for</param>
        /// <param name="ImageWithText">Replacement text (if applicable)</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void UpdateImages(ImageReplaceOptions option, Parsers parsers,
                                 string ImageReplaceText, string ImageWithText, bool SkipIfNoChange)
        {
            bool noChange = true; string strTemp = "";

            ImageReplaceText = ImageReplaceText.Trim();
            ImageWithText    = ImageWithText.Trim();

            if (ImageReplaceText.Length > 0)
            {
                switch (option)
                {
                case ImageReplaceOptions.NoAction:
                    return;

                case ImageReplaceOptions.Replace:
                    if (ImageWithText.Length > 0)
                    {
                        strTemp = parsers.ReplaceImage(ImageReplaceText, ImageWithText, mArticleText, out noChange);
                    }
                    break;

                case ImageReplaceOptions.Remove:
                    strTemp = parsers.RemoveImage(ImageReplaceText, mArticleText, false, ImageWithText, out noChange);
                    break;

                case ImageReplaceOptions.Comment:
                    strTemp = parsers.RemoveImage(ImageReplaceText, mArticleText, true, ImageWithText, out noChange);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("option");
                }
            }

            if (noChange && SkipIfNoChange)
            {
                Trace.AWBSkipped("No File Changed");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("File replacement applied", strTemp, false);
            }
        }
コード例 #15
0
        /// <summary>
        /// Performs the general fixes for user talk pages (ie user talk template substitution)
        /// </summary>
        /// <param name="removeText"></param>
        /// <param name="userTalkTemplatesRegex">Regex of user talk templates to substitute</param>
        /// <param name="SkipIfNoChange"></param>
        public void PerformUserTalkGeneralFixes(HideText removeText, Regex userTalkTemplatesRegex, bool SkipIfNoChange)
        {
            string originalText = ArticleText;

            HideText(removeText);
            Variables.Profiler.Profile("HideText");

            AWBChangeArticleText("Subst user talk warnings",
                                 Parsers.SubstUserTemplates(ArticleText, Name, userTalkTemplatesRegex), true);

            Variables.Profiler.Profile("SubstUserTemplates");

            UnHideText(removeText);
            Variables.Profiler.Profile("UnHideText");

            if (SkipIfNoChange && (originalText == ArticleText))
            {
                Trace.AWBSkipped("No user talk templates subst'd");
            }
        }
コード例 #16
0
        public void SendPageToCustomModule(IModule Module)
        { // TODO: Check this Skips properly if module tells us to. If not, we'll have to set the Skip property directly
            ProcessArticleEventArgs processArticleEventArgs = this;
            string strEditSummary = "", strTemp; bool skipArticle;

            strTemp = Module.ProcessArticle(processArticleEventArgs.ArticleText,
                                            processArticleEventArgs.ArticleTitle, NameSpaceKey, out strEditSummary, out skipArticle);

            if (!skipArticle)
            {
                processArticleEventArgs.EditSummary = strEditSummary;
                processArticleEventArgs.Skip        = false;
                AWBChangeArticleText("Custom module", strTemp, true);
                AppendPluginEditSummary();
            }
            else
            {
                Trace.AWBSkipped("Skipped by custom module");
            }
        }
コード例 #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Module"></param>
        public void SendPageToCustomModule(IModule Module)
        {
            ProcessArticleEventArgs processArticleEventArgs = this;
            string strEditSummary;
            bool   skipArticle;

            string strTemp = Module.ProcessArticle(processArticleEventArgs.ArticleText,
                                                   processArticleEventArgs.ArticleTitle, NameSpaceKey, out strEditSummary, out skipArticle);

            if (!skipArticle)
            {
                processArticleEventArgs.EditSummary = strEditSummary;
                processArticleEventArgs.Skip        = false;
                AWBChangeArticleText("Custom module", strTemp, true);
                AppendPluginEditSummary();
            }
            else
            {
                Trace.AWBSkipped("Skipped by custom module");
            }
        }
コード例 #18
0
        /// <summary>
        /// Adds [[Category:XXXX births]], [[Category:XXXX deaths]], [[Category:Living people]] etc. to articles about people where available, for en-wiki only
        /// </summary>
        /// <param name="parsers"></param>
        /// <param name="skipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void FixPeopleCategories(Parsers parsers, bool skipIfNoChange)
        {
            bool   noChange2;
            string strTemp = parsers.FixPeopleCategories(mArticleText, out noChange);

            strTemp = Parsers.LivingPeople(strTemp, out noChange2);

            if (!noChange2)
            {
                noChange = false;
            }

            if (skipIfNoChange && noChange)
            {
                Trace.AWBSkipped("No human category changes");
            }
            else if (!noChange)
            {
                AWBChangeArticleText("Human category changes", strTemp, true);
            }
        }
コード例 #19
0
        /// <summary>
        /// Process a "find and replace"
        /// </summary>
        /// <param name="findAndReplace">A FindandReplace object</param>
        /// <param name="substTemplates">A SubstTemplates object</param>
        /// <param name="replaceSpecial">An MWB ReplaceSpecial object</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void PerformFindAndReplace(FindandReplace findAndReplace, SubstTemplates substTemplates,
                                          MWB.ReplaceSpecial replaceSpecial, bool SkipIfNoChange)
        {
            string strTemp = mArticleText.Replace("\r\n", "\n"),
                   testText = strTemp, tmpEditSummary = "";

            strTemp = findAndReplace.MultipleFindAndReplace(strTemp, mName, ref tmpEditSummary);
            strTemp = replaceSpecial.ApplyRules(strTemp, mName);
            strTemp = substTemplates.SubstituteTemplates(strTemp, mName); // TODO: Possible bug, this was "articleTitle" not "Name"

            if (SkipIfNoChange && (testText == strTemp))                  // NoChange
            {
                Trace.AWBSkipped("No Find And Replace Changes");
            }
            else
            {
                AWBChangeArticleText("Find and replace applied" + tmpEditSummary,
                                     strTemp.Replace("\n", "\r\n"), false);
                EditSummary += tmpEditSummary;
            }
        }
コード例 #20
0
 /// <summary>
 /// AWB skips the article; passed through to the underlying AWBLogListener object
 /// </summary>
 /// <param name="reason">The reason for skipping</param>
 public void AWBSkip(string reason)
 {
     Trace.AWBSkipped(reason);
 }