/// <summary>
        /// Processes talk pages: moves any talk page header template, moves any default, adds a section heading if missing
        /// </summary>
        /// <param name="articleText">The talk page text</param>
        /// <param name="summary">The edit summary to update</param>
        /// <param name="moveDefaultsort">The action to take over any defaultsort on the page</param>
        /// <returns>The updated talk page text</returns>
        public static bool ProcessTalkPage(ref string articleText, ref string summary, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText, new MatchEvaluator(pr.SkipTOCMatchEvaluator), 1);
            
            // move talk page header to the top
            articleText = MoveTalkHeader(articleText, ref summary);

            if (pr.FoundSkipToTalk)
                WriteHeaderTemplate("Skip to talk", ref articleText, ref summary);

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText, 
                    new MatchEvaluator(pr.DefaultSortMatchEvaluator), 1);
                if (pr.FoundDefaultSort)
                {
                    if (string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        AppendToSummary(ref summary, "DEFAULTSORT has no key; removed");
                    }
                    else
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText, ref summary);
                    }
                }
            }
            
            articleText = AddMissingFirstCommentHeader(articleText, ref summary);
            
            return pr.FoundTalkHeader || pr.FoundSkipToTalk || pr.FoundDefaultSort;
        }
        public static bool ProcessTalkPage(ref string articleText, ref string summary, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();
            articleText = WikiRegexes.TalkHeaderTemplate.Replace(articleText, 
                new MatchEvaluator(pr.TalkHeaderMatchEvaluator), 1);

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText, new MatchEvaluator(pr.SkipTOCMatchEvaluator), 1);
            
            if (pr.FoundTalkHeader)
                WriteHeaderTemplate("talkheader", ref articleText, ref summary);

            if (pr.FoundSkipTOC)
                WriteHeaderTemplate("skiptotoctalk", ref articleText, ref summary);

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText, 
                    new MatchEvaluator(pr.DefaultSortMatchEvaluator), 1);
                if (pr.FoundDefaultSort)
                {
                    if (string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        AppendToSummary(ref summary, "DEFAULTSORT has no key; removed");
                    }
                    else
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText, ref summary);
                    }
                }
            }
            return pr.FoundTalkHeader || pr.FoundSkipTOC || pr.FoundDefaultSort;
        }
Exemple #3
0
        // Helper routines:
        private static string SetDefaultSort(string key, DEFAULTSORT location, string articleText, ref string summary)
        {
            string movedTo;

            switch (location)
            {
            case DEFAULTSORT.MoveToTop:
                articleText = "{{DEFAULTSORT:" + key + "}}\r\n" + articleText;
                movedTo     = " given top billing";
                break;

            case DEFAULTSORT.MoveToBottom:
                articleText = articleText + "\r\n{{DEFAULTSORT:" + key + "}}";
                movedTo     = " sent to the bottom";
                break;

            default:
                movedTo = "";
                break;
            }

            if (location != DEFAULTSORT.NoChange)
            {
                AppendToSummary(ref summary, "DEFAULTSORT" + movedTo);
            }

            return(articleText);
        }
 public static bool ProcessTalkPage(ref string ArticleText, IMyTraceListener Trace, 
 DEFAULTSORT MoveDEFAULTSORT, string PluginName)
 {
     FoundTalkheader = false; FoundSkipTOC = false; FoundDefaultSort = false;
     ArticleText = TalkheaderTemplateRegex.Replace(ArticleText, new MatchEvaluator(TalkheaderMatchEvaluator), 1);
     ArticleText = SkipTOCTemplateRegex.Replace(ArticleText, new MatchEvaluator(SkipTOCMatchEvaluator), 1);
     if (FoundTalkheader)
         WriteHeaderTemplate("talkheader", ref ArticleText, Trace, PluginName);
     if (FoundSkipTOC)
         WriteHeaderTemplate("skiptotoctalk", ref ArticleText, Trace, PluginName);
     if (MoveDEFAULTSORT != DEFAULTSORT.NoChange)
     {
         ArticleText = WikiRegexes.Defaultsort.Replace(ArticleText, 
             new MatchEvaluator(DefaultSortMatchEvaluator), 1);
         if (FoundDefaultSort)
         {
             if (string.IsNullOrEmpty(DefaultSortKey))
             {
                 if (Trace != null)
                     Trace.WriteArticleActionLine("DEFAULTSORT has no key; removed", PluginName);
             }
             else
             {
                 WriteDefaultSortMagicWord(MoveDEFAULTSORT, Trace, PluginName, ref ArticleText);
             }
         }
         DefaultSortKey = "";
     }
     return (FoundTalkheader || FoundSkipTOC) || FoundDefaultSort;
 }
        /// <summary>
        /// Moves the default sort.
        /// </summary>
        /// <returns>
        /// The updated article text.
        /// </returns>
        /// <param name='key'>
        /// Current defaultsort key.
        /// </param>
        /// <param name='location'>
        /// Required defaultsort location (top or bottom).
        /// </param>
        /// <param name='articleText'>
        /// Article text.
        /// </param>
        private static string SetDefaultSort(string key, DEFAULTSORT location, string articleText)
        {
            switch (location)
            {
            case DEFAULTSORT.MoveToTop:
                return("{{DEFAULTSORT:" + key + "}}\r\n" + articleText);

            case DEFAULTSORT.MoveToBottom:
                return(articleText + "\r\n{{DEFAULTSORT:" + key + "}}");
            }

            return("");
        }
        /// <summary>
        /// Processes talk pages: moves any talk page header template, moves any default, adds a section heading if missing
        /// </summary>
        /// <param name="articleText">The talk page text</param>
        /// <param name="moveDefaultsort">The action to take over any defaultsort on the page</param>
        /// <returns>The updated talk page text</returns>
        public static bool ProcessTalkPage(ref string articleText, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText,
                                                                   new MatchEvaluator(pr.SkipTOCMatchEvaluator), 1);

            articleText = WikiProjectBannerShell(articleText);

            // move talk page header to the top
            articleText = MoveTalkHeader(articleText);

            if (pr.FoundSkipToTalk)
            {
                WriteHeaderTemplate("Skip to talk", ref articleText);
            }

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText,
                                                              new MatchEvaluator(pr.DefaultSortMatchEvaluator), 1);
                if (pr.FoundDefaultSort)
                {
                    if (!string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText);
                    }
                }
            }

            articleText = AddMissingFirstCommentHeader(articleText);

            articleText = WPBiography(articleText);

            articleText = WPSongs(articleText);

            // remove redundant Template: in templates in zeroth section
            string zerothSection = WikiRegexes.ZerothSection.Match(articleText).Value;

            if (zerothSection.Length > 0)
            {
                articleText = articleText.Replace(zerothSection, Parse.Parsers.RemoveTemplateNamespace(zerothSection));
            }

            return(pr.FoundSkipToTalk || pr.FoundDefaultSort);
        }
        // Helper routines:
        private static void WriteDefaultSortMagicWord(DEFAULTSORT Location, IMyTraceListener Trace, string PluginName, ref string ArticleText)
        {
            string strMovedTo;

            if (Location == DEFAULTSORT.MoveToTop)
            {
                ArticleText = "{{DEFAULTSORT:" + DefaultSortKey + "}}\r\n" + ArticleText;
                strMovedTo  = " given top billing";
            }
            else
            {
                ArticleText = ArticleText + "\r\n{{DEFAULTSORT:" + DefaultSortKey + "}}";
                strMovedTo  = " sent to the bottom";
            }
            if (Trace != null)
            {
                Trace.WriteArticleActionLine("DEFAULTSORT" + strMovedTo, PluginName, false);
            }
        }
        /// <summary>
        /// Processes talk pages: moves any talk page header template, moves any default, adds a section heading if missing
        /// </summary>
        /// <param name="articleText">The talk page text</param>
        /// <param name="moveDefaultsort">The action to take over any defaultsort on the page</param>
        /// <returns>The updated talk page text</returns>
        public static bool ProcessTalkPage(ref string articleText, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText,
                                                                   new MatchEvaluator(pr.SkipTOCMatchEvaluator), 1);

            articleText = WikiProjectBannerShell(articleText);

            // move talk page header to the top
            articleText = MoveTalkHeader(articleText);

            if (pr.FoundSkipToTalk)
                WriteHeaderTemplate("Skip to talk", ref articleText);

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText,
                                                              new MatchEvaluator(pr.DefaultSortMatchEvaluator), 1);
                if (pr.FoundDefaultSort)
                {
                    if (!string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText);
                    }
                }
            }

            articleText = AddMissingFirstCommentHeader(articleText);
            
            articleText = WPBiography(articleText);

            articleText = WPSongs(articleText);

            // remove redundant Template: in templates in zeroth section
            string zerothSection = WikiRegexes.ZerothSection.Match(articleText).Value;
            if(zerothSection.Length > 0)
                articleText = articleText.Replace(zerothSection, Parse.Parsers.RemoveTemplateNamespace(zerothSection));

            return pr.FoundSkipToTalk || pr.FoundDefaultSort;
        }
Exemple #9
0
        // Helper routines:
        private static string SetDefaultSort(string key, DEFAULTSORT location, IMyTraceListener trace, string pluginName, string articleText)
        {
            string strMovedTo;

            if (location == DEFAULTSORT.MoveToTop)
            {
                articleText = "{{DEFAULTSORT:" + key + "}}\r\n" + articleText;
                strMovedTo  = " given top billing";
            }
            else
            {
                articleText = articleText + "\r\n{{DEFAULTSORT:" + key + "}}";
                strMovedTo  = " sent to the bottom";
            }
            if (trace != null)
            {
                trace.WriteArticleActionLine("DEFAULTSORT" + strMovedTo, pluginName, false);
            }

            return(articleText);
        }
 public static bool ProcessTalkPage(ref string ArticleText, IMyTraceListener Trace,
                                    DEFAULTSORT MoveDEFAULTSORT, string PluginName)
 {
     FoundTalkheader = false; FoundSkipTOC = false; FoundDefaultSort = false;
     ArticleText     = TalkheaderTemplateRegex.Replace(ArticleText, new MatchEvaluator(TalkheaderMatchEvaluator), 1);
     ArticleText     = SkipTOCTemplateRegex.Replace(ArticleText, new MatchEvaluator(SkipTOCMatchEvaluator), 1);
     if (FoundTalkheader)
     {
         WriteHeaderTemplate("talkheader", ref ArticleText, Trace, PluginName);
     }
     if (FoundSkipTOC)
     {
         WriteHeaderTemplate("skiptotoctalk", ref ArticleText, Trace, PluginName);
     }
     if (MoveDEFAULTSORT != DEFAULTSORT.NoChange)
     {
         ArticleText = WikiRegexes.Defaultsort.Replace(ArticleText,
                                                       new MatchEvaluator(DefaultSortMatchEvaluator), 1);
         if (FoundDefaultSort)
         {
             if (string.IsNullOrEmpty(DefaultSortKey))
             {
                 if (Trace != null)
                 {
                     Trace.WriteArticleActionLine("DEFAULTSORT has no key; removed", PluginName);
                 }
             }
             else
             {
                 WriteDefaultSortMagicWord(MoveDEFAULTSORT, Trace, PluginName, ref ArticleText);
             }
         }
         DefaultSortKey = "";
     }
     if ((!FoundTalkheader && !FoundSkipTOC) && !FoundDefaultSort)
     {
         return(false);
     }
     return(true);
 }
Exemple #11
0
        public static bool ProcessTalkPage(ref string articleText, IMyTraceListener trace,
                                           DEFAULTSORT moveDEFAULTSORT, string pluginName)
        {
            Processor pr = new Processor();

            articleText = TalkHeaderTemplateRegex.Replace(articleText,
                                                          new MatchEvaluator(pr.TalkHeaderMatchEvaluator),
                                                          1);
            articleText = SkipTOCTemplateRegex.Replace(articleText, new MatchEvaluator(pr.SkipTOCMatchEvaluator), 1);
            if (pr.FoundTalkHeader)
            {
                WriteHeaderTemplate("talkheader", ref articleText, trace, pluginName);
            }
            if (pr.FoundSkipTOC)
            {
                WriteHeaderTemplate("skiptotoctalk", ref articleText, trace, pluginName);
            }
            if (moveDEFAULTSORT != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText,
                                                              new MatchEvaluator(pr.DefaultSortMatchEvaluator), 1);
                if (pr.FoundDefaultSort)
                {
                    if (string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        if (trace != null)
                        {
                            trace.WriteArticleActionLine("DEFAULTSORT has no key; removed", pluginName);
                        }
                    }
                    else
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDEFAULTSORT, trace, pluginName, articleText);
                    }
                }
            }
            return(pr.FoundTalkHeader || pr.FoundSkipTOC || pr.FoundDefaultSort);
        }
        // Helper routines:
        private static string SetDefaultSort(string key, DEFAULTSORT Location, IMyTraceListener Trace, string PluginName, string ArticleText)
        {
            string strMovedTo;
            if (Location == DEFAULTSORT.MoveToTop)
            {
                ArticleText = "{{DEFAULTSORT:" + key + "}}\r\n" + ArticleText;
                strMovedTo = " given top billing";
            }
            else
            {
                ArticleText = ArticleText + "\r\n{{DEFAULTSORT:" + key + "}}";
                strMovedTo = " sent to the bottom";
            }
            if (Trace != null)
                Trace.WriteArticleActionLine("DEFAULTSORT" + strMovedTo, PluginName, false);

            return ArticleText;
        }
 public static void ProcessTalkPage(ref string ArticleText, DEFAULTSORT MoveDEFAULTSORT, string PluginName)
 {
     ProcessTalkPage(ref ArticleText, null, MoveDEFAULTSORT, PluginName);
 }
Exemple #14
0
        public static bool ProcessTalkPage(ref string articleText, ref string summary, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText, new MatchEvaluator(pr.SkipTOCMatchEvaluator), 1);

            // move talk page header to the top
            articleText = MoveTalkHeader(articleText, ref summary);

            if (pr.FoundSkipToTalk)
            {
                WriteHeaderTemplate("skip to talk", ref articleText, ref summary);
            }

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText,
                                                              new MatchEvaluator(pr.DefaultSortMatchEvaluator), 1);
                if (pr.FoundDefaultSort)
                {
                    if (string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        AppendToSummary(ref summary, "DEFAULTSORT has no key; removed");
                    }
                    else
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText, ref summary);
                    }
                }
            }

            articleText = AddMissingFirstCommentHeader(articleText, ref summary);

            return(pr.FoundTalkHeader || pr.FoundSkipToTalk || pr.FoundDefaultSort);
        }
        // Helper routines:
        private static string SetDefaultSort(string key, DEFAULTSORT location, string articleText)
        {
            switch (location)
            {
                case DEFAULTSORT.MoveToTop:
                    return "{{DEFAULTSORT:" + key + "}}\r\n" + articleText;

                case DEFAULTSORT.MoveToBottom:
                    return articleText + "\r\n{{DEFAULTSORT:" + key + "}}";
            }

            return "";
        }
        // Helper routines:
        private static string SetDefaultSort(string key, DEFAULTSORT location, string articleText, ref string summary)
        {
            string movedTo;
            switch (location)
            {
                case DEFAULTSORT.MoveToTop:
                    articleText = "{{DEFAULTSORT:" + key + "}}\r\n" + articleText;
                    movedTo = " given top billing";
                    break;
                case DEFAULTSORT.MoveToBottom:
                    articleText = articleText + "\r\n{{DEFAULTSORT:" + key + "}}";
                    movedTo = " sent to the bottom";
                    break;
                default:
                    movedTo = "";
                    break;
            }

            if (location != DEFAULTSORT.NoChange)
                AppendToSummary(ref summary, "DEFAULTSORT" + movedTo);

            return articleText;
        }
Exemple #17
0
 public static void ProcessTalkPage(ref string articleText, DEFAULTSORT moveDEFAULTSORT, string pluginName)
 {
     ProcessTalkPage(ref articleText, null, moveDEFAULTSORT, pluginName);
 }
 public static void ProcessTalkPage(ref string ArticleText, DEFAULTSORT MoveDEFAULTSORT, string PluginName)
 {
     ProcessTalkPage(ref ArticleText, null, MoveDEFAULTSORT, PluginName);
 }
 public static void ProcessTalkPage(ref string articleText, DEFAULTSORT moveDEFAULTSORT, string pluginName)
 {
     ProcessTalkPage(ref articleText, null, moveDEFAULTSORT, pluginName);
 }
 public static bool ProcessTalkPage(ref string ArticleText, IMyTraceListener Trace, 
 DEFAULTSORT MoveDEFAULTSORT, string PluginName)
 {
     Processor pr = new Processor();
     ArticleText = TalkHeaderTemplateRegex.Replace(ArticleText, 
         new MatchEvaluator(pr.TalkHeaderMatchEvaluator),
         1);
     ArticleText = SkipTOCTemplateRegex.Replace(ArticleText, new MatchEvaluator(pr.SkipTOCMatchEvaluator), 1);
     if (pr.FoundTalkHeader)
         WriteHeaderTemplate("talkheader", ref ArticleText, Trace, PluginName);
     if (pr.FoundSkipTOC)
         WriteHeaderTemplate("skiptotoctalk", ref ArticleText, Trace, PluginName);
     if (MoveDEFAULTSORT != DEFAULTSORT.NoChange)
     {
         ArticleText = WikiRegexes.Defaultsort.Replace(ArticleText, 
             new MatchEvaluator(pr.DefaultSortMatchEvaluator), 1);
         if (pr.FoundDefaultSort)
         {
             if (string.IsNullOrEmpty(pr.DefaultSortKey))
             {
                 if (Trace != null)
                     Trace.WriteArticleActionLine("DEFAULTSORT has no key; removed", PluginName);
             }
             else
             {
                 ArticleText = SetDefaultSort(pr.DefaultSortKey, MoveDEFAULTSORT, Trace, PluginName, ArticleText);
             }
         }
     }
     return pr.FoundTalkHeader || pr.FoundSkipTOC || pr.FoundDefaultSort;
 }
        /// <summary>
        /// Processes talk pages: moves any talk page header template, moves any default, adds a section heading if missing
        /// </summary>
        /// <param name="articleText">The talk page text</param>
        /// <param name="moveDefaultsort">The action to take over any defaultsort on the page</param>
        /// <returns>The updated talk page text</returns>
        public static bool ProcessTalkPage(ref string articleText, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText, pr.SkipTOCMatchEvaluator, 1);
            string zerothSectionOriginal = WikiRegexes.ZerothSection.Match(articleText).Value,
            articleTextOriginal = articleText;

            // https://en.wikipedia.org/wiki/Wikipedia:TPL
            // Correct order per WP:TPL is
            // 1. {{Skip to talk}}
            // 2. {{Talk header}}
            // 3. {{GA}} or {{GA nominee}}
            // 4. {{Vital article}}
            // 5. {{community article probation}}, {{censor}}, {{BLP others}} and other high-priority/importance, warning/attention templates.
            // 6. Specific talk page guideline banners, such as {{Not a forum}}, {{Recurring themes}}, {{FAQ}}, {{Round in circles}}, etc.
            // 7. Language related talk page guideline banners, such as {{American English}}
            // 8. Any "article history" banner
            // 9. Any "article milestone" banner
            // 10. WikiProjectBannerShell - Any WikiProject banners
            // 11. {{Image requested}}
            // 12. {{Press}} and {{Connected contributor}}
            // 13. {{To do}}
            // 14. {{Maintained}}
            // 15. {{Find sources notice}}, {{Reliable sources for medical articles}}
            // 16. {{Split from}}, {{Split to}}
            // 17. {{Merge from}}, {{Merge-to}}

            string wpbsBefore = WikiRegexes.WikiProjectBannerShellTemplate.Match(articleText).Value;
            bool blanklinesinwpbsBefore = wpbsBefore.Contains("\r\n\r\n");

            articleText = MoveTalkTemplates(articleText, MergeTemplates);
            articleText = MoveTalkTemplates(articleText, SplitTemplates);
            articleText = MoveTalkTemplates(articleText, FindSource);
            articleText = MoveTalkTemplate(articleText, Maintained);
            articleText = MoveTalkTemplate(articleText, TodoTemplate);
            articleText = MoveTalkTemplates(articleText, PressConnected);
            articleText = MoveTalkTemplate(articleText, ImageRequested);

            // if template moving leaves blank lines in WPBS then clean this up
            if(wpbsBefore.Length > 0 && !blanklinesinwpbsBefore)
                articleText = WikiRegexes.WikiProjectBannerShellTemplate.Replace(articleText, m => m.Value.Replace("\r\n\r\n", "\r\n"));
 
            articleText = WikiProjectBannerShell(articleText);

            articleText = MoveTalkTemplate(articleText, WikiRegexes.WikiProjectBannerShellTemplate);
            if(!WikiRegexes.WikiProjectBannerShellTemplate.IsMatch(articleText))
            	articleText = MoveTalkTemplates(articleText, WikiProjects);
            articleText = MoveTalkTemplates(articleText, MilestoneTemplates);
            articleText = MoveTalkTemplates(articleText, TalkHistoryBTemplates);
            articleText = MoveTalkTemplates(articleText, TalkHistoryTemplates);
            articleText = MoveTalkTemplate(articleText, EnglishVariationsTemplates);
            articleText = MoveTalkTemplates(articleText, TalkGuidelineTemplates);
            articleText = MoveTalkTemplates(articleText, TalkWarningTemplates);
            articleText = MoveTalkTemplate(articleText, VitalArticle);
            articleText = MoveTalkTemplate(articleText, GANomineeTemplate);

            // move talk page header to the top
            articleText = MoveTalkTemplate(articleText, WikiRegexes.TalkHeaderTemplate);

            if (pr.FoundSkipToTalk)
                WriteHeaderTemplate("Skip to talk", ref articleText);

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText, pr.DefaultSortMatchEvaluator, 1);
                if (pr.FoundDefaultSort)
                {
                    if (!string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText);
                    }
                }
            }

            articleText = AddMissingFirstCommentHeader(articleText);
            
            articleText = WPBiography(articleText);

            articleText = WPSongs(articleText);

            articleText = WPJazz(articleText);

            // remove redundant Template: in templates in zeroth section
            // clean up excess blank lines after template move
            string zerothSection = WikiRegexes.ZerothSection.Match(articleText).Value;
            if(zerothSection.Length > 0)
            {
				// have we only added whitespace? then reset articletext
				if(zerothSection.Length > zerothSectionOriginal.Length && 
				   WikiRegexes.WhiteSpace.Replace(zerothSection, "").Equals(WikiRegexes.WhiteSpace.Replace(zerothSectionOriginal, "")))
					articleText = articleTextOriginal;
				else 
				{
	                string zerothbefore = zerothSection;
	                // clean excess blank lines at end of zeroth section, leave only one newline
	                // not when later sections: would remove blank line before heading
	                if(zerothSection.Length == articleText.Length &&
	                   (zerothSection.Length-zerothSection.Trim().Length) > 2)
	                    zerothSection = zerothSection.Trim() + "\r\n";

                zerothSection = WikiRegexes.ThreeOrMoreNewlines.Replace(zerothSection, "\r\n\r\n");
                zerothSection = Parse.Parsers.RemoveTemplateNamespace(zerothSection);
                articleText = articleText.Replace(zerothbefore, zerothSection);
				}
            }


            return pr.FoundSkipToTalk || pr.FoundDefaultSort;
        }
        /// <summary>
        /// Processes talk pages: moves any talk page header template, moves any default, adds a section heading if missing
        /// </summary>
        /// <param name="articleText">The talk page text</param>
        /// <param name="moveDefaultsort">The action to take over any defaultsort on the page</param>
        /// <returns>The updated talk page text</returns>
        public static bool ProcessTalkPage(ref string articleText, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText, pr.SkipTOCMatchEvaluator, 1);
            string zerothSectionOriginal = WikiRegexes.ZerothSection.Match(articleText).Value,
                   articleTextOriginal   = articleText;

            // https://en.wikipedia.org/wiki/Wikipedia:TPL
            // Correct order per WP:TPL is
            // 1. {{Skip to talk}}
            // 2. {{Talk header}}
            // 3. {{GA}} or {{GA nominee}}
            // 4. {{Vital article}}
            // 5. {{community article probation}}, {{censor}}, {{BLP others}} and other high-priority/importance, warning/attention templates.
            // 6. Specific talk page guideline banners, such as {{Not a forum}}, {{Recurring themes}}, {{FAQ}}, {{Round in circles}}, etc.
            // 7. Language related talk page guideline banners, such as {{American English}}
            // 8. Any "article history" banner or "article milestone" banner (e.g., {{DYK talk}}, {{On this day}}, {{ITN talk}})
            // 9. WikiProject banner shell - Any WikiProject banners
            // 10. {{Image requested}}
            // 11. {{Press}} and {{Connected contributor}}
            // 12. {{To do}}
            // 13. {{Find sources notice}}, {{Reliable sources for medical articles}}
            // 14. {{Copied}}
            // 15. {{Split from}}, {{Split to}}
            // 16. {{Merge from}}, {{Merge-to}}

            string wpbsBefore             = WikiRegexes.WikiProjectBannerShellTemplate.Match(articleText).Value;
            bool   blanklinesinwpbsBefore = wpbsBefore.Contains("\r\n\r\n");

            articleText = MoveTalkTemplates(articleText, MergeTemplates);
            articleText = MoveTalkTemplates(articleText, SplitTemplates);
            articleText = MoveTalkTemplates(articleText, Copied);
            articleText = MoveTalkTemplates(articleText, FindSource);
            articleText = MoveTalkTemplate(articleText, TodoTemplate);
            articleText = MoveTalkTemplates(articleText, PressConnected);
            articleText = MoveTalkTemplate(articleText, ImageRequested);

            // if template moving leaves blank lines in WPBS then clean this up
            if (wpbsBefore.Length > 0 && !blanklinesinwpbsBefore)
            {
                articleText = WikiRegexes.WikiProjectBannerShellTemplate.Replace(articleText, m => m.Value.Replace("\r\n\r\n", "\r\n"));
            }

            articleText = WikiProjectBannerShell(articleText);

            articleText = MoveTalkTemplate(articleText, WikiRegexes.WikiProjectBannerShellTemplate);
            if (!WikiRegexes.WikiProjectBannerShellTemplate.IsMatch(articleText))
            {
                articleText = MoveTalkTemplates(articleText, WikiProjects);
            }
            articleText = MoveTalkTemplates(articleText, MilestoneTemplates);
            articleText = MoveTalkTemplates(articleText, TalkHistoryBTemplates);
            articleText = MoveTalkTemplates(articleText, TalkHistoryTemplates);
            articleText = MoveTalkTemplate(articleText, EnglishVariationsTemplates);
            articleText = MoveTalkTemplates(articleText, TalkGuidelineTemplates);
            articleText = MoveTalkTemplates(articleText, TalkWarningTemplates);
            articleText = MoveTalkTemplate(articleText, VitalArticle);
            articleText = MoveTalkTemplate(articleText, GANomineeTemplate);

            // move talk page header to the top
            articleText = MoveTalkTemplate(articleText, WikiRegexes.TalkHeaderTemplate);

            if (pr.FoundSkipToTalk)
            {
                WriteHeaderTemplate("Skip to talk", ref articleText);
            }

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText, pr.DefaultSortMatchEvaluator, 1);
                if (pr.FoundDefaultSort)
                {
                    if (!string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText);
                    }
                }
            }

            articleText = AddMissingFirstCommentHeader(articleText);

            articleText = WPBiography(articleText);

            articleText = WPSongs(articleText);

            articleText = WPJazz(articleText);

            // remove redundant Template: in templates in zeroth section
            // clean up excess blank lines after template move
            string zerothSection = WikiRegexes.ZerothSection.Match(articleText).Value;

            if (zerothSection.Length > 0)
            {
                // have we only added whitespace? then reset articletext
                if (zerothSection.Length > zerothSectionOriginal.Length &&
                    WikiRegexes.WhiteSpace.Replace(zerothSection, "").Equals(WikiRegexes.WhiteSpace.Replace(zerothSectionOriginal, "")))
                {
                    articleText = articleTextOriginal;
                }
                else
                {
                    string zerothbefore = zerothSection;
                    // clean excess blank lines at end of zeroth section, leave only one newline
                    // not when later sections: would remove blank line before heading
                    if (zerothSection.Length == articleText.Length &&
                        (zerothSection.Length - zerothSection.Trim().Length) > 2)
                    {
                        zerothSection = zerothSection.Trim() + "\r\n";
                    }

                    zerothSection = WikiRegexes.ThreeOrMoreNewlines.Replace(zerothSection, "\r\n\r\n");
                    zerothSection = Parse.Parsers.RemoveTemplateNamespace(zerothSection);
                    articleText   = articleText.Replace(zerothbefore, zerothSection);
                }
            }


            return(pr.FoundSkipToTalk || pr.FoundDefaultSort);
        }
        public static bool ProcessTalkPage(ref string articleText, ref string summary, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.TalkHeaderTemplate.Replace(articleText,
                                                                 new MatchEvaluator(pr.TalkHeaderMatchEvaluator), 1);

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText, new MatchEvaluator(pr.SkipTOCMatchEvaluator), 1);

            if (pr.FoundTalkHeader)
            {
                WriteHeaderTemplate("talkheader", ref articleText, ref summary);
            }

            if (pr.FoundSkipTOC)
            {
                WriteHeaderTemplate("skiptotoctalk", ref articleText, ref summary);
            }

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText,
                                                              new MatchEvaluator(pr.DefaultSortMatchEvaluator), 1);
                if (pr.FoundDefaultSort)
                {
                    if (string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        AppendToSummary(ref summary, "DEFAULTSORT has no key; removed");
                    }
                    else
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText, ref summary);
                    }
                }
            }
            return(pr.FoundTalkHeader || pr.FoundSkipTOC || pr.FoundDefaultSort);
        }
        /// <summary>
        /// Processes talk pages: moves any talk page header template, moves any default, adds a section heading if missing
        /// </summary>
        /// <param name="articleText">The talk page text</param>
        /// <param name="moveDefaultsort">The action to take over any defaultsort on the page</param>
        /// <returns>The updated talk page text</returns>
        public static bool ProcessTalkPage(ref string articleText, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText, pr.SkipTOCMatchEvaluator, 1);


            // https://en.wikipedia.org/wiki/Wikipedia:TPL
            // Correct order per WP:TPL is
            // 1. {{Skip to talk}}
            // 2. {{Talk header}}
            // 3. {{GA nominee}}
            // 4. {{community article probation}}, {{censor}}, {{BLP others}} and other high-priority/importance, warning/attention templates.
            // 5. Specific talk page guideline banners, such as {{Not a forum}}, {{Recurring themes}}, {{FAQ}}, {{Round in circles}}, etc.
            // 6. Language related talk page guideline banners, such as {{American English}}
            // 7. Any "article history" banner
            // 8. WikiProjectBannerShell - Any WikiProject banners
            // 9. {{Image requested}}
            // 10. {{Press}} and {{Connected contributor}}
            // 11. {{To do}}
            // 12. {{Maintained}}

            string wpbsBefore = WikiRegexes.WikiProjectBannerShellTemplate.Match(articleText).Value;
            bool blanklinesinwpbsBefore = wpbsBefore.Contains("\r\n\r\n");

            articleText = MoveTalkTemplate(articleText, Maintained);
            articleText = MoveTalkTemplate(articleText, TodoTemplate);
            articleText = MoveTalkTemplates(articleText, PressConnected);
            articleText = MoveTalkTemplate(articleText, ImageRequested);

            // if template moving leaves blank lines in WPBS then clean this up
            if(wpbsBefore.Length > 0 && !blanklinesinwpbsBefore)
                articleText = WikiRegexes.WikiProjectBannerShellTemplate.Replace(articleText, m => m.Value.Replace("\r\n\r\n", "\r\n"));
 
            articleText = WikiProjectBannerShell(articleText);

            articleText = MoveTalkTemplate(articleText, WikiRegexes.WikiProjectBannerShellTemplate);
            articleText = MoveTalkTemplate(articleText, TalkHistoryTemplates);
            articleText = MoveTalkTemplate(articleText, EnglishVariationsTemplates);
            articleText = MoveTalkTemplates(articleText, TalkGuidelineTemplates);
            articleText = MoveTalkTemplates(articleText, TalkWarningTemplates);
            articleText = MoveTalkTemplate(articleText, GANomineeTemplate);

            // move talk page header to the top
            articleText = MoveTalkTemplate(articleText, WikiRegexes.TalkHeaderTemplate);

            if (pr.FoundSkipToTalk)
                WriteHeaderTemplate("Skip to talk", ref articleText);

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText, pr.DefaultSortMatchEvaluator, 1);
                if (pr.FoundDefaultSort)
                {
                    if (!string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText);
                    }
                }
            }

            articleText = AddMissingFirstCommentHeader(articleText);
            
            articleText = WPBiography(articleText);

            articleText = WPSongs(articleText);

            articleText = WPJazz(articleText);

            // remove redundant Template: in templates in zeroth section
            // clean up excess blank lines after template move
            string zerothSection = WikiRegexes.ZerothSection.Match(articleText).Value;
            if(zerothSection.Length > 0)
            {
                string zerothbefore = zerothSection;
                zerothSection = WikiRegexes.ThreeOrMoreNewlines.Replace(zerothSection, "\r\n\r\n");
                zerothSection = Parse.Parsers.RemoveTemplateNamespace(zerothSection);
                articleText = articleText.Replace(zerothbefore, zerothSection);
            }


            return pr.FoundSkipToTalk || pr.FoundDefaultSort;
        }
Exemple #25
0
        /// <summary>
        /// Processes talk pages: moves any talk page header template, moves any default, adds a section heading if missing
        /// </summary>
        /// <param name="articleText">The talk page text</param>
        /// <param name="moveDefaultsort">The action to take over any defaultsort on the page</param>
        /// <returns>The updated talk page text</returns>
        public static bool ProcessTalkPage(ref string articleText, DEFAULTSORT moveDefaultsort)
        {
            Processor pr = new Processor();

            articleText = WikiRegexes.SkipTOCTemplateRegex.Replace(articleText, pr.SkipTOCMatchEvaluator, 1);


            // https://en.wikipedia.org/wiki/Wikipedia:TPL
            // Correct order per WP:TPL is
            // 1. {{Skip to talk}}
            // 2. {{Talk header}}
            // 3. {{GA nominee}}
            // 4. {{community article probation}}, {{censor}}, {{BLP others}} and other high-priority/importance, warning/attention templates.
            // 5. Specific talk page guideline banners, such as {{Not a forum}}, {{Recurring themes}}, {{FAQ}}, {{Round in circles}}, etc.
            // 6. Language related talk page guideline banners, such as {{American English}}
            // 7. Any "article history" banner
            // 8. WikiProjectBannerShell - Any WikiProject banners
            // 9. {{Image requested}}
            // 10. {{Press}} and {{Connected contributor}}
            // 11. {{To do}}
            // 12. {{Maintained}}

            string wpbsBefore             = WikiRegexes.WikiProjectBannerShellTemplate.Match(articleText).Value;
            bool   blanklinesinwpbsBefore = wpbsBefore.Contains("\r\n\r\n");

            articleText = MoveTalkTemplate(articleText, Maintained);
            articleText = MoveTalkTemplate(articleText, TodoTemplate);
            articleText = MoveTalkTemplates(articleText, PressConnected);
            articleText = MoveTalkTemplate(articleText, ImageRequested);

            // if template moving leaves blank lines in WPBS then clean this up
            if (wpbsBefore.Length > 0 && !blanklinesinwpbsBefore)
            {
                articleText = WikiRegexes.WikiProjectBannerShellTemplate.Replace(articleText, m => m.Value.Replace("\r\n\r\n", "\r\n"));
            }

            articleText = WikiProjectBannerShell(articleText);

            articleText = MoveTalkTemplate(articleText, WikiRegexes.WikiProjectBannerShellTemplate);
            articleText = MoveTalkTemplate(articleText, TalkHistoryTemplates);
            articleText = MoveTalkTemplate(articleText, EnglishVariationsTemplates);
            articleText = MoveTalkTemplates(articleText, TalkGuidelineTemplates);
            articleText = MoveTalkTemplates(articleText, TalkWarningTemplates);
            articleText = MoveTalkTemplate(articleText, GANomineeTemplate);

            // move talk page header to the top
            articleText = MoveTalkTemplate(articleText, WikiRegexes.TalkHeaderTemplate);

            if (pr.FoundSkipToTalk)
            {
                WriteHeaderTemplate("Skip to talk", ref articleText);
            }

            if (moveDefaultsort != DEFAULTSORT.NoChange)
            {
                articleText = WikiRegexes.Defaultsort.Replace(articleText, pr.DefaultSortMatchEvaluator, 1);
                if (pr.FoundDefaultSort)
                {
                    if (!string.IsNullOrEmpty(pr.DefaultSortKey))
                    {
                        articleText = SetDefaultSort(pr.DefaultSortKey, moveDefaultsort, articleText);
                    }
                }
            }

            articleText = AddMissingFirstCommentHeader(articleText);

            articleText = WPBiography(articleText);

            articleText = WPSongs(articleText);

            articleText = WPJazz(articleText);

            // remove redundant Template: in templates in zeroth section
            // clean up excess blank lines after template move
            string zerothSection = WikiRegexes.ZerothSection.Match(articleText).Value;

            if (zerothSection.Length > 0)
            {
                string zerothbefore = zerothSection;
                zerothSection = WikiRegexes.ThreeOrMoreNewlines.Replace(zerothSection, "\r\n\r\n");
                zerothSection = Parse.Parsers.RemoveTemplateNamespace(zerothSection);
                articleText   = articleText.Replace(zerothbefore, zerothSection);
            }


            return(pr.FoundSkipToTalk || pr.FoundDefaultSort);
        }