FANDOM


// This is a custom module for AWB to replace [[wikipedia:]] links to {{wp}}; in progress
public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip) {
     Skip = false;
     Summary = "";
 
     ArticleText = WpConvert(ArticleText);
 
     return ArticleText;
}
 
public string WpConvert(string ArticleText) {
 
     string pattern = "\\[{2}wikipedia:(([a-zA-z]{2,3}):)?([^\\[\\|]*)\\|([^\\[\\|]*)]{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++) {
          if(string.Equals(mc[i].Groups[3].Value, mc[i].Groups[4].Value, StringComparison.OrdinalIgnoreCase)) {
               if(String.IsNullOrEmpty(mc[i].Groups[1].Value))
	            rep[i] = "{{wp|en|" + mc[i].Groups[4].Value + "}}";
	       else
	            rep[i] = "{{wp|" + mc[i].Groups[2].Value + "|" + mc[i].Groups[4].Value + "}}";
          }
	  else {
               if(string.IsNullOrEmpty(mc[i].Groups[1].Value))
                    rep[i] = "{{wp|en|" + mc[i].Groups[3].Value + "|" + mc[i].Groups[4].Value + "}}";
               else
                    rep[i] = "{{wp|" + mc[i].Groups[2].Value + "|" + mc[i].Groups[3].Value + "|" + mc[i].Groups[4].Value + "}}";
          }
          result = result.Replace(mc[i].Groups[0].Value, rep[i]);
     }
 
     return result;
}
Community content is available under CC-BY-SA unless otherwise noted.