public static void LoadWikiData(string data) { LocalDomain = Category1 = Category2 = Category3 = Information = Description = Date = Source = Author = Permission = Other_versions = Summary = Licensing = ""; List <PotentialProblem> problems = new List <PotentialProblem>(); List <KeyValuePair <string, string> > replaces = new List <KeyValuePair <string, string> >(); List <KeyValuePair <string, string> > selfReplaces = new List <KeyValuePair <string, string> >(); DefaultCategory = "1"; // newer properties that require default values (since they are not specified in // older .wiki files) NowCommonsDeletionSummary = "Media file now available on Commons"; NowCommonsAddingTagEditSummary = "Added {{now Commons}} tag"; NowCommonsReplacingTagEditSummary = "Replaced {{move to Commons}} tag with {{now Commons}} tag"; LocalFtcgPage = "w:en:WP:FTCG"; FileTalkMinimumSize = "120"; // small default string[] lines = data.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { string l = lines[i]; if (l == "" || l.StartsWith("#")) { continue; } if (l == "[PotentialProblem]") { string test = lines[i + 1]; string message = lines[i + 2]; PotentialProblem prob = new PotentialProblem(); prob.Test = test.Substring(test.IndexOf('=') + 1); prob.IsRegex = test.StartsWith("IfRegex="); prob.Message = message.Substring(message.IndexOf('=') + 1); problems.Add(prob); i += 2; } else if (l == "[Replacement]") { string lookfor = lines[i + 1]; string replacewith = lines[i + 2]; replaces.Add(new KeyValuePair <string, string>(lookfor.Substring(lookfor.IndexOf('=') + 1), replacewith.Substring(replacewith.IndexOf('=') + 1))); i += 2; } else if (l == "[SelfLicenseReplacement]") { string lookfor = lines[i + 1]; string replacewith = lines[i + 2]; selfReplaces.Add(new KeyValuePair <string, string>(lookfor.Substring(lookfor.IndexOf('=') + 1), replacewith.Substring(replacewith.IndexOf('=') + 1))); i += 2; } else { try { // a very naughty little bit of covert reflection here typeof(LocalWikiData).GetProperty(l.Substring(0, l.IndexOf('=')), BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreCase) .SetValue(null, l.Substring(l.IndexOf('=') + 1), null); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } //MessageBox.Show(Localization.GetString("LocalWikiDataLoadFailed") + "\n\n" + e.Message); // silently fail for the moment } } } // validate FileTalkMinimumSize int dummy; if (!int.TryParse(FileTalkMinimumSize, out dummy)) { FileTalkMinimumSize = "120"; } PotentialProblems = problems.ToArray(); Replacements = replaces.ToArray(); SelfLicenseReplacements = selfReplaces.ToArray(); }
public static void LoadWikiData(string data) { LocalDomain = Category1 = Category2 = Category3 = Information = Description = Date = Source = Author = Permission = Other_versions = Summary = Licensing = ""; List<PotentialProblem> problems = new List<PotentialProblem>(); List<KeyValuePair<string, string>> replaces = new List<KeyValuePair<string, string>>(); List<KeyValuePair<string, string>> selfReplaces = new List<KeyValuePair<string, string>>(); DefaultCategory = "1"; // newer properties that require default values (since they are not specified in // older .wiki files) NowCommonsDeletionSummary = "Media file now available on Commons"; NowCommonsAddingTagEditSummary = "Added {{now Commons}} tag"; NowCommonsReplacingTagEditSummary = "Replaced {{move to Commons}} tag with {{now Commons}} tag"; LocalFtcgPage = "w:en:WP:FTCG"; FileTalkMinimumSize = "120"; // small default string[] lines = data.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { string l = lines[i]; if (l == "" || l.StartsWith("#")) continue; if (l == "[PotentialProblem]") { string test = lines[i + 1]; string message = lines[i + 2]; PotentialProblem prob = new PotentialProblem(); prob.Test = test.Substring(test.IndexOf('=') + 1); prob.IsRegex = test.StartsWith("IfRegex="); prob.Message = message.Substring(message.IndexOf('=') + 1); problems.Add(prob); i += 2; } else if (l == "[Replacement]") { string lookfor = lines[i + 1]; string replacewith = lines[i + 2]; replaces.Add(new KeyValuePair<string, string>(lookfor.Substring(lookfor.IndexOf('=') + 1), replacewith.Substring(replacewith.IndexOf('=') + 1))); i += 2; } else if (l == "[SelfLicenseReplacement]") { string lookfor = lines[i + 1]; string replacewith = lines[i + 2]; selfReplaces.Add(new KeyValuePair<string, string>(lookfor.Substring(lookfor.IndexOf('=') + 1), replacewith.Substring(replacewith.IndexOf('=') + 1))); i += 2; } else { try { // a very naughty little bit of covert reflection here typeof(LocalWikiData).GetProperty(l.Substring(0, l.IndexOf('=')), BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreCase) .SetValue(null, l.Substring(l.IndexOf('=') + 1), null); } catch (Exception) { if (Debugger.IsAttached) Debugger.Break(); //MessageBox.Show(Localization.GetString("LocalWikiDataLoadFailed") + "\n\n" + e.Message); // silently fail for the moment } } } // validate FileTalkMinimumSize int dummy; if (!int.TryParse(FileTalkMinimumSize, out dummy)) FileTalkMinimumSize = "120"; PotentialProblems = problems.ToArray(); Replacements = replaces.ToArray(); SelfLicenseReplacements = selfReplaces.ToArray(); }
public static void LoadWikiData(string[] lines) { LocalDomain = Category1 = Category2 = Category3 = Information = Description = Date = Source = Author = Permission = Other_versions = Summary = Licensing = ""; List <PotentialProblem> problems = new List <PotentialProblem>(); Replacements = new StringDictionary(); SelfLicenseReplacements = new StringDictionary(); DefaultCategory = "1"; for (int i = 0; i < lines.Length; i++) { string l = lines[i]; if (l == "" || l.StartsWith("#")) { continue; } if (l == "[PotentialProblem]") { string test = lines[i + 1]; string message = lines[i + 2]; PotentialProblem prob = new PotentialProblem(); prob.Test = test.Substring(test.IndexOf('=') + 1); prob.IsRegex = test.StartsWith("IfRegex="); prob.Message = message.Substring(message.IndexOf('=') + 1); problems.Add(prob); i += 2; } else if (l == "[Replacement]") { string lookfor = lines[i + 1]; string replacewith = lines[i + 2]; Replacements.Add(lookfor.Substring(lookfor.IndexOf('=') + 1), replacewith.Substring(replacewith.IndexOf('=') + 1)); i += 2; } else if (l == "[SelfLicenseReplacement]") { string lookfor = lines[i + 1]; string replacewith = lines[i + 2]; SelfLicenseReplacements.Add(lookfor.Substring(lookfor.IndexOf('=') + 1), replacewith.Substring(replacewith.IndexOf('=') + 1)); i += 2; } else { try { // a very naughty little bit of covert reflection here typeof(LocalWikiData).GetProperty(l.Substring(0, l.IndexOf('=')), BindingFlags.Static | BindingFlags.Public) .SetValue(null, l.Substring(l.IndexOf('=') + 1), null); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } //MessageBox.Show(Localization.GetString("LocalWikiDataLoadFailed") + "\n\n" + e.Message); // silently fail for the moment } } } PotentialProblems = problems.ToArray(); }
public static void LoadWikiData(string[] lines) { LocalDomain = Category1 = Category2 = Category3 = Information = Description = Date = Source = Author = Permission = Other_versions = Summary = Licensing = ""; List<PotentialProblem> problems = new List<PotentialProblem>(); Replacements = new StringDictionary(); SelfLicenseReplacements = new StringDictionary(); DefaultCategory = "1"; for (int i = 0; i < lines.Length; i++) { string l = lines[i]; if (l == "" || l.StartsWith("#")) continue; if (l == "[PotentialProblem]") { string test = lines[i + 1]; string message = lines[i + 2]; PotentialProblem prob = new PotentialProblem(); prob.Test = test.Substring(test.IndexOf('=') + 1); prob.IsRegex = test.StartsWith("IfRegex="); prob.Message = message.Substring(message.IndexOf('=') + 1); problems.Add(prob); i += 2; } else if (l == "[Replacement]") { string lookfor = lines[i + 1]; string replacewith = lines[i + 2]; Replacements.Add(lookfor.Substring(lookfor.IndexOf('=') + 1), replacewith.Substring(replacewith.IndexOf('=') + 1)); i += 2; } else if (l == "[SelfLicenseReplacement]") { string lookfor = lines[i + 1]; string replacewith = lines[i + 2]; SelfLicenseReplacements.Add(lookfor.Substring(lookfor.IndexOf('=') + 1), replacewith.Substring(replacewith.IndexOf('=') + 1)); i += 2; } else { try { // a very naughty little bit of covert reflection here typeof(LocalWikiData).GetProperty(l.Substring(0, l.IndexOf('=')), BindingFlags.Static | BindingFlags.Public) .SetValue(null, l.Substring(l.IndexOf('=') + 1), null); } catch (Exception) { if (Debugger.IsAttached) Debugger.Break(); //MessageBox.Show(Localization.GetString("LocalWikiDataLoadFailed") + "\n\n" + e.Message); // silently fail for the moment } } } PotentialProblems = problems.ToArray(); }