public static bool LoadWikiDataHosted(string uri) { if (uri.StartsWith("//")) { uri = MorebitsDotNet.GetProtocol() + ":" + uri; } WebClient loader = new WebClient(); loader.Headers.Add("User-Agent", MorebitsDotNet.UserAgent); loader.Encoding = Encoding.UTF8; string result; try { result = loader.DownloadString(new Uri(uri)); } catch (Exception) { MorebitsDotNet.DefaultErrorHandler(Localization.GetString("FailedToLoadHostedLocalWikiData", uri)); return(false); } LocalWikiData.LoadWikiData(result); return(true); }
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { Process.Start(MorebitsDotNet.GetProtocol() + "://en.wikipedia.org/wiki/User_talk:This,_that_and_the_other"); } catch (Exception) { MessageBox.Show(this, Localization.GetString("LinkVisitFailed"), Application.ProductName); } }
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { Process.Start(MorebitsDotNet.GetProtocol() + "://en.wikipedia.org/w/index.php?title=User_talk:This,_that_and_the_other/For_the_Common_Good&action=watch"); } catch (Exception) { MessageBox.Show(this, Localization.GetString("LinkVisitFailed"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { Process.Start(MorebitsDotNet.GetProtocol() + "://en.wikipedia.org/wiki/WP:FTCG"); } catch (Exception) { MessageBox.Show(Localization.GetString("LinkVisitFailed")); } }
private void lnkCatLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { Process.Start(MorebitsDotNet.GetProtocol() + "://" + Settings.CommonsDomain + ".org/wiki/Category:" + lnkCatLink.Text); } catch (Exception) { //ErrorHandler(Localization.GetString("LinkVisitFailed")); } }
private void hostedListLoader_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { WebClient loader = new WebClient(); loader.Headers.Add("User-Agent", MorebitsDotNet.UserAgent); try { string result = loader.DownloadString(new Uri("http://en.wikipedia.org/w/index.php?action=raw&ctype=text/css&title=User:This,%20that%20and%20the%20other/FtCG%20local%20wiki%20data%20files.css")); Invoke((MethodInvoker) delegate() { try { cboLocalDataHosted.Items.Clear(); cboLocalDataHosted.ForeColor = SystemColors.WindowText; foreach (string line in result.Split('\n')) { string[] parts = line.Split('|'); if (parts.Length == 2) { HostedLocalWikiDataEntry item = new HostedLocalWikiDataEntry(parts[0], parts[1]); cboLocalDataHosted.Items.Add(item); if (Settings.LocalWikiDataHosted.StartsWith(item.displayName + "|")) { cboLocalDataHosted.SelectedItem = item; } } } if (cboLocalDataHosted.Items.Count > 0 && cboLocalDataHosted.SelectedIndex == -1) { cboLocalDataHosted.SelectedIndex = 0; } } catch (Exception) { MorebitsDotNet.DefaultErrorHandler(Localization.GetString("FailedToLoadHostedLocalWikiDataList")); } }); } catch (Exception ex) { if (!(ex is InvalidOperationException)) { MorebitsDotNet.DefaultErrorHandler(Localization.GetString("FailedToLoadHostedLocalWikiDataList")); } } }
public void SetContent(string html) { string text = "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" /><link rel=\"stylesheet\" " + "href=\"http://bits.wikimedia.org/commons.wikimedia.org/load.php?debug=false&lang=en&modules=filepage%7Cmediawiki.legacy.shared%7Cmediawiki.skinning.interface%7Cskins.vector.styles&only=styles&skin=vector&*\" />" + "<link rel=\"stylesheet\" " + "href=\"http://bits.wikimedia.org/commons.wikimedia.org/load.php?debug=false&lang=en&modules=site&only=styles&skin=vector&*\" />" + "<base href=\"http://" + MorebitsDotNet.GetDomain(Wiki.Commons) + "/wiki/x\" target=\"_blank\" />" + "<style>body { font-size: 0.8em; background-color: white; color: black; padding: 0.8em; } .editsection, .mw-editsection { display: none; }</style>" + html; if (webBrowser1.Document == null) { webBrowser1.DocumentText = text; } else { webBrowser1.Document.Write(text); } }
private void cboCatName_TextChanged(object sender, EventArgs e) { if (cboCatName.Text.Length == 0 || textUpdateTarget != cboCatName.Text) { return; } // needed to avoid overzealous mouse pointer hiding on Windows PlatformSpecific.FakeMouseMovement(); DateTime now = DateTime.Now; latestDate = now; // use same queries as HotCat (via GET), to take advantage of server-side caching MorebitsDotNet.GetApi(Wiki.Commons, "format=json&action=opensearch&namespace=14&limit=30&search=Category:" + Uri.EscapeDataString(cboCatName.Text), now, delegate(string json, object date) { if (latestDate > ((DateTime)date)) { return; } string[] results; // we take advantage of the fact that [ is not a legal character in wiki page titles // To be honest, this whole thing is crass, but I don't want to bring in a full JSON // parser just for this string resultsPart = json.Substring(json.IndexOf('[', 2) + 1); // ...and taking advantage of the fact that ] is not legal either! if (resultsPart.IndexOf(']') > 0) { // we have results, so trim off the trailing junk and parse out character escapes resultsPart = resultsPart.Substring(1, resultsPart.IndexOf(']') - 2); resultsPart.Replace("\\\\", "#"); int location; string charValue; while ((location = resultsPart.IndexOf("\\u")) != -1) { charValue = resultsPart.Substring(location + 2, 4); resultsPart = resultsPart.Remove(location, 6).Insert(location, Char.ConvertFromUtf32(int.Parse(charValue, NumberStyles.AllowHexSpecifier))); } resultsPart = resultsPart.Replace("\\\"", "\"").Replace("#", "\\"); results = resultsPart.Split(new string[] { "\",\"" }, StringSplitOptions.None); } else { // no results results = new string[0]; } //MessageBox.Show(json + "\n\n====================\n\n" + string.Join("\n", results)); ParentCoolCat.AddCategoryExistenceRange(results, true); if (ParentCoolCat.DoesCategoryExist(cboCatName.Text) != true) { // does it exist? Go looking MorebitsDotNet.GetApi(Wiki.Commons, "format=json&action=query&titles=Category:" + Uri.EscapeDataString(cboCatName.Text), cboCatName.Text, delegate(string innerJson, object catName) { // more crassness bool exists = innerJson.IndexOf("\"-1\":") == -1; SetCategoryExistenceIcon(exists); ParentCoolCat.AddCategoryExistence((string)catName, exists); FinishCategoryAutoComplete(results, exists ? (string)catName : null); } ); } else { SetCategoryExistenceIcon(true); FinishCategoryAutoComplete(results, null); } } ); }