コード例 #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));
     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));
     Bot.LogEvent(
         Bot.Msg("Page \"{0}\" was successfully renamed to \"{1}\"."), title, newTitle);
     title = newTitle;
 }
コード例 #2
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)
 {
     Page mp = new Page(site, "Special:Movepage/" + HttpUtility.UrlEncode(title));
     mp.GetEditSessionData();
     if (String.IsNullOrEmpty(mp.editSessionToken)) {
         Console.WriteLine("Unable to rename page \"" + title + "\" to \"" +
             newTitle + "\".");
         return;
     }
        		HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(site.site +
         site.indexPath + "index.php?title=Special:Movepage&action=submit");
     webReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
     webReq.Method = "POST";
     webReq.ContentType = Bot.webContentType;
     webReq.UserAgent = Bot.botVer;
     webReq.CookieContainer = new CookieContainer();
     string postData = string.Format("wpNewTitle={0}&wpOldTitle={1}&wpEditToken={2}" +
         "&wpReason={3}", HttpUtility.UrlEncode(newTitle), HttpUtility.UrlEncode(title),
         mp.editSessionToken, HttpUtility.UrlEncode(reason));
     foreach (Cookie cookie in site.cookies)
         webReq.CookieContainer.Add(cookie);
     byte[] postBytes = Encoding.UTF8.GetBytes(postData);
     webReq.ContentLength = postBytes.Length;
     Stream reqStrm = webReq.GetRequestStream();
     reqStrm.Write(postBytes, 0, postBytes.Length);
     reqStrm.Close();
     HttpWebResponse webResp = (HttpWebResponse) webReq.GetResponse();
     StreamReader strmReader = new StreamReader(webResp.GetResponseStream());
     string respStr = strmReader.ReadToEnd();
     strmReader.Close();
     webResp.Close();
     if (site.editSessionTokenRE2.IsMatch(respStr)) {
         Console.WriteLine("Failed to rename page \"" + title + "\" to \"" +
             newTitle + "\".");
         return;
     }
     Console.WriteLine("Page \"" + title + "\" was successfully renamed to \"" +
         newTitle + "\".");
     title = newTitle;
 }
コード例 #3
0
ファイル: DotNetWikiBot.cs プロジェクト: knabbi/GW2WBot
 /// <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, bool leaveRedirect)
 {
     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));
     if (leaveRedirect)
         postData += "&wpLeaveRedirect=1";
     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;
 }
コード例 #4
0
 /// <summary>Logs in and retrieves cookies.</summary>    	  	
 private void LogIn()
 {
     HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(site + indexPath +
         "index.php?title=Special:Userlogin&action=submitlogin&type=login");
     String postData = String.Format("wpName=+{0}&wpPassword={1}&wpRemember=1&wpLoginattempt=Log+in",
         new string[] {userName, userPass});
     webReq.Method = "POST";
     webReq.ContentType = Bot.webContentType;
     webReq.UserAgent = Bot.botVer;
     webReq.Proxy.Credentials = CredentialCache.DefaultCredentials;
     webReq.CookieContainer = new CookieContainer();
     webReq.AllowAutoRedirect = false;
     byte[] postBytes = Encoding.UTF8.GetBytes(postData);
     webReq.ContentLength = postBytes.Length;
     Stream reqStrm = webReq.GetRequestStream();
     reqStrm.Write(postBytes, 0, postBytes.Length);
     reqStrm.Close();
     try {
         HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();
         cookies = webResp.Cookies;
         webResp.Close();
     }
     catch (WebException) {
         if (indexPath == "/wiki/")
             throw new WikiBotException("\n\nLogin failed. Check your username and password.\n");
         indexPath = "/wiki/";
         wikiPath = "/wiki/index.php?title=";
         LogIn();
         return;
     }
     Page testLogin = new Page(this, "Non-existing-page");
     testLogin.GetEditSessionData();
     if (String.IsNullOrEmpty(testLogin.editSessionToken)) {
         throw new WikiBotException("\n\nLogin failed. Check your username and password.\n");
     }
     Console.WriteLine("Logged in as " + userName);
 }