User:Yobot/Automobile

From Wikipedia, the free encyclopedia
// Removes old parameters (similar, parent_company, fuel_capacity, fuel_economy, electric_range) in Infobox automobile.
// Converts the image parameter to barefilenames
 
        private static readonly Regex Templ = Tools.NestedTemplateRegex(new List<string>("Infobox automobile, Infobox automobile engine, Infobox automobile platform".Split(',')));
        private static readonly Regex File = new Regex(@"\[\[File:([^\|\]]+)(.*)",     RegexOptions.Compiled);
        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            Skip = false;
            Summary = "";
 
              foreach(Match m in Templ.Matches(ArticleText))
                {
                string TemplCall = m.Value, newValue = m.Value;
 
                      //  Remove only from Infobox automobile
                      //  newValue = Tools.RemoveTemplateParameter(newValue, "similar");
                      //  newValue = Tools.RemoveTemplateParameter(newValue, "parent_company");
                      //  newValue = Tools.RemoveTemplateParameter(newValue, "fuel_capacity");
                      //  newValue = Tools.RemoveTemplateParameter(newValue, "fuel_economy");
                      //  newValue = Tools.RemoveTemplateParameter(newValue, "electric_range");
 
                string image = Tools.GetTemplateParameterValue(TemplCall, "image");
                //string oldcaption = Tools.GetTemplateParameterValue(TemplCall, "caption");
                //string newcaption = Tools.GetTemplateParameterValue(TemplCall, "image");
                       //newcaption = File.Replace(newcaption, "$4");
                       //image = File.Replace(image, "$1")+"\r\n| caption="+caption;
                       string Rest =File.Replace(image, "$2");
                       if (!Rest.Contains("File"))
                       {
                       image = File.Replace(image, "$1");
                       }
 
                        //newValue = Tools.RemoveTemplateParameter(newValue, "caption");
                        newValue = Tools.SetTemplateParameterValue(newValue, "image", image);
                       //if ((oldcaption.Length == 0) && (newcaption.Length > 0))
                       //{
                       // newValue = Tools.SetTemplateParameterValue(newValue, "caption", newcaption);
                       //}

            ArticleText = ArticleText.Replace(m.Value, newValue);
        }
            return ArticleText;
        }