public SaveSection ( string title, string section, string text, string summary ) : string | ||
title | string | |
section | string | |
text | string | |
summary | string | |
리턴 | string |
private void PutNotification(Wiki wiki, TalkResult result, DateTime date) { string talkPageTemplate; string dateString = date.ToString("d MMMM yyyy"); if (!result.Moved) { talkPageTemplate = "{{Не переименовано|" + dateString + "|" + result.Title + "}}\n"; } else { talkPageTemplate = "{{Переименовано|" + dateString + "|" + result.Title + "|" + result.MovedTo + "}}\n"; } string talkPage = "Обсуждение:" + (result.Moved ? result.MovedTo : result.Title); Console.Out.WriteLine("Updating " + talkPage + "..."); try { ParameterCollection parameters = new ParameterCollection(); parameters.Add("rvprop", "content"); parameters.Add("rvsection", "0)"); parameters.Add("prop", "revisions"); XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, new string[] { talkPage }); string content; XmlNode node = xml.SelectSingleNode("//rev"); if (node != null) { content = node.FirstChild != null ? node.FirstChild.Value : ""; } else { content = ""; } int index = content.IndexOf("{{talkheader", StringComparison.CurrentCultureIgnoreCase); if (index != -1) { int endIndex = content.IndexOf("}}", index); if (endIndex != -1) { content = content.Insert(endIndex + 2, "\n" + talkPageTemplate); } } else { index = content.IndexOf("{{заголовок обсуждения", StringComparison.CurrentCultureIgnoreCase); if (index != -1) { int endIndex = content.IndexOf("}}", index); if (endIndex != -1) { content = content.Insert(endIndex + 2, "\n" + talkPageTemplate); } } else { content = content.Insert(0, talkPageTemplate); } } wiki.SaveSection(talkPage, "0", content, "итог"); } catch (WikiException e) { Console.Out.WriteLine("Failed to update " + talkPage + ":" + e.Message); } }
public void UpdateMainPage(Wiki wiki) { Console.Out.WriteLine("Updating proposed merges..."); using (TextReader sr = new StreamReader(_cacheDir + "MainPage.txt")) { string text = sr.ReadToEnd(); wiki.SaveSection("Википедия:К объединению", "1", text, "обновление"); } }
static void Main(string[] args) { Wiki wiki = new Wiki("http://ru.wikipedia.org/w/"); wiki.SleepBetweenQueries = 2; if (string.IsNullOrEmpty(Settings.Default.Login) || string.IsNullOrEmpty(Settings.Default.Password)) { Console.Out.WriteLine("Please add login and password to the configuration file."); return; } Console.Out.WriteLine("Logging in as " + Settings.Default.Login + "..."); try { WikiCache.Login(wiki, Settings.Default.Login, Settings.Default.Password); } catch (WikiException e) { Console.Out.WriteLine(e.Message); return; } Console.Out.WriteLine("Logged in as " + wiki.User + "."); var parameters = new ParameterCollection { {"list", "recentchanges"}, {"rcnamespace", "0"}, {"rcprop", "user"}, {"rcshow", "patrolled|!bot|!anon|!redirect"}, {"rclimit", "2500"}, {"rctype", "edit|new"}, }; if (!File.Exists("DoNotCheck.txt")) { FileStream fs = File.Create("DoNotCheck.txt"); fs.Close(); } HashSet<string> checkedUsers = new HashSet<string>(); using (StreamReader sr = new StreamReader("DoNotCheck.txt")) { string line; while ((line = sr.ReadLine()) != null) { checkedUsers.Add(line); } } HashSet<string> users = new HashSet<string>(); XmlDocument doc = wiki.Enumerate(parameters, false); foreach (XmlNode edit in doc.SelectNodes("//rc")) { string userName = edit.Attributes["user"].Value; if (!checkedUsers.Contains(userName) && !users.Contains(userName)) { users.Add(userName); } } parameters = new ParameterCollection { {"list", "users"}, {"usprop", "groups|editcount|registration"}, }; Dictionary<string, UserInfo> candidates = new Dictionary<string, UserInfo>(); int limit = 500; StringBuilder usersString = new StringBuilder(); int index = 0; foreach (string user in users) { if (index < limit) { usersString.Append("|" + user); ++index; } else { usersString.Remove(0, 1); ParameterCollection localParameters = new ParameterCollection(parameters); localParameters.Add("ususers", usersString.ToString()); doc = wiki.Enumerate(localParameters, true); using (StreamWriter sw = new StreamWriter("DoNotCheck.txt", true)) { FillInCandidates(candidates, doc.SelectNodes("//user"), sw); } index = 1; usersString = new StringBuilder("|" + user); } } if (index > 0) { usersString.Remove(0, 1); ParameterCollection localParameters = new ParameterCollection(parameters); localParameters.Add("ususers", usersString.ToString()); doc = wiki.Enumerate(localParameters, true); using (StreamWriter sw = new StreamWriter("DoNotCheck.txt", true)) { FillInCandidates(candidates, doc.SelectNodes("//user"), sw); } } StringBuilder sb = new StringBuilder("== Список ==\n"); using (StreamWriter sw = new StreamWriter("DoNotCheck.txt", true)) { foreach (var candidate in candidates) { parameters = new ParameterCollection { {"list", "logevents"}, {"leprop", "timestamp"}, {"letype", "block"}, {"letitle", "User:"******"//item") != null; if (wasBlocked) { sw.WriteLine(candidate.Key); continue; } parameters = new ParameterCollection { {"list", "usercontribs"}, {"uclimit", "500"}, {"ucnamespace", "0"}, {"ucprop", "patrolled"}, {"ucuser", candidate.Key}, }; doc = wiki.Enumerate(parameters, false); int totalEdits = doc.SelectNodes("//item").Count; int patrolledEdits = doc.SelectNodes("//item[@patrolled]").Count; Console.Out.WriteLine("{0}: {1} from {2} (was blocked? {3})", candidate.Key, patrolledEdits, totalEdits, wasBlocked ? "Yes" : "No"); if (patrolledEdits > 5 && totalEdits == 500) { sb.AppendFormat("* {{{{userlinks|{0}}}}}, всего правок: {1}, дата регистрации — {2}, отпатрулировано правок: {3}\n", candidate.Key, candidate.Value.Edits, candidate.Value.Registration == DateTime.MinValue ? "— дата неизвестна" : candidate.Value.Registration.ToUniversalTime().ToLongDateString(), patrolledEdits); } } } Console.Out.WriteLine("Википедия:Заявки на статус автопатрулируемого/Кандидаты..."); wiki.SaveSection("Википедия:Заявки на статус автопатрулируемого/Кандидаты", "1", sb.ToString(), "обновление"); }
static void Main(string[] args) { Wiki wiki = new Wiki("http://ru.wikipedia.org/w/"); if (string.IsNullOrEmpty(Settings.Default.Login) || string.IsNullOrEmpty(Settings.Default.Password)) { Console.Out.WriteLine("Please add login and password to the configuration file."); return; } Console.Out.WriteLine("Logging in as " + Settings.Default.Login + "..."); try { wiki.Login(Settings.Default.Login, Settings.Default.Password); } catch (WikiException e) { Console.Out.WriteLine(e.Message); return; } Console.Out.WriteLine("Logged in as " + Settings.Default.Login + "."); wiki.SleepBetweenQueries = 3; Regex re = new Regex(@"\*\s*\[\[User:(.+?)\]\]\s*→\s*\[\[User:(.+?)\]\]"); Dictionary<string, string> renamedUsers = new Dictionary<string, string>(); string renamedUsersData = wiki.LoadText("Википедия:Проект:Патрулирование/Статистика/1k+/Переименования"); using (TextReader sr = new StringReader(renamedUsersData)) { string line; while ((line = sr.ReadLine()) != null) { Match m = re.Match(line); if (m.Success) { string oldName = m.Groups[1].Value; string newName = m.Groups[2].Value; if (!renamedUsers.ContainsKey(oldName)) { renamedUsers.Add(oldName, newName); } } } } DateTime currentMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); DateTime now = currentMonth; DateTime firstReviewMonth = new DateTime(2008, 9, 1); while (currentMonth > firstReviewMonth) { DateTime previousMonth = currentMonth.AddMonths(-1); if (File.Exists("output" + previousMonth.ToString("yyyy-MM") + ".txt")) { currentMonth = currentMonth.AddMonths(-1); continue; } string start = previousMonth.ToString("yyyy-MM-ddTHH:mm:ssZ"); string stop = currentMonth.ToString("yyyy-MM-ddTHH:mm:ssZ"); Console.Out.WriteLine("Quering list of editors for " + previousMonth.ToString("MMMM yyyy") + "..."); ParameterCollection parameters = new ParameterCollection(); parameters.Add("list", "logevents"); parameters.Add("letype", "review"); parameters.Add("lestart", start); parameters.Add("leend", stop); parameters.Add("ledir", "newer"); parameters.Add("lelimit", "max"); Dictionary<string, User> users = new Dictionary<string, User>(); XmlNode continueNode = null; while (true) { XmlDocument doc; try { doc = wiki.MakeRequest(Claymore.SharpMediaWiki.Action.Query, parameters); } catch (WikiException e) { Console.Out.WriteLine(e.Message); return; } continueNode = doc.SelectSingleNode("//query-continue"); if (continueNode != null) { string name = continueNode.FirstChild.Attributes[0].Name; string value = continueNode.FirstChild.Attributes[0].Value; parameters.Set(name, value); } XmlNodeList entries = doc.SelectNodes("//item[@action!=\"approve-a\" and @action!=\"approve-ia\"]"); foreach (XmlNode entry in entries) { string username = renamedUsers.ContainsKey(entry.Attributes["user"].Value) ? renamedUsers[entry.Attributes["user"].Value] : entry.Attributes["user"].Value; string ns = entry.Attributes["ns"].Value; if (!users.ContainsKey(username)) { User user = new User(username); if (ns == "0") { user.ArticleActions = 1; } else if (ns == "14") { user.CategoryActions = 1; } else if (ns == "10") { user.TemplateActions = 1; } else if (ns == "6") { user.FileActions = 1; } users.Add(username, user); } else { User user = users[username]; if (ns == "0") { ++user.ArticleActions; } else if (ns == "14") { ++user.CategoryActions; } else if (ns == "10") { ++user.TemplateActions; } else if (ns == "6") { ++user.FileActions; } users[username] = user; } } if (continueNode == null) { break; } } Console.Out.WriteLine("Processing data..."); List<User> userList = new List<User>(users.Select(s => s.Value)); userList.Sort(CompareUsers); using (StreamWriter sw = new StreamWriter("output" + previousMonth.ToString("yyyy-MM") + ".txt", false)) { int totalActions = 0; int totalArticleActions = 0; int totalCategoryActions = 0; int totalTemplateActions = 0; int totalFileActions = 0; bool bots = false; sw.WriteLine("== " + previousMonth.ToString("MMMM") + " =="); sw.WriteLine("{| class=\"standard sortable\""); sw.WriteLine("!№!!Участник!!всего!!статей!!категорий!!шаблонов!!файлов"); for (int i = 0, j = 1; i < userList.Count; ++i) { if (userList[i].Name.Contains("Lockalbot") || userList[i].Name.Contains("Secretary")) { bots = true; continue; } sw.WriteLine("|-"); totalActions += userList[i].Actions; totalArticleActions += userList[i].ArticleActions; totalCategoryActions += userList[i].CategoryActions; totalTemplateActions += userList[i].TemplateActions; totalFileActions += userList[i].FileActions; string line = string.Format("|{0}||[[User:{1}|]]||{2}||{3}||{4}||{5}||{6}", j++, userList[i].Name, userList[i].Actions, userList[i].ArticleActions, userList[i].CategoryActions, userList[i].TemplateActions, userList[i].FileActions); sw.WriteLine(line); } sw.WriteLine("|-"); sw.WriteLine("|||Итого||{0}||{1}||{2}||{3}||{4}", totalActions, totalArticleActions, totalCategoryActions, totalTemplateActions, totalFileActions); sw.WriteLine("|}"); if (bots) { sw.WriteLine("; Боты"); sw.WriteLine("{| class=\"standard sortable\""); sw.WriteLine("!№!!Участник!!всего!!статей!!категорий!!шаблонов!!файлов"); for (int i = 0, j = 1; i < userList.Count; ++i) { if (userList[i].Name.Contains("Lockalbot") || userList[i].Name.Contains("Secretary")) { sw.WriteLine("|-"); string line = string.Format("|{0}||[[User:{1}|]]||{2}||{3}||{4}||{5}||{6}", j++, userList[i].Name, userList[i].Actions, userList[i].ArticleActions, userList[i].CategoryActions, userList[i].TemplateActions, userList[i].FileActions); sw.WriteLine(line); } } sw.WriteLine("|}"); } sw.WriteLine("\n— ~~~~"); } currentMonth = currentMonth.AddMonths(-1); } currentMonth = new DateTime(2008, 9, 1); Dictionary<string, List<MonthStat>> userStatistics = new Dictionary<string, List<MonthStat>>(); while (currentMonth < now) { using (TextReader sr = new StreamReader("output" + currentMonth.ToString("yyyy-MM") + ".txt")) { string line; while ((line = sr.ReadLine()) != null) { if (line == "|-") { line = sr.ReadLine(); string[] fields = line.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries); string user = fields[1]; int actions = int.Parse(fields[2]); if (user.StartsWith("[[User:"******"output" + currentMonth.ToString("yyyy-MM") + ".txt")) { string line; while ((line = sr.ReadLine()) != null) { if (line == "|-") { line = sr.ReadLine(); string[] fields = line.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries); string user = fields[1]; int actions = int.Parse(fields[2]); if (userStatistics.ContainsKey(user)) { List<MonthStat> stats = userStatistics[user]; stats.Add(new MonthStat(currentMonth, actions)); } } } } currentMonth = currentMonth.AddMonths(1); } using (StreamWriter sw = new StreamWriter("output.txt", false)) { sw.WriteLine("== Статистика =="); for (int year = DateTime.Today.Year; year >= 2008; --year) { DateTime currentYear = new DateTime(year, 1, 1); List<UserStat> userStats = new List<UserStat>(); foreach (var user in userStatistics) { var stats = user.Value.Where(s => (s.Month >= currentYear && s.Month < currentYear.AddYears(1))); UserStat userStat = new UserStat(user.Key, stats); userStat.enterDate = user.Value.Where(s => s.Actions >= 1000).Min(s => s.Month); userStat.ActionsBefore = user.Value.Where(s => s.Month < currentYear).Sum(s => s.Actions); userStat.Max = user.Value.Max(s => s.Actions); if (stats.Count() > 0 && userStat.enterDate.Year <= year) { userStats.Add(userStat); } } userStats.Sort(CompareUserStat); sw.WriteLine("\n=== {0} ===", currentYear.Year); sw.WriteLine("{| class=\"wikitable sortable\""); sw.Write("! № !! Участник"); currentMonth = currentYear; while (currentMonth < currentYear.AddYears(1)) { sw.Write(" !! " + currentMonth.ToString("MMM yy")); currentMonth = currentMonth.AddMonths(1); } sw.Write(" !! За {0} !! На конец {0} ", currentYear.Year); sw.WriteLine(); for (int index = 0; index < userStats.Count; ++index) { sw.WriteLine("|-"); sw.WriteLine(userStats[index].IsBot ? "! Бот" : string.Format("! {0}", index + 1)); sw.Write(string.Format("| {0}", userStats[index].Name)); int max = userStats[index].Stat.Max(s => s.Actions); currentMonth = currentYear; int totalActions = 0; while (currentMonth < currentYear.AddYears(1)) { int actions = 0; foreach (var item in userStats[index].Stat) { if (item.Month == currentMonth) { actions = item.Actions; break; } } if (actions != userStats[index].Max) { sw.Write(" || " + actions); } else { sw.Write(string.Format(" || '''{0}'''", actions)); } totalActions += actions; currentMonth = currentMonth.AddMonths(1); } sw.Write(string.Format(" || {0}", totalActions)); sw.Write(string.Format(" || {0}", totalActions + userStats[index].ActionsBefore)); sw.WriteLine(); } sw.WriteLine("|}"); } } currentMonth = new DateTime(now.Year, now.Month, 1).AddMonths(-1); Console.Out.WriteLine("Updating the wiki page..."); using (TextReader sr = new StreamReader("output" + currentMonth.ToString("yyyy-MM") + ".txt")) { DateTime previousMonth = new DateTime(now.Year, now.Month, 1).AddMonths(-1); string text = sr.ReadToEnd(); string period = previousMonth.ToString("MMMM yyyy"); wiki.Save(previousMonth.ToString("Википедия:Проект:Патрулирование\\/Статистика\\/yyyy\\/MM"), text, "статистика патрулирования за " + period[0].ToString().ToLower() + period.Substring(1)); } Console.Out.WriteLine("Updating Википедия:Проект:Патрулирование/Статистика/1k+..."); using (TextReader sr = new StreamReader("output.txt")) { string text = sr.ReadToEnd(); wiki.SaveSection("Википедия:Проект:Патрулирование/Статистика/1k+", "1", text, "обновление"); } wiki.Save(currentMonth.ToString("Википедия:Проект:Патрулирование\\/Статистика\\/yyyy"), string.Format("#REDIRECT [[{0}]]", currentMonth.ToString("Википедия:Проект:Патрулирование\\/Статистика\\/yyyy\\/MM")), "обновление"); Console.Out.WriteLine("Done."); wiki.Logout(); }
private void PutNotification(Wiki wiki, string title, string date) { string talkPage = wiki.GetNamespace(1) + ":" + title; Console.Out.WriteLine("Updating " + talkPage + "..."); try { ParameterCollection parameters = new ParameterCollection(); parameters.Add("rvprop", "content"); parameters.Add("rvsection", "0)"); parameters.Add("prop", "revisions"); XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, new string[] { talkPage }); string content; XmlNode node = xml.SelectSingleNode("//rev"); if (node != null && node.FirstChild != null) { content = node.FirstChild.Value; } else { content = ""; } int index = content.IndexOf("{{" + _l10i.NotificationTemplate + "|", StringComparison.CurrentCultureIgnoreCase); if (index != -1) { int endIndex = content.IndexOf("}}", index); if (endIndex != -1) { content = content.Insert(endIndex, "|" + date); } } else { index = content.IndexOf("{{talkheader", StringComparison.CurrentCultureIgnoreCase); if (index != -1) { int endIndex = content.IndexOf("}}", index); if (endIndex != -1) { content = content.Insert(endIndex + 2, "\n{{" + _l10i.NotificationTemplate + "|" + date + "}}\n"); } } else { index = content.IndexOf("{{заголовок обсуждения", StringComparison.CurrentCultureIgnoreCase); if (index != -1) { int endIndex = content.IndexOf("}}", index); if (endIndex != -1) { content = content.Insert(endIndex + 2, "\n{{" + _l10i.NotificationTemplate + "|" + date + "}}\n"); } } else { content = content.Insert(0, "\n{{" + _l10i.NotificationTemplate + "|" + date + "}}\n"); } } } wiki.SaveSection(talkPage, "0", content, _l10i.MainPageUpdateComment); } catch (WikiException e) { Console.Out.WriteLine("Failed to update " + talkPage + ":" + e.Message); } }
static void Main(string[] args) { Wiki wiki = new Wiki("http://ru.wikipedia.org/w/"); wiki.SleepBetweenQueries = 2; if (string.IsNullOrEmpty(Settings.Default.Login) || string.IsNullOrEmpty(Settings.Default.Password)) { Console.Out.WriteLine("Please add login and password to the configuration file."); return; } Console.Out.WriteLine("Logging in as " + Settings.Default.Login + "..."); try { WikiCache.Login(wiki, Settings.Default.Login, Settings.Default.Password); } catch (WikiException e) { Console.Out.WriteLine(e.Message); return; } Console.Out.WriteLine("Logged in as " + wiki.User + "."); Dictionary<string, int> requestNumbers = new Dictionary<string, int>(); string text = wiki.LoadText("Википедия:Заявки на арбитраж/Все страницы"); StringReader reader = new StringReader(text); Regex re = new Regex(@" \[\[ВП:(\d+)\]\] — \[\[(.+?)\|"); string line; while ((line = reader.ReadLine()) != null) { Match m = re.Match(line); if (m.Success) { int number = int.Parse(m.Groups[1].Value); string page = m.Groups[2].Value; requestNumbers.Add(page, number); } } var parameters = new ParameterCollection { {"list" , "categorymembers"}, {"cmtitle", "Категория:Википедия:Заявки в Арбитражный комитет"}, {"cmlimit", "max"}, }; List<ArbComEntry> entries = new List<ArbComEntry>(); var doc = wiki.Enumerate(parameters, true); foreach (XmlNode page in doc.SelectNodes("//cm")) { parameters = new ParameterCollection { {"list" , "backlinks"}, {"bltitle", page.Attributes["title"].Value}, {"bllimit", "max"}, {"blfilterredir", "redirects"}, }; int number = int.MinValue; if (requestNumbers.ContainsKey(page.Attributes["title"].Value)) { number = requestNumbers[page.Attributes["title"].Value]; } else { XmlDocument xml = wiki.Enumerate(parameters, true); foreach (XmlNode link in xml.SelectNodes("//bl")) { if (link.Attributes["title"].Value.StartsWith("Википедия:")) { if (int.TryParse(link.Attributes["title"].Value.Replace("Википедия:", ""), out number)) { break; } else { number = int.MinValue; } } } } ArbComEntry entry = new ArbComEntry(); entry.Number = number; entry.Page = page.Attributes["title"].Value; entries.Add(entry); } string prefix = "Википедия:Заявки на арбитраж/"; StringBuilder sb = new StringBuilder("== Заявки ==\n"); entries.Sort(CompareEntries); foreach (ArbComEntry entry in entries) { string requestNumber = ""; if (entry.Number != int.MinValue) { requestNumber = string.Format("[[ВП:{0}]] — ", entry.Number); } string title = entry.Page.Substring(prefix.Length); sb.AppendFormat("* {2}[[{1}{0}|{0}]] [[Обсуждение Википедии:Заявки на арбитраж/{0}|±]] ([[{1}{0}/Дискуссия арбитров|д]])\n", title, prefix, requestNumber); } text = sb.ToString(); wiki.SaveSection("Википедия:Заявки на арбитраж/Все страницы", "1", text, "/* Заявки */ обновление"); }
public void UpdateMainPage(Wiki wiki) { Console.Out.WriteLine("Updating articles for cleanup..."); using (TextReader sr = new StreamReader(_cacheDir + "MainPage.txt")) { string text = sr.ReadToEnd(); wiki.SaveSection(_l10i.MainPage, _l10i.MainPageSection, text, _l10i.MainPageUpdateComment); } }