public void OpenPageInBrowser(string title) { if (!Variables.UsingSecure) { string url = ArticleUrl.Replace("$1", Tools.WikiEncode(title)); Tools.OpenURLInBrowser(url); } else { Tools.OpenArticleInBrowser(title); } }
/// <summary> /// Gets the wikitext for a specified article. /// </summary> /// <param name="Article">The article to return the wikitext for.</param> /// <param name="indexpath">The path to the index page of the wiki to edit.</param> /// <returns>The wikitext of the specified article.</returns> public static String GetWikiText(String Article, string indexpath, int oldid) { try { string targetUrl = indexpath + "index.php?title=" + Tools.WikiEncode(Article) + "&action=raw"; if (oldid != 0) { targetUrl += "&oldid=" + oldid; } HttpWebRequest wr = Variables.PrepareWebRequest(targetUrl, mUserAgent); HttpWebResponse resps; Stream stream; StreamReader sr; string wikitext = ""; //wr.Proxy.Credentials = CredentialCache.DefaultCredentials; resps = (HttpWebResponse)wr.GetResponse(); stream = resps.GetResponseStream(); sr = new StreamReader(stream); wikitext = sr.ReadToEnd(); sr.Close(); stream.Close(); resps.Close(); return(wikitext); } catch (WebException ex) { if (ex.ToString().Contains("404")) { return(""); } else { throw; } } }
public void OpenPageInBrowser(string title) { string url = ArticleUrl.Replace("$1", Tools.WikiEncode(title)); Tools.OpenURLInBrowser(url); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <returns></returns> public static string GetUserTalkURL(string username) { return(URLIndex + "?title=User_talk:" + Tools.WikiEncode(username) + "&action=purge"); }
/// <summary> /// returns URL to the given page, depends on project settings /// </summary> public static string NonPrettifiedURL(string title) { return(URLIndex + "?title=" + Tools.WikiEncode(title)); }
/// <summary> /// Edits the specified page. /// </summary> /// <param name="Article">The article to edit.</param> /// <param name="NewText">The new wikitext for the article.</param> /// <param name="Summary">The edit summary to use for this edit.</param> /// <param name="Minor">Whether or not to flag the edit as minor.</param> /// <param name="Watch">Whether article should be added to your watchlist</param> /// <returns>An EditPageRetvals object</returns> public EditPageRetvals EditPageEx(String Article, String NewText, String Summary, bool Minor, bool Watch) { HttpWebRequest wr = Variables.PrepareWebRequest(m_indexpath + "index.php?title=" + Tools.WikiEncode(Article) + "&action=submit", UserAgent); string editpagestr = GetEditPage(Article); Match m = Edittime.Match(editpagestr); string wpEdittime = m.Groups[1].Value; m = EditToken.Match(editpagestr); string wpEditkey = HttpUtility.UrlEncode(m.Groups[1].Value); wr.CookieContainer = new CookieContainer(); foreach (Cookie cook in logincookies) { wr.CookieContainer.Add(cook); } //Create poststring string poststring = string.Format( "wpSection=&wpStarttime={0}&wpEdittime={1}&wpScrolltop=&wpTextbox1={2}&wpSummary={3}&wpSave=Save%20Page&wpEditToken={4}", new[] { DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss"), wpEdittime, HttpUtility.UrlEncode(NewText), HttpUtility.UrlEncode(Summary), wpEditkey }); if (Minor) { poststring = poststring.Insert(poststring.IndexOf("wpSummary"), "wpMinoredit=1&"); } if (Watch || editpagestr.Contains("type='checkbox' name='wpWatchthis' checked='checked' accesskey=\"w\" id='wpWatchthis' />")) { poststring += "&wpWatchthis=1"; } wr.Method = "POST"; wr.ContentType = "application/x-www-form-urlencoded"; //poststring = HttpUtility.UrlEncode(poststring); byte[] bytedata = Encoding.UTF8.GetBytes(poststring); wr.ContentLength = bytedata.Length; Stream rs = wr.GetRequestStream(); rs.Write(bytedata, 0, bytedata.Length); rs.Close(); WebResponse resps = wr.GetResponse(); StreamReader sr = new StreamReader(resps.GetResponseStream()); EditPageRetvals retval = new EditPageRetvals(); retval.article = Article; retval.responsetext = sr.ReadToEnd(); Match permalinkmatch = permalinkrx.Match(retval.responsetext); //From the root directory. retval.difflink = m_indexpath.Substring(0, m_indexpath.IndexOf("/", 9)) + permalinkmatch.Groups[1].Value + "&diff=prev"; retval.difflink = retval.difflink.Replace("&", "&"); // TODO: Check our submission worked and we have a valid difflink; throw an exception if not. Also check for the sorry we could not process because of loss of session data message return(retval); }
/// <summary> /// /// </summary> /// <param name="ArticleText">The text of the article</param> /// <param name="ArticleTitle">The title of the artlce</param> /// <param name="Regexes"></param> /// <param name="includeComment"></param> /// <returns></returns> public static string ExpandTemplate(string ArticleText, string ArticleTitle, Dictionary <Regex, string> Regexes, bool includeComment) { WikiFunctions.Parse.Parsers parsers = new WikiFunctions.Parse.Parsers(); foreach (KeyValuePair <Regex, string> p in Regexes) { MatchCollection uses = p.Key.Matches(ArticleText); foreach (Match m in uses) { string call = m.Value; string expandUri = Variables.URLLong + "api.php?action=expandtemplates&format=xml&title=" + Tools.WikiEncode(ArticleTitle) + "&text=" + HttpUtility.UrlEncode(call); string result; try { string respStr = Tools.GetHTML(expandUri); Match m1 = ExpandTemplatesRegex.Match(respStr); if (!m.Success) { continue; } result = HttpUtility.HtmlDecode(m1.Groups[1].Value); } catch { continue; } bool skipArticle; result = parsers.Unicodify(result, out skipArticle); if (includeComment) { result = result + "<!-- " + call + " -->"; } ArticleText = ArticleText.Replace(call, result); } } return(ArticleText); }
public static string GetENLinkWithSimpleSkinAndLocalLanguage(string Article) { return("http://en.wikipedia.org/w/index.php?title=" + Tools.WikiEncode(Article) + "&useskin=simple&uselang=" + WikiFunctions.Variables.LangCode.ToString()); }
public static string GetUserTalkURL() { return(URLLong + "index.php?title=User_talk:" + Tools.WikiEncode(User.Name) + "&action=purge"); }
/// <summary> /// returns URL to the given page, depends on project settings /// </summary> public static string NonPrettifiedURL(string title) { return(URLLong + "index.php?title=" + Tools.WikiEncode(title)); }