Example #1
0
        public static bool TryParse(WikiPage page,
                                    string directory,
                                    PortalModule portal,
                                    out IPortalModule module)
        {
            module = null;
            Dictionary<string, string> options;
            if (!TryParseTemplate(page.Text, out options))
            {
                return false;
            }

            var categories = new List<string>();
            if (options.ContainsKey("категория"))
            {
                categories.Add(options["категория"]);
            }

            if (options.ContainsKey("категории"))
            {
                string[] separators;
                if (options["категории"].Contains("\""))
                {
                    separators = new string[] { "\"," };
                }
                else
                {
                    separators = new string[] { "," };
                }
                string[] cats = options["категории"].Split(separators,
                    StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < cats.Length; ++i)
                {
                    string cat = cats[i].Replace("\"", "").Trim();
                    if (!string.IsNullOrEmpty(cat))
                    {
                        categories.Add(cat);
                    }
                }
            }

            var categoriesToIgnore = new List<string>();
            if (options.ContainsKey("игнорировать"))
            {
                string[] separators;
                if (options["игнорировать"].Contains("\""))
                {
                    separators = new string[] { "\"," };
                }
                else
                {
                    separators = new string[] { "," };
                }
                string[] cats = options["игнорировать"].Split(separators,
                    StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < cats.Length; ++i)
                {
                    string cat = cats[i].Replace("\"", "").Trim();
                    if (!string.IsNullOrEmpty(cat))
                    {
                        categoriesToIgnore.Add(cat);
                    }
                }
            }

            var usersToIgnore = new List<string>();
            if (options.ContainsKey("игнорировать авторов"))
            {
                string[] separators;
                if (options["игнорировать авторов"].Contains("\""))
                {
                    separators = new string[] { "\"," };
                }
                else
                {
                    separators = new string[] { "," };
                }
                string[] cats = options["игнорировать авторов"].Split(separators,
                    StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < cats.Length; ++i)
                {
                    string cat = cats[i].Replace("\"", "").Trim();
                    if (!string.IsNullOrEmpty(cat))
                    {
                        usersToIgnore.Add(cat);
                    }
                }
            }

            string title = "";
            if (options.ContainsKey("страница"))
            {
                title = options["страница"];
            }

            string archive = "";
            if (options.ContainsKey("архив"))
            {
                archive = options["архив"];
            }

            string prefix = "";
            if (options.ContainsKey("префикс"))
            {
                prefix = options["префикс"];
            }

            bool markEdits = true;
            if (options.ContainsKey("помечать правки") && options["помечать правки"].ToLower() == "нет")
            {
                markEdits = false;
            }

            int ns = 0;
            if (options.ContainsKey("пространство имён"))
            {
                int.TryParse(options["пространство имён"], out ns);
            }

            string header = "";
            if (options.ContainsKey("шапка"))
            {
                header = options["шапка"].Replace("\\n", "\n");
            }

            string footer = "";
            if (options.ContainsKey("подвал"))
            {
                footer = options["подвал"].Replace("\\n", "\n");
            }

            string templates = "";
            if (options.ContainsKey("шаблоны"))
            {
                templates = options["шаблоны"].Replace("\\n", "\n");
            }

            string format = "* [[%(название)]]";
            if (options.ContainsKey("формат элемента"))
            {
                format = options["формат элемента"].Replace("{", "{{").Replace("}", "}}");
            }

            int depth = 15;
            if (options.ContainsKey("глубина"))
            {
                int.TryParse(options["глубина"], out depth);
            }

            int hours = 720;
            if (options.ContainsKey("часов"))
            {
                int.TryParse(options["часов"], out hours);
            }

            int maxItems = 20;
            if (options.ContainsKey("элементов"))
            {
                int.TryParse(options["элементов"], out maxItems);
            }

            int normalSize = 40 * 1000;
            if (options.ContainsKey("нормальная"))
            {
                int.TryParse(options["нормальная"], out normalSize);
            }

            int shortSize = 10 * 1000;
            if (options.ContainsKey("небольшая"))
            {
                int.TryParse(options["небольшая"], out shortSize);
            }

            string longColor = "#F2FFF2";
            if (options.ContainsKey("цвет крупной"))
            {
                longColor = options["цвет крупной"];
            }

            string shortColor = "#FFE8E9";
            if (options.ContainsKey("цвет небольшой"))
            {
                archive = options["цвет небольшой"];
            }

            string normalColor = "#FFFDE8";
            if (options.ContainsKey("цвет нормальной"))
            {
                archive = options["цвет нормальной"];
            }

            string delimeter = "\n";
            if (options.ContainsKey("разделитель"))
            {
                delimeter = options["разделитель"].Replace("\"", "").Replace("\\n", "\n");
            }

            if (options.ContainsKey("тип"))
            {
                string t = options["тип"].ToLower();
                if (t == "список новых статей")
                {
                    if (!options.ContainsKey("архив"))
                    {
                        module = new NewPages(portal,
                            categories,
                            categoriesToIgnore,
                            usersToIgnore,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                    }
                    else
                    {
                        module = new NewPagesWithArchive(portal,
                            categories,
                            categoriesToIgnore,
                            usersToIgnore,
                            title,
                            ns,
                            archive,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                    }
                }
                else if (t == "список наблюдения")
                {
                    module = new WatchList(portal,
                        categories[0],
                        title,
                        ns,
                        format,
                        depth);
                }
                else if (t == "отсортированный список статей, которые должны быть во всех проектах")
                {
                    module = new EncyShell(portal,
                        title,
                        shortSize,
                        normalSize,
                        shortColor,
                        normalColor,
                        longColor);
                }
                else if (t == "список новых статей с изображениями в карточке")
                {
                    module = new NewPagesWithImages(portal,
                            categories,
                            categoriesToIgnore,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                }
                else if (t == "список новых статей с изображениями")
                {
                    Regex regex = new Regex(@"\[{2}(Image|File|Файл|Изображение):(?'fileName'.+?)\|");
                    module = new NewPagesWithImages(portal,
                            categories,
                            categoriesToIgnore,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            regex,
                            markEdits);
                }
                else if (t == "списки новых статей по дням")
                {
                    module = new NewPagesWithWeeks(portal,
                            categories,
                            categoriesToIgnore,
                            title,
                            ns,
                            depth,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                }
                else if (t == "список страниц с заданными категориями и шаблонами")
                {
                    module = new CategoryTemplateIntersection(portal,
                            categories,
                            categoriesToIgnore,
                            templates,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                }
                else if (t == "список страниц с заданными категориями, шаблонами и обсуждением")
                {
                    module = new CategoryIntersectionAndTalkPages(portal,
                            categories,
                            categoriesToIgnore,
                            templates,
                            prefix,
                            title,
                            ns,
                            depth,
                            hours,
                            maxItems,
                            format,
                            delimeter,
                            header,
                            footer,
                            markEdits);
                }
            }
            return module != null;
        }