示例#1
0
 /// <summary>Renames the page.</summary>
 /// <param name="newTitle">New title of that page.</param>
 /// <param name="reason">Reason for renaming.</param>
 public void RenameTo(string newTitle, string reason)
 {
     if (string.IsNullOrEmpty(newTitle))
         throw new ArgumentNullException("newTitle");
     if (string.IsNullOrEmpty(title))
         throw new WikiBotException(Bot.Msg("No title specified for page to rename."));
     //Page mp = new Page(site, "Special:Movepage/" + HttpUtility.UrlEncode(title));
     Page mp = new Page(site, "Special:Movepage/" + title);
     mp.GetEditSessionData();
     if (string.IsNullOrEmpty(mp.editSessionToken))
         throw new WikiBotException(string.Format(
             Bot.Msg("Unable to rename page \"{0}\" to \"{1}\"."), title, newTitle));
     if (Bot.askConfirm)
     {
         Console.Write("\n\n" +
             Bot.Msg("The page \"{0}\" is going to be renamed to \"{1}\".\n"),
             title, newTitle);
         if (!Bot.UserConfirms())
             return;
     }
     string postData = string.Format("wpNewTitle={0}&wpOldTitle={1}&wpEditToken={2}" +
         "&wpReason={3}", HttpUtility.UrlEncode(newTitle), HttpUtility.UrlEncode(title),
         HttpUtility.UrlEncode(mp.editSessionToken), HttpUtility.UrlEncode(reason));
     string respStr = site.PostDataAndGetResultHTM(site.indexPath +
         "index.php?title=Special:Movepage&action=submit", postData);
     if (Site.editSessionTokenRE2.IsMatch(respStr))
         throw new WikiBotException(string.Format(
             Bot.Msg("Failed to rename page \"{0}\" to \"{1}\"."), title, newTitle));
     Console.WriteLine(
         Bot.Msg("Page \"{0}\" was successfully renamed to \"{1}\"."), title, newTitle);
     title = newTitle;
 }
示例#2
0
 /// <summary>Gets all MediaWiki messages from "Special:Allmessages" page and loads them into
 /// site.messages PageList. The function is not backward compatible.</summary>
 public void GetMediaWikiMessages()
 {
     if (messages == null)
         messages = new PageList(this);
     Console.WriteLine(Bot.Msg("Updating MediaWiki messages dump. Please, wait..."));
     string res = site + indexPath + "index.php?title=Special:Allmessages";
     string src = "";
     Page p = null;
     Regex nextPortionRE = new Regex("offset=([^\"]+)\" title=\"[^\"]+\" rel=\"next\"");
     do
     {
         src = GetPageHTM(res + (src != ""
             ? "&offset=" + HttpUtility.HtmlDecode(nextPortionRE.Match(src).Groups[1].Value)
             : "&limit=5000"));
         using (XmlReader reader = GetXMLReader(src))
         {
             reader.ReadToFollowing("tbody");
             while (reader.Read())
             {
                 if (reader.Name == "tr" && reader.NodeType == XmlNodeType.Element &&
                     reader["id"] != null)
                     p = new Page(this, namespaces["8"].ToString() + ":" +
                         Bot.Capitalize(reader["id"].Replace("msg_", "")));
                 else if (reader.Name == "td" &&
                     (reader["class"] == "am_default" || reader["class"] == "am_actual"))
                     p.text = reader.ReadString();
                 else if (reader.Name == "tr" && reader.NodeType == XmlNodeType.EndElement)
                     messages.Add(p);
                 else if (reader.Name == "tbody" &&
                     reader.NodeType == XmlNodeType.EndElement)
                     break;
             }
         }
     } while (nextPortionRE.IsMatch(src));
     if (p != null)
         messages.Add(p);
     Console.WriteLine(Bot.Msg("MediaWiki messages dump updated successfully."));
 }