WikiCrawler/MediaWiki/Api.cs
/// <summary>
/// Set the content of the specified page.
/// </summary>
Set the content of the specified page.
Set the content of the specified page .
public bool SetPage(Article newpage,
			string summary,
			string tags = "",
			bool minor = false,
			bool notminor = false,
			bool bot = true,
			bool createonly = false,
			bool nocreate = false)
        {
            MD5 hashFn = MD5.Create();
            byte[] hash = hashFn.ComputeHash(Encoding.UTF8.GetBytes(newpage.revisions[0].text.ToCharArray()));
            string md5 = Convert.ToBase64String(hash);
			if (string.IsNullOrEmpty(newpage.edittoken))
				newpage.edittoken = GetCsrfToken();
            string baseQuery = "format=json"
                + "&action=edit"
                + "&title=" + UrlEncode(newpage.title)
                + "&text=" + UrlEncode(newpage.revisions[0].text)
                + "&summary=" + UrlEncode(summary)
                + "&starttimestamp=" + UrlEncode(newpage.starttimestamp)
                + "&token=" + UrlEncode(newpage.edittoken);
			if (!string.IsNullOrEmpty(tags))
			{
				baseQuery += "&tags=" + UrlEncode(tags);
			}
			if (bot)
			{
				baseQuery += "&bot";
				baseQuery += "&assert=bot";
			}
			else
			{
				baseQuery += "&assert=user";
			}
			if (minor)
			{
				baseQuery += "&minor";
			}
			if (notminor)
			{
				baseQuery += "&notminor";
			}
			if (createonly)
			{
				baseQuery += "&createonly";
			}
			if (nocreate)
			{
				baseQuery += "&nocreate";
			}
            HttpWebRequest request = CreateApiRequest();
			string json;
			using (StreamReader read = new StreamReader(EasyWeb.Post(request, baseQuery)))
			{
				json = read.ReadToEnd();
			}
            Dictionary<string, object> deser = (Dictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json);
            if (deser.ContainsKey("error"))
            {
                Dictionary<string, object> error = (Dictionary<string, object>)deser["error"];
				throw new WikimediaException(error["code"] + ": " + error["info"]);
			}
			newpage.Dirty = false;
			newpage.Changes.Clear();
            return true;
        }
public bool SetPage ( Article newpage , string summary , string tags = " " , bool minor = false , bool notminor = false , bool bot = true , bool createonly = false , bool nocreate = false ) { MD5 hashFn = MD5 . Create ( ) ; byte [ ] hash = hashFn . ComputeHash ( Encoding . UTF8 . GetBytes ( newpage . revisions [ 0 ] . text . ToCharArray ( ) ) ) ; string md5 = Convert . ToBase64String ( hash ) ; if ( string . IsNullOrEmpty ( newpage . edittoken ) ) newpage . edittoken = GetCsrfToken ( ) ; string baseQuery = " " + " " + " " + UrlEncode ( newpage . title ) + " " + UrlEncode ( newpage . revisions [ 0 ] . text ) + " " + UrlEncode ( summary ) + " " + UrlEncode ( newpage . starttimestamp ) + " " + UrlEncode ( newpage . edittoken ) ; if ( ! string . IsNullOrEmpty ( tags ) ) { baseQuery += " " + UrlEncode ( tags ) ; } if ( bot ) { baseQuery += " " ; baseQuery += " " ; } else { baseQuery += " " ; } if ( minor ) { baseQuery += " " ; } if ( notminor ) { baseQuery += " " ; } if ( createonly ) { baseQuery += " " ; } if ( nocreate ) { baseQuery += " " ; } HttpWebRequest request = CreateApiRequest ( ) ; string json ; using ( StreamReader read = new StreamReader ( EasyWeb . Post ( request , baseQuery ) ) ) { json = read . ReadToEnd ( ) ; } Dictionary < string , object > deser = ( Dictionary < string , object > ) new JavaScriptSerializer ( ) . DeserializeObject ( json ) ; if ( deser . ContainsKey ( " " ) ) { Dictionary < string , object > error = ( Dictionary < string , object > ) deser [ " " ] ; throw new WikimediaException ( error [ " " ] + " " + error [ " " ] ) ; } newpage . Dirty = false ; newpage . Changes . Clear ( ) ; return true ; }
Set the content of the specified page.
Set the content of the specified page .
//+ "&md5=" + UrlEncode(md5) //Read response
newpage
Article
summary
string
tags
string
minor
bool
notminor
bool
bot
bool
createonly
bool
nocreate
bool