User:Yobot/Bare filenames

// Replaces File:Example.jpg with Example.jpg in parameter image

private static readonly Regex Milperson = Tools.NestedTemplateRegex(new List("Infobox book".Split(',')));

public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)

{

Skip = true;

Summary = "Use bare filenames in image parameter in infobox";

foreach(Match m in Milperson.Matches(ArticleText))

{

string TempCall = m.Value, newValue = m.Value;

string image = Tools.GetTemplateParameterValue(TempCall, "image");

string caption = Tools.GetTemplateParameterValue(TempCall, "caption");

if(image.Length == 0)

continue;

string imagelink = WikiRegexes.FileNamespaceLink.Match(image).Value;

string newcaption = caption;

string newimage = WikiRegexes.FileNamespaceLink.Match(image).Groups[1].Value;

if (newimage.Contains("|"))

newimage = newimage.Substring(0, newimage.IndexOf("|"));

//if (imagelink.Contains("|"))

// continue;

newValue = Tools.UpdateTemplateParameterValue(newValue, "image", newimage);

newValue = Tools.UpdateTemplateParameterValue(newValue, "caption", newcaption);

if(!m.Value.Equals(newValue))

{

Skip = false;

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

}

}

return ArticleText;

}