FANDOM


// This is a custom module for AWB to replace [[wikispecies:]] links to {{wsp}}
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip) {
 
	 if(ArticleText.Contains("wikispecies:"))
		 Skip = false;
	 else
		 Skip = true;
 
     Summary = "Changing Wikispecies links (using [[User:Dserbot/WspConvert.cs|WspConvert.cs]] with [[wikipedia:WP:AWB|AWB]])";
 
     ArticleText = WspConvert(ArticleText);
 
     return ArticleText;
}
 
public string WspConvert(string ArticleText) {
 
     string pattern = "\\[{2}wikispecies:([^\\[\\|]+)\|([^\\[\\|]+)\\]{2}";
     string result;
 
     result = String.Copy(ArticleText);
 
     Regex rgx = new Regex(pattern);
 
     int count = Regex.Matches(ArticleText, pattern).Count;
     MatchCollection mc = Regex.Matches(ArticleText, pattern);
 
     string[] rep = new string[count];
 
     for(int i = 0; i < count; i++) {
 
		 string wspTitle = mc[i].Groups[1].Value;
		 string disp = mc[i].Groups[2].Value;
 
		 if(string.Equals(wspTitle, disp, StringComparison.OrdinalIgnoreCase))
			 rep[i] = "{{wsp|" + wspTitle + "}}";
		 else
			 rep[i] = "{{wsp|" + wspTitle + "|" + disp + "}}";
 
         result = result.Replace(mc[i].Groups[0].Value, rep[i]);
     }
 
     return result;
}
Community content is available under CC-BY-SA unless otherwise noted.