WikiCrawler/MediaWiki/Api.cs
/// <summary>
/// Returns the Wiki text for all of the specified pages
/// </summary>
Returns the Wiki text for all of the specified pages
Returns the Wiki text for all of the specified pages
public Article[] GetPages(IList<string> titles,
			string prop = "info|revisions",
			string iiprop = "",
			int iilimit = Limit.Unspecified,
			string rvprop = "content",
			int rvlimit = Limit.Unspecified,
			string clshow = "",
			int cllimit = Limit.Max,
			string cldir = "")
        {
			if (titles.Count == 0) return new Article[0];
			string baseQuery = "format=json"
				+ "&action=query"
				+ "&titles=" + UrlEncode(string.Join("|", titles));
			if (!string.IsNullOrEmpty(prop))
			{
				baseQuery += "&prop=" + UrlEncode(prop);
			}
			if (!string.IsNullOrEmpty(iiprop))
			{
				baseQuery += "&iiprop=" + UrlEncode(iiprop);
			}
			if (iilimit != Limit.Unspecified)
			{
				baseQuery += "&iilimit=" + GetLimitParameter(iilimit);
			}
			if (!string.IsNullOrEmpty(rvprop))
			{
				baseQuery += "&rvprop=" + UrlEncode(rvprop);
			}
			if (rvlimit != Limit.Unspecified)
			{
				baseQuery += "&rvlimit=" + GetLimitParameter(rvlimit);
			}
			if (!string.IsNullOrEmpty(clshow))
			{
				baseQuery += "&clshow=" + UrlEncode(clshow);
			}
			if (cllimit != Limit.Unspecified)
			{
				baseQuery += "&cllimit=" + GetLimitParameter(cllimit);
			}
			if (!string.IsNullOrEmpty(cldir))
			{
				baseQuery += "&cldir=" + UrlEncode(cldir);
			}
			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);
            Dictionary<string, object> query = (Dictionary<string, object>)deser["query"];
            Dictionary<string, object> pages = (Dictionary<string, object>)query["pages"];
            Article[] ret = new Article[pages.Count];
            int current = 0;
            foreach (KeyValuePair<string, object> page in pages)
            {
				Dictionary<string, object> jsonData = (Dictionary<string, object>)page.Value;
				if (jsonData.ContainsKey("invalid"))
				{
					continue;
				}
				ret[current++] = new Article(jsonData);
            }
            return ret;
        }
public Article [ ] GetPages ( IList < string > titles , string prop = " " , string iiprop = " " , int iilimit = Limit . Unspecified , string rvprop = " " , int rvlimit = Limit . Unspecified , string clshow = " " , int cllimit = Limit . Max , string cldir = " " ) { if ( titles . Count == 0 ) return new Article [ 0 ] ; string baseQuery = " " + " " + " " + UrlEncode ( string . Join ( " " , titles ) ) ; if ( ! string . IsNullOrEmpty ( prop ) ) { baseQuery += " " + UrlEncode ( prop ) ; } if ( ! string . IsNullOrEmpty ( iiprop ) ) { baseQuery += " " + UrlEncode ( iiprop ) ; } if ( iilimit != Limit . Unspecified ) { baseQuery += " " + GetLimitParameter ( iilimit ) ; } if ( ! string . IsNullOrEmpty ( rvprop ) ) { baseQuery += " " + UrlEncode ( rvprop ) ; } if ( rvlimit != Limit . Unspecified ) { baseQuery += " " + GetLimitParameter ( rvlimit ) ; } if ( ! string . IsNullOrEmpty ( clshow ) ) { baseQuery += " " + UrlEncode ( clshow ) ; } if ( cllimit != Limit . Unspecified ) { baseQuery += " " + GetLimitParameter ( cllimit ) ; } if ( ! string . IsNullOrEmpty ( cldir ) ) { baseQuery += " " + UrlEncode ( cldir ) ; } 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 ) ; Dictionary < string , object > query = ( Dictionary < string , object > ) deser [ " " ] ; Dictionary < string , object > pages = ( Dictionary < string , object > ) query [ " " ] ; Article [ ] ret = new Article [ pages . Count ] ; int current = 0 ; foreach ( KeyValuePair < string , object > page in pages ) { Dictionary < string , object > jsonData = ( Dictionary < string , object > ) page . Value ; if ( jsonData . ContainsKey ( " " ) ) { continue ; } ret [ current ++ ] = new Article ( jsonData ) ; } return ret ; }
Returns the Wiki text for all of the specified pages
Returns the Wiki text for all of the specified pages
//Download stream //Parse and read
titles
IList<string>
prop
string
iiprop
string
iilimit
int
rvprop
string
rvlimit
int
clshow
string
cllimit
int
cldir
string