public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
{
Skip = false;
Summary = "";
ArticleText = Regex.Replace(ArticleText,
@"(?<=\[\[)[ _]*" +
@"(?:" + Variables.LangCode.ToString().ToLower() + @"[ _]*:[ _]*)?" +
@"(?:Category|" + Variables.Namespaces[14].Replace(":", "") + @")[ _]*:[ _]*" +
@"(?=[^\]]+\]\])",
Variables.Namespaces[14], RegexOptions.IgnoreCase);
ArticleText = Regex.Replace(ArticleText,
@"(?<=\[\[" +
Variables.Namespaces[14] +
@")\p{Ll}",
new MatchEvaluator(UpFirstChar));
Match match;
string key;
if (!Regex.IsMatch(ArticleText, @"\{\{DEFAULTSORT:[^\}]*\}\}"))
{
match = Regex.Match(ArticleText, @"\[\[Categorie:[^\|\]]+\|((?:[^,\]]+(?=,)|[^\]]{2,})(?:, *[^\]]+)?)\]\]");
if (!match.Success)
{
key = CleanKey(ArticleTitle);
}
else
{
key = CleanKey(match.Groups[1].Value);
}
ArticleText = Regex.Replace(ArticleText,
@"(\[\[Categorie:[^\]]+\]\].*)",
"{{DEFAULTSORT:" + key + "}}\n$1",
RegexOptions.Singleline);
ArticleText = Regex.Replace(ArticleText,
@"(?<=\[\[Categorie:[^\|\]]+)\|[^\]]{2,}(?=\]\])",
"");
}
else
{
ArticleText = Regex.Replace(ArticleText,
@"(?<=\{\{)[ _]*DEFAULTSORT[ _]*:[ _]*([^\}]*?)[ _]*(?=\}\})",
new MatchEvaluator(Key),
RegexOptions.IgnoreCase);
ArticleText = Regex.Replace(ArticleText,
@"(?<=\{\{DEFAULTSORT:[^\}]*\}\})\s*(?=\[\[" +
Variables.Namespaces[14] +
@")",
"\r\n",
RegexOptions.Singleline);
}
return ArticleText;
}
private string UpFirstChar(Match m)
{
return m.Value.ToUpper();
}
private string CleanKey(string key)
{
key = Regex.Replace(key.Replace("_"," "), @" +", " ");
string[] tr1 = new string[48] { "0⅛¼⅜⅝⅞½¾٠۰", "1١۱", "2٢۲", "3٣۳", "4٤۴", "5٥۵", "6٦۶", "7٧۷", "8٨۸", "9٩۹", "aáàâãäåăąāạậả", "AÁÀÂÃÄÅĂĄĀ", "cçćĉčċ", "CÇĆĈČĊ", "dðďđ", "DÐĎĐ", "eéèêëěėęēệếề", "EÉÈÊËĚĖĘĒ", "gğĝġģ", "GĞĜĠĢ", "hĥħ", "HĤĦ", "iíìîïıĩįīịỉ", "IÍÌÎÏİĨĮĪ", "jĵ", "JĴ", "kĸķ", "KĶ", "lĺľłļŀ", "LĹĽŁĻĿ", "nñʼnńňņ", "NÑŃŇŅ", "oóòôõöøőōộồớơớờố", "OÓÒÔÕÖØŐŌ", "rŕřŗ", "RŔŘŖ", "sśŝšşș", "SŚŜŠŞȘ", "tťŧţ", "TŤŦŢ", "uúùûüŭůűũųūưựứủ", "UÚÙÛÜŬŮŰŨŲŪ", "wŵ", "WŴ", "yýÿŷỳỹ", "YÝŶŸ", "zźžż", "ZŹŽŻ" };
string[] tr2 = new string[9] { "aeæ", "AEÆ", "oeœ", "OEŒ", "ssß", "ijij", "ngŋ", "NGŊ", "phφ" };
string[] tr3 = new string[26] { "Aa", "Bb", "Cc", "Dd", "Ee", "Ff", "Gg", "Hh", "Ii", "Jj", "Kk", "Ll", "Mm", "Nn", "Oo", "Pp", "Qq", "Rr", "Ss", "Tt", "Uu","Vv", "Ww", "Xx", "Yy", "Zz" };
string haak= " (\\[.*\\])| (\".*\")| ('.*')| (\\(.*\\))";
foreach (string t in tr1)
{
key = Regex.Replace(key, @"[" + t.Substring(1) + @"]", t.Substring(0, 1));
}
foreach (string t in tr2)
{
key = Regex.Replace(key, @"[" + t.Substring(2) + @"]", t.Substring(0, 2));
}
key=Regex.Replace(key, haak, "");
foreach (string t in tr3)
{
key = Regex.Replace(key, @" " + t.Substring(1),@" " + t.Substring(0, 1));
}
return key;
}
private string Key(Match m)
{
return "DEFAULTSORT:" + CleanKey(m.Groups[1].Value);
}