Inheritance: System.Windows.Forms.Form
        /// <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)
        {
            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 (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;
            }
        }
Beispiel #2
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,
                                          WikiFunctions.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
            {
                this.AWBChangeArticleText("Find and replace applied" + tmpEditSummary,
                                          strTemp.Replace("\n", "\r\n"), false);
                EditSummary += tmpEditSummary;
            }
        }
Beispiel #3
0
        public void SubstTemplatesNoExpand()
        {
            WikiFunctions.SubstTemplates st = new WikiFunctions.SubstTemplates();
            st.ExpandRecursively =false;

            Assert.AreEqual("Now {{foo}}", st.SubstituteTemplates("Now {{foo}}", "test"));

            st.TemplateList = new [] {"foo", "bar"};

            Assert.AreEqual(2, st.NoOfRegexes);

            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{foo}}", "test"));
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{ foo}}", "test"));
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{ foo }}", "test"));
            Assert.AreEqual("Now {{subst:foo|first=y}}", st.SubstituteTemplates("Now {{foo|first=y}}", "test"));
            Assert.AreEqual("Now {{subst:foo|first}}", st.SubstituteTemplates("Now {{foo|first}}", "test"));
            Assert.AreEqual("Now {{subst:foo}} {{subst:bar}}", st.SubstituteTemplates("Now {{foo}} {{bar}}", "test"));

            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{Template:foo}}", "test"));
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{template:foo}}", "test"));
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{template :foo}}", "test"));
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{ template :foo}}", "test"));
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{ template : foo}}", "test"));
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{Msg:foo}}", "test"));
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{msg :foo}}", "test"));
        }
        public void SubstTemplatesNoExpand()
        {
            WikiFunctions.SubstTemplates st = new WikiFunctions.SubstTemplates();
            st.ExpandRecursively = false;

            Assert.AreEqual("Now {{foo}}", st.SubstituteTemplates("Now {{foo}}", "test"), "no change when no templates in list");

            st.TemplateList = new[] {"foo", "bar"};

            Assert.AreEqual(2, st.NoOfRegexes);

            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{foo}}", "test"), "simple case");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{Foo}}", "test"), "First letter casing handling");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{ foo}}", "test"), "whitespace before");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{ foo }}", "test"), "whitespace after");
            Assert.AreEqual("Now {{subst:foo|first=y}}", st.SubstituteTemplates("Now {{foo|first=y}}", "test"), "template with parameters");
            Assert.AreEqual("Now {{subst:foo|first}}", st.SubstituteTemplates("Now {{foo|first}}", "test"), "template with arguments");
            Assert.AreEqual("Now {{subst:foo}} {{subst:bar}}", st.SubstituteTemplates("Now {{foo}} {{bar}}", "test"), "Multiple");

            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{Template:foo}}", "test"), "Template prefix");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{template:foo}}", "test"), "template prefix");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{template :foo}}", "test"), "template spacing after");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{ template :foo}}", "test"), "template spacing before");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{ template : foo}}", "test"), "all whitespace");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{Msg:foo}}", "test"), "Msg prefix");
            Assert.AreEqual("Now {{subst:foo}}", st.SubstituteTemplates("Now {{msg :foo}}", "test"), "Msg prefix spacing");

            st.TemplateList = new[] {"foo (bar)"};
            Assert.AreEqual(1, st.NoOfRegexes);

            Assert.AreEqual("Now {{subst:foo (bar)}}", st.SubstituteTemplates("Now {{foo (bar)}}", "test"), "template name is escaped");
            Assert.AreEqual("Now {{subst:foo (bar)}}", st.SubstituteTemplates("Now {{Foo (bar)}}", "test"), "template name is escaped, casing handling");
        }