Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
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="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;
        }
Exemplo n.º 3
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,
                                                                   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;
        }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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);
            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;
        }
Exemplo n.º 7
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);
        }