VerifyNamespaces() public static method

Checks if given namespaces are sufficient for AWB to function properly and that their format is expected.
public static VerifyNamespaces ( string>.Dictionary namespaces ) : bool
namespaces string>.Dictionary namespaces to verify
return bool
Example #1
0
        public static SiteInfo CreateOrLoad(IApiEdit editor)
        {
            SiteInfo si = (SiteInfo)ObjectCache.Global.Get <SiteInfo>(Key(editor.URL));

            if (si != null &&
                Namespace.VerifyNamespaces(si.Namespaces))
            {
                return(si);
            }

            si = new SiteInfo(editor);
            ObjectCache.Global[Key(editor.URL)] = si;

            return(si);
        }
Example #2
0
        /// <summary>
        /// Loads SiteInfo from local cache or API call, processes data returned
        /// </summary>
        /// <returns></returns>
        public bool LoadSiteInfo()
        {
            if (!LoadFromCache())
            {
                LoadFromNetwork();
            }

            XmlDocument xd = new XmlDocument();

            xd.LoadXml(siteinfoOutput);

            var api = xd["api"];

            if (api == null)
            {
                return(false);
            }

            var query = api["query"];

            if (query == null)
            {
                return(false);
            }

            var general = query["general"];

            if (general == null)
            {
                return(false);
            }

            ArticleUrl            = Host + general.GetAttribute("articlepath");
            Language              = general.GetAttribute("lang");
            IsRightToLeft         = general.HasAttribute("rtl");
            CapitalizeFirstLetter = general.GetAttribute("case") == "first-letter";
            MediaWikiVersion      = general.GetAttribute("generator").Replace("MediaWiki ", "");

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

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

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

            if (!Namespace.VerifyNamespaces(namespaces))
            {
                throw new Exception("Error loading namespaces from " + ApiPath);
            }

            namespaceAliases = Variables.PrepareAliases(namespaces);

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

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

            if (query["magicwords"] == null)
            {
                return(false);
            }

            foreach (XmlNode xn in 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);
            }

            // CategoryCollation: Unicode sorting in category sort keys
            LoadCategoryCollation();
            UcaCategoryCollation = (from Match m in UcacatCollation.Matches(catCollationInfo) select m.Groups[1].Value).ToList();

            return(true);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool LoadSiteInfo()
        {
            string output = Editor.HttpGet(ApiPath + "?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics|magicwords&format=xml");

            XmlDocument xd = new XmlDocument();

            xd.LoadXml(output);

            var api = xd["api"];

            if (api == null)
            {
                return(false);
            }

            var query = api["query"];

            if (query == null)
            {
                return(false);
            }

            var general = query["general"];

            if (general == null)
            {
                return(false);
            }

            ArticleUrl            = Host + general.GetAttribute("articlepath");
            Language              = general.GetAttribute("lang");
            IsRightToLeft         = general.HasAttribute("rtl");
            CapitalizeFirstLetter = general.GetAttribute("case") == "first-letter";

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

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

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

            if (!Namespace.VerifyNamespaces(namespaces))
            {
                throw new Exception("Error loading namespaces from " + ApiPath);
            }

            namespaceAliases = Variables.PrepareAliases(namespaces);

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

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

            if (query["magicwords"] == null)
            {
                return(false);
            }

            foreach (XmlNode xn in 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);
        }