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);
}
}