static string AddImage(string itemString, WikiImage image) { if (image == null || !PicturedRegex.IsMatch(itemString)) return itemString; return image.ToHtml() + itemString; }
static string AddImage(string itemString, WikiImage image) { if (image == null || !PicturedRegex.IsMatch(itemString)) { return(itemString); } return(image.ToHtml() + itemString); }
static WikiImage GetImage(string imageName, string sizeString, string title) { if (!imageName.StartsWith("File:")) { imageName = "File:" + imageName; } string queryUrl = "http://en.wikipedia.org/w/api.php?format=xml&action=query&prop=imageinfo&iiprop=url&titles=" + Uri.EscapeUriString(imageName); var size = ParseSizeString(sizeString); if (size.Item1.HasValue) { queryUrl += "&iiurlwidth=" + size.Item1.Value; } if (size.Item2.HasValue) { queryUrl += "&iiurlheight=" + size.Item2.Value; } string xml = CreateWebClient().DownloadString(queryUrl); var doc = XDocument.Parse(xml); var ii = doc.Root.Element("query").Element("pages").Element("page").Element("imageinfo").Element("ii"); WikiImage image; string descriptionUrl = ii.Attribute("descriptionurl").Value; if (size.Item1.HasValue || size.Item2.HasValue) { string thumbUrl = ii.Attribute("thumburl").Value; int width = int.Parse(ii.Attribute("thumbwidth").Value); int height = int.Parse(ii.Attribute("thumbheight").Value); image = new WikiImage(thumbUrl, width, height, descriptionUrl, title); } else { image = new WikiImage(ii.Attribute("url").Value, descriptionUrl, title); } return(image); }
static WikiImage GetImage(string imageName, string sizeString, string title) { if (!imageName.StartsWith("File:")) imageName = "File:" + imageName; string queryUrl = "http://en.wikipedia.org/w/api.php?format=xml&action=query&prop=imageinfo&iiprop=url&titles=" + Uri.EscapeUriString(imageName); var size = ParseSizeString(sizeString); if (size.Item1.HasValue) { queryUrl += "&iiurlwidth=" + size.Item1.Value; } if (size.Item2.HasValue) queryUrl += "&iiurlheight=" + size.Item2.Value; string xml = CreateWebClient().DownloadString(queryUrl); var doc = XDocument.Parse(xml); var ii = doc.Root.Element("query").Element("pages").Element("page").Element("imageinfo").Element("ii"); WikiImage image; string descriptionUrl = ii.Attribute("descriptionurl").Value; if (size.Item1.HasValue || size.Item2.HasValue) { string thumbUrl = ii.Attribute("thumburl").Value; int width = int.Parse(ii.Attribute("thumbwidth").Value); int height = int.Parse(ii.Attribute("thumbheight").Value); image = new WikiImage(thumbUrl, width, height, descriptionUrl, title); } else image = new WikiImage(ii.Attribute("url").Value, descriptionUrl, title); return image; }