Jump to content

User:OrenBochman/AWB Modules

From Wikipedia, the free encyclopedia

MY first Module

[edit]

this places talk header template if it is missing in a talk page!

        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            Regex header =  new Regex(@"\{\{Talk header([^}]*)}}", RegexOptions.IgnoreCase);
            Regex header1 = new Regex(@"\{\{Talkheader([^}]*)}}", RegexOptions.IgnoreCase);
           
            Summary = "Adding {{Talk header}}";
 
            Skip = (header.Match(ArticleText).Success 
                || header1.Match(ArticleText).Success 
                || !Namespace.IsTalk(ArticleTitle));
            if (!Skip)
                ArticleText = "{{Talk header}} \r\n" + ArticleText;
 
            return ArticleText;
        }


Fix Upper Case Heading to Sentence case

[edit]
        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
        Skip =false;
        //System.Console.WriteLine("text=[" + ArticleText+ "]");
 
       // string pattern = @"(?<tag>[=]{2,5})([ ]*)(?<head>[A-Z0-9\'\-]+)(?<tail>([ ]+[A-Z0-9,&\-/:()\']+)+)?([ ]*)(\1)";
       string pattern = @"(?<tag>[=]{2,5})([ ]*)(?<head>[A-Z0-9]+)(?<tail>([ ]+[A-Z0-9,&\-/:()\']+)+)?([ ]*)(\1)";
 
        MatchEvaluator evaluator = new MatchEvaluator(TitleCaseFixer);
        String result=Regex.Replace(ArticleText, pattern, evaluator, RegexOptions.ExplicitCapture);
 
        //if(String.Equals(ArticleText, result , StringComparison.CurrentCulture)){Skip =true;}
        Summary = "Err #58 Heading to Sentence Case";
 
            return  result;
        }
 
 
        public static string TitleCaseFixer(Match match)
        {
             string result = "";
             // Creates a TextInfo based on the "en-US" culture.
             System.Globalization.TextInfo myTI = new System.Globalization.CultureInfo("en-US",false).TextInfo;
             result += match.Groups["tag"].Value;               
             result += myTI.ToTitleCase(myTI.ToLower(match.Groups["head"].Value));                    
             result += myTI.ToLower(match.Groups["tail"].Value);
             result += match.Groups["tag"].Value;                                
             return result;
        }