GetHTML() публичный статический Метод

Gets the HTML from the given web address.
public static GetHTML ( string url ) : string
url string The URL of the webpage.
Результат string
Пример #1
0
        /// <summary>
        /// Gets a list of users with given parameters
        /// </summary>
        /// <param name="group">user group, e.g. "sysop"</param>
        /// <param name="from">username to start from</param>
        /// <param name="limit">limit of users returned (max. 5000) if value <= 0, maximum assumed</param>
        /// <returns>The list of the articles.</returns>
        /// <remarks>Only used by IRCM</remarks>
        public static List <Article> FromListUsers(string group, string from)
        {
            //TODO:api.php?
            int            limit = 5000;
            List <Article> list  = new List <Article>();

            try
            {
                string url = Variables.URLLong + "index.php?title=Special:Listusers&group=" + group +
                             "&username="******"&limit=" + limit.ToString();

                string search = Tools.GetHTML(url);
                search = Tools.StringBetween(search, "<!-- start content -->", "<!-- end content -->");
                search = "<div>" + search + "</div>";
                StringReader sr  = new StringReader(search);
                XmlDocument  xml = new XmlDocument();
                xml.Load(sr);

                foreach (XmlNode n in xml.GetElementsByTagName("li"))
                {
                    list.Add(new WikiFunctions.Article(Variables.Namespaces[2] + n.FirstChild.InnerText));
                }
            }
            finally
            { }
            return(list);
        }
Пример #2
0
        /// <summary>
        /// Loads the category collation information (value of wgCategoryCollation parameter) from https://noc.wikimedia.org/conf/InitialiseSettings.php.txt
        // Stores result in object cache
        /// </summary>
        private void LoadCategoryCollation()
        {
            catCollationInfo = (string)ObjectCache.Global.Get <string>("CategoryCollation:");

            // web lookup if not in cache
            if (string.IsNullOrEmpty(catCollationInfo))
            {
                catCollationInfo = Tools.GetHTML(@"https://noc.wikimedia.org/conf/InitialiseSettings.php.txt");

                // remove text before wgCategoryCollation section
                catCollationInfo = catCollationInfo.Substring(catCollationInfo.IndexOf("wgCategoryCollation"));

                // remove comments
                catCollationInfo = Regex.Replace(catCollationInfo, @" *//.*", "");

                // remove text after wgCategoryCollation section
                catCollationInfo = catCollationInfo.Substring(0, catCollationInfo.IndexOf(")"));

                // cache successful result
                if (!string.IsNullOrEmpty(catCollationInfo))
                {
                    ObjectCache.Global.Set("CategoryCollation:", catCollationInfo);
                }
            }
        }
Пример #3
0
        private static void UpdateFunc()
        {
            try
            {
                String tempPath = ".\\";
                if (File.Exists(tempPath + "AWBUpdater.exe.new"))
                {
                    File.Copy(tempPath + "AWBUpdater.exe.new", tempPath + "AWBUpdater.exe", true);
                    File.Delete(tempPath + "AWBUpdater.exe.new");
                }
                else
                {
                    //TODO:Tweak to check for optional AWB Updates
                    string text = Tools.GetHTML("http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw");

                    Match m_updversion = Regex.Match(text, @"<!-- Updater version: (.*?) -->", RegexOptions.IgnoreCase);

                    if (m_updversion.Success && m_updversion.Groups[1].Value.Length == 4)
                    {
                        FileVersionInfo versionUpdater = FileVersionInfo.GetVersionInfo(".\\AWBUpdater.exe");

                        if ((Convert.ToInt32(m_updversion.Groups[1].Value) > Convert.ToInt32(versionUpdater.FileVersion.Replace(".", ""))) && (MessageBox.Show("There is an update for the updater. Run the updater now?", "Update Updater?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
                        {
                            System.Diagnostics.Process.Start(".\\AWBUpdater.exe");
                        }
                    }
                }
            }
            catch { }
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool LoadLocalisedMagicWordAlias()
        {
            string output = Tools.GetHTML(ApiPath + "?action=query&meta=siteinfo&siprop=magicwords&format=xml");

            //TODO:Remove post 1.14
            if (output.Contains("'siprop': magicwords"))
            {
                return(true);
            }

            XmlDocument xd = new XmlDocument();

            xd.LoadXml(output);

            if (xd.GetElementsByTagName("api").Count != 1)
            {
                return(false);
            }

            magicWords.Clear();

            foreach (XmlNode xn in xd["api"]["query"]["magicwords"].GetElementsByTagName("magicword"))
            {
                List <string> alias = new List <string>();

                foreach (XmlNode xin in xn["aliases"].GetElementsByTagName("alias"))
                {
                    alias.Add(xin.InnerText);
                }

                magicWords.Add(xn.Attributes["name"].Value, alias);
            }

            return(true);
        }
Пример #5
0
        /// <summary>
        /// Checks if the current version of AWB is enabled
        /// </summary>
        public WikiStatusResult CheckEnabled()
        {
            try
            {
                string strText = Tools.GetHTML("http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw");

                if (string.IsNullOrEmpty(strText))
                {
                    Tools.WriteDebug(ToString(), "Empty version checkpage");
                    return(WikiStatusResult.Error);
                }

                if (!strText.Contains(AWBVersion + " enabled"))
                {
                    return(WikiStatusResult.OldVersion);
                }

                return(WikiStatusResult.Null);
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(ToString(), ex.Message);
                Tools.WriteDebug(ToString(), ex.StackTrace);
                return(WikiStatusResult.Error);
            }
        }
Пример #6
0
        public bool LoadNamespaces()
        {
            string output = Tools.GetHTML(m_ScriptPath + "api.php?action=query&meta=siteinfo&siprop=general|namespaces|statistics&format=xml");

            XmlDocument xd = new XmlDocument();

            xd.LoadXml(output);

            if (xd.GetElementsByTagName("api").Count != 1 || xd.GetElementsByTagName("namespaces").Count != 1)
            {
                return(false);
            }

            foreach (XmlNode xn in xd.GetElementsByTagName("ns"))
            {
                int id = int.Parse(xn.Attributes["id"].Value);

                if (id != 0)
                {
                    m_Namespaces[id] = xn.InnerText + ":";
                }
            }

            return(true);
        }
Пример #7
0
        private static void UpdateFunc()
        {
            try
            {
                string AWBDirectory = Path.GetDirectoryName(Application.ExecutablePath) + "\\";
                if (File.Exists(AWBDirectory + "AWBUpdater.exe.new"))
                {
                    File.Copy(AWBDirectory + "AWBUpdater.exe.new", AWBDirectory + "AWBUpdater.exe", true);
                    File.Delete(AWBDirectory + "AWBUpdater.exe.new");
                }
                else
                {
                    bool update = false;

                    string text = Tools.GetHTML("http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw");

                    FileVersionInfo awbVersionInfo = FileVersionInfo.GetVersionInfo(AWBDirectory + "AutoWikiBrowser.exe");
                    int             awbFileVersion = StringToVersion(awbVersionInfo.FileVersion);

                    if (text.Contains(awbVersionInfo.FileVersion + " enabled"))
                    {
                        return;
                    }

                    int awbCurrentVersion =
                        StringToVersion(Regex.Match(text, @"<!-- Current version: (.*?) -->").Groups[1].Value);
                    int awbNewestVersion =
                        StringToVersion(Regex.Match(text, @"<!-- Newest version: (.*?) -->").Groups[1].Value);
                    int updaterVersion = StringToVersion(Regex.Match(text, @"<!-- Updater version: (.*?) -->").Groups[1].Value);

                    if ((awbCurrentVersion > 4000) || (awbNewestVersion > 4000))
                    {
                        if (awbFileVersion < awbCurrentVersion)
                        {
                            update = true;
                        }
                        else if ((awbFileVersion >= awbCurrentVersion) && (awbFileVersion < awbNewestVersion) &&
                                 MessageBox.Show("There is an optional update to AutoWikiBrowser. Would you like to upgrade?", "Optional update", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            update = true;
                        }

                        if (!update && (updaterVersion > 1400) &&
                            (updaterVersion > StringToVersion(FileVersionInfo.GetVersionInfo(AWBDirectory + "AWBUpdater.exe").FileVersion)))
                        {
                            MessageBox.Show("There is an Update to the AWB updater. Updating Now", "Updater update", MessageBoxButtons.YesNo);
                            update = true;
                        }

                        if (update)
                        {
                            Process.Start(AWBDirectory + "AWBUpdater.exe");
                        }
                    }
                }
            }
            catch { }
        }
Пример #8
0
        /// <summary>
        /// Do the actual checking for enabledness etc
        /// </summary>
        private static void UpdateFunc()
        {
            try
            {
                string text =
                    Tools.GetHTML(
                        "https://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/VersionJSON&action=raw");
                GlobalVersionPage = text;

                var json = JObject.Parse(text);

                Result = AWBEnabledStatus.Disabled; // Disabled till proven enabled

                var definition      = new { version = "", releasedate = "", dotnetversion = "", dev = false };
                var enabledVersions = (from v in json["enabledversions"] select JsonConvert.DeserializeAnonymousType(v.ToString(), definition)).ToList();

                string updaterVersion = json["updaterversion"].ToString();

                FileVersionInfo awbVersionInfo =
                    FileVersionInfo.GetVersionInfo(AWBDirectory + "AutoWikiBrowser.exe");

                if (enabledVersions.Any(v => v.version == awbVersionInfo.FileVersion))
                {
                    Result = AWBEnabledStatus.Enabled;
                }

                string updaterFileVersion = FileVersionInfo.GetVersionInfo(AWBDirectory + "AWBUpdater.exe").FileVersion;

                if (Version.Parse(updaterFileVersion) < Version.Parse(updaterVersion))
                {
                    Result |= AWBEnabledStatus.UpdaterUpdate;
                }

                if ((Result & AWBEnabledStatus.Disabled) == AWBEnabledStatus.Disabled)
                {
                    // If it's disabled, updates aren't optional!
                    return;
                }

                var awbVersionParsed = Version.Parse(awbVersionInfo.FileVersion);

                var newerVersions = enabledVersions.Where(v => !v.dev && (Version.Parse(v.version) > awbVersionParsed)).Select(v => v.version);
                // Dev versions aren't optional updates
                if (newerVersions.Any())
                {
                    NewerVersions.AddRange(newerVersions.ToArray());
                    Result |= AWBEnabledStatus.OptionalUpdate;
                }
            }
            catch
            {
                Result = AWBEnabledStatus.Error;
            }
        }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="names"></param>
        /// <returns></returns>
        public Dictionary <string, string> GetMessages(params string[] names)
        {
            string output = Tools.GetHTML(ApiPath + "?format=xml&action=query&meta=allmessages&ammessages=" + string.Join("|", names));

            XmlDocument xd = new XmlDocument();

            xd.LoadXml(output);

            Dictionary <string, string> result = new Dictionary <string, string>(names.Length);

            foreach (XmlNode xn in xd.GetElementsByTagName("message"))
            {
                result[xn.Attributes["name"].Value] = xn.InnerText;
            }

            return(result);
        }
Пример #10
0
        /// <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);
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool LoadNamespaces()
        {
            string output = Tools.GetHTML(ApiPath + "?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics&format=xml");

            XmlDocument xd = new XmlDocument();

            xd.LoadXml(output);

            if (xd["api"] == null || xd["api"]["query"] == null ||
                xd["api"]["query"]["namespaces"] == null || xd["api"]["query"]["namespacealiases"] == null)
            {
                return(false);
            }

            foreach (XmlNode xn in xd["api"]["query"]["namespaces"].GetElementsByTagName("ns"))
            {
                int id = int.Parse(xn.Attributes["id"].Value);

                if (id != 0)
                {
                    namespaces[id] = xn.InnerText + ":";
                }
            }

            namespaceAliases = Variables.PrepareAliases(namespaces);

            foreach (XmlNode xn in xd["api"]["query"]["namespacealiases"].GetElementsByTagName("ns"))
            {
                int id = int.Parse(xn.Attributes["id"].Value);

                if (id != 0)
                {
                    namespaceAliases[id].Add(xn.InnerText);
                }
            }

            return(true);
        }
Пример #12
0
        /// <summary>
        /// Do the actual checking for enabledness etc
        /// </summary>
        private static void UpdateFunc()
        {
            try
            {
                string text =
                    Tools.GetHTML(
                        "https://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw");
                GlobalVersionPage = text;

                int awbCurrentVersion =
                    StringToVersion(Regex.Match(text, @"<!-- Current version: (.*?) -->").Groups[1].Value);

                int awbNewestVersion =
                    StringToVersion(Regex.Match(text, @"<!-- Newest version: (.*?) -->").Groups[1].Value);

                if ((awbCurrentVersion > 4000) || (awbNewestVersion > 4000))
                {
                    int updaterVersion =
                        StringToVersion(Regex.Match(text, @"<!-- Updater version: (.*?) -->").Groups[1].Value);

                    FileVersionInfo awbVersionInfo =
                        FileVersionInfo.GetVersionInfo(AWBDirectory + "AutoWikiBrowser.exe");
                    int awbFileVersion = StringToVersion(awbVersionInfo.FileVersion);

                    Result = AWBEnabledStatus.Disabled; //Disabled till proven enabled

                    if (awbFileVersion < awbCurrentVersion)
                    {
                        return;
                    }

                    foreach (Match m in EnabledVersions.Matches(text))
                    {
                        if (StringToVersion(m.Groups[1].Value) == awbFileVersion)
                        {
                            Result = AWBEnabledStatus.Enabled;
                            break;
                        }
                    }

                    if (Result == AWBEnabledStatus.Disabled)
                    {
                        return;
                    }

                    if ((updaterVersion > 1400) &&
                        (updaterVersion >
                         StringToVersion(FileVersionInfo.GetVersionInfo(AWBDirectory + "AWBUpdater.exe").FileVersion)))
                    {
                        Result |= AWBEnabledStatus.UpdaterUpdate;
                    }

                    if ((awbFileVersion >= awbCurrentVersion) && (awbFileVersion < awbNewestVersion))
                    {
                        Result |= AWBEnabledStatus.OptionalUpdate;
                    }
                }
            }
            catch
            {
                Result = AWBEnabledStatus.Error;
            }
        }
Пример #13
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public static UserInfo GetUserInfo()
 {
     return(new UserInfo(Tools.GetHTML(Variables.URLApi + "?action=query&meta=userinfo&uiprop=groups|rights&format=xml")));
 }