Ejemplo n.º 1
0
        /// <summary>
        /// Sets different language variables, such as namespaces. Default is english Wikipedia
        /// </summary>
        /// <param name="langCode">The language code, default is en</param>
        /// <param name="projectName">The project name default is Wikipedia</param>
        /// <param name="customProject">Script path of a custom project or ""</param>
        /// <param name="protocol"></param>
        public static void SetProject(string langCode, ProjectEnum projectName, string customProject, string protocol)
        {
            TryLoadingAgainAfterLogin = false;
            Namespaces.Clear();
            CancelBackgroundRequests();
            UnderscoredTitles.Clear();
            WikiRegexes.TemplateRedirects.Clear();
            bool typoReloadNeeded = (LangCode != langCode || Project != projectName || customProject != CustomProject);

            Project       = projectName;
            LangCode      = langCode;
            CustomProject = customProject;
            Protocol      = protocol;

            RefreshProxy();

            URLEnd = "/w/";

            Stub = "[^{}|]*?[Ss]tub";

            MonthNames = ENLangMonthNames;

            SectStub      = @"\{\{[Ss]ect";
            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);

            TypoSummaryTag = "typos fixed: ";
            AWBDefaultSummaryTag();
            mSummaryTag          = "using";
            NotificationsEnabled = true;

            if (IsCustomProject)
            {
                LangCode = "en";
                var uri = new Uri(Protocol + customProject);
                URLEnd        = uri.AbsolutePath;
                URL           = protocol + uri.Host;
                CustomProject = customProject;
            }
            else
            {
                URL = "https://" + LangCode + "." + Project + ".org";
            }

            // HACK:
            switch (projectName)
            {
            case ProjectEnum.wikipedia:
            case ProjectEnum.wikinews:
            case ProjectEnum.wikisource:
            case ProjectEnum.wikibooks:
            case ProjectEnum.wikiquote:
            case ProjectEnum.wiktionary:
            case ProjectEnum.wikiversity:
                //If not set the following will be used:
                //mSummaryTag="using";
                //WPAWB = "[[Project:Wikipedia:AutoWikiBrowser|AWB]]";
                SetLanguageSpecificValues(langCode, projectName);
                break;

            case ProjectEnum.commons:
                URL      = "https://commons.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.meta:
                URL      = "https://meta.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.mediawiki:
                URL      = "https://www.mediawiki.org";
                LangCode = "en";
                break;

            case ProjectEnum.incubator:
                URL      = "https://incubator.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.species:
                URL      = "https://species.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.wikia:
                URL    = "http://" + customProject + ".wikia.com";
                URLEnd = "/";
                break;

            case ProjectEnum.custom:
                break;
            }

            //refresh once more in case project settings were reset due to error with loading
            RefreshProxy();

            //HACK:HACK:HACK:HACK:HACK:
            if (MainForm != null && MainForm.TheSession != null)
            {
                try
                {
                    if (!MainForm.TheSession.UpdateProject(false))
                    {
                        LangCode = "en";
                        Project  = ProjectEnum.wikipedia;
                        SetToEnglish();
                    }
                }
                catch (ReadApiDeniedException)
                {
                    TryLoadingAgainAfterLogin = true;
                    ReloadProjectSettings     = new ProjectHoldArea
                    {
                        projectName   = projectName,
                        customProject = customProject,
                        langCode      = langCode,
                        protocol      = Protocol
                    };
                    return;
                }
            }

            RegenerateRegexes();

            RetfPath = Namespaces[Namespace.Project] + "AutoWikiBrowser/Typos";

            if (typoReloadNeeded && MainForm != null)
            {
                MainForm.LoadTypos(true);
            }

            foreach (string s in Namespaces.Values)
            {
                System.Diagnostics.Trace.Assert(s.EndsWith(":"), "Internal error: namespace does not end with ':'.",
                                                "Please contact a developer.");
            }
            System.Diagnostics.Trace.Assert(!Namespaces.ContainsKey(0), "Internal error: key exists for namespace 0.",
                                            "Please contact a developer.");

            if (projectName.Equals(ProjectEnum.wiktionary))
            {
                CapitalizeFirstLetter = false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets different language variables, such as namespaces. Default is english Wikipedia
        /// </summary>
        /// <param name="langCode">The language code, default is en</param>
        /// <param name="projectName">The project name default is Wikipedia</param>
        /// <param name="customProject">Script path of a custom project or ""</param>
        /// <param name="protocol"></param>
        public static void SetProject(string langCode, ProjectEnum projectName, string customProject, string protocol)
        {
            TryLoadingAgainAfterLogin = false;
            Namespaces.Clear();
            CancelBackgroundRequests();
            UnderscoredTitles.Clear();
            WikiRegexes.TemplateRedirects.Clear();

            Project       = projectName;
            LangCode      = langCode;
            CustomProject = customProject;
            Protocol      = protocol;

            RefreshProxy();

            URLEnd = "/w/";

            Stub = "[^{}|]*?[Ss]tub";

            MonthNames = ENLangMonthNames;

            SectStub      = @"\{\{[Ss]ect";
            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);

            TypoSummaryTag = "typos fixed: ";
            AWBDefaultSummaryTag();
            mSummaryTag          = " using ";
            NotificationsEnabled = true;

            if (IsCustomProject)
            {
                LangCode = "en";
                var uri = new Uri(Protocol + customProject);
                URLEnd        = uri.AbsolutePath;
                URL           = protocol + uri.Host;
                CustomProject = customProject;
            }
            else
            {
                URL = "https://" + LangCode + "." + Project + ".org";
            }

            // HACK:
            switch (projectName)
            {
            case ProjectEnum.wikipedia:
            case ProjectEnum.wikinews:
            case ProjectEnum.wikisource:
            case ProjectEnum.wikibooks:
            case ProjectEnum.wikiquote:
            case ProjectEnum.wiktionary:
            case ProjectEnum.wikiversity:
                //If not set the following will be used:
                //mSummaryTag="using";
                //WPAWB = "[[Project:Wikipedia:AutoWikiBrowser|AWB]]";
                switch (langCode)
                {
                case "en":
                    if (projectName == ProjectEnum.wikipedia)
                    {
                        SetToEnglish();
                    }
                    TypoSummaryTag = @"[[WP:AWB/T|typos fixed]]: ";
                    break;

                case "ar":
                    mSummaryTag    = " ";
                    WPAWB          = "باستخدام [[Project:أوب|أوب]]";
                    Stub           = @"(?:[^{}|]*?[Ss]tub|بذرة|بذور[^{}]*?)";
                    TypoSummaryTag = ".الأخطاء المصححة: ";
                    break;

                case "arz":
                    mSummaryTag    = " ";
                    WPAWB          = "عن طريق [[Project:AWB|اوب]]";
                    Stub           = @"(?:[^{}|]*?[Ss]tub|تقاوى|بذرة[^{}]*?)";
                    TypoSummaryTag = ".الأخطاء المصححة: ";
                    break;

                case "bg":
                    mSummaryTag = " редактирано с ";
                    WPAWB       = "AWB";
                    break;

                case "ca":
                    mSummaryTag = " ";
                    WPAWB       = "[[Viquipèdia:AutoWikiBrowser|AWB]]";
                    break;

                case "cs":
                    mSummaryTag = " za použití ";
                    WPAWB       = "[[Wikipedie:AutoWikiBrowser|AWB]]";
                    Stub        = @"[^{}|]*?([Pp]ahýl)";
                    break;

                case "cy":
                    Stub = @"[^{}|]*?([Ss]tub|[Εe]ginyn[^{}]*?)";
                    break;

                case "da":
                    mSummaryTag = " ved brug af ";
                    WPAWB       = "[[en:WP:AWB|AWB]]";
                    break;

                case "de":
                    mSummaryTag    = " mit ";
                    TypoSummaryTag = ", Schreibweise:";
                    break;

                case "el":
                    mSummaryTag   = " με τη χρήση ";
                    WPAWB         = "[[Βικιπαίδεια:AutoWikiBrowser|AWB]]";
                    Stub          = @"[^{}|]*?([Ss]tub|[Εε]πέκταση)";
                    SectStub      = @"\{\{θέματος";
                    SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
                    break;

                case "eo":
                    mSummaryTag    = " per ";
                    WPAWB          = "[[Vikipedio:AutoWikiBrowser|AWB]]";
                    TypoSummaryTag = ", Skribmaniero:";
                    break;

                case "he":
                    mSummaryTag = " באמצעות ";
                    WPAWB       = "[[ויקיפדיה:AutoWikiBrowser|AWB]]";
                    break;

                case "hi":
                    mSummaryTag = " ";
                    WPAWB       = "[[विकिपीडिया:ऑटोविकिब्राउज़र|AWB]] के साथ";
                    break;

                case "hu":
                    mSummaryTag = " ";
                    WPAWB       = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                    break;

                case "hy":
                    mSummaryTag = " oգտվելով ";
                    WPAWB       = "[[Վիքիպեդիա:ԱվտոՎիքիԲրաուզեր|ԱՎԲ]]";
                    break;

                case "ku":
                    mSummaryTag = " ";
                    WPAWB       = "[[Wîkîpediya:AutoWikiBrowser|AWB]]";
                    break;

                case "ms":
                    mSummaryTag = "menggunakan";
                    break;

                case "nl":
                    mSummaryTag = " met ";
                    break;

                case "pl":
                    mSummaryTag   = " przy użyciu ";
                    SectStub      = @"\{\{[Ss]ek";
                    SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
                    break;

                case "pt":
                    mSummaryTag = " utilizando ";
                    WPAWB       = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                    break;

                case "ru":
                    mSummaryTag = " с помощью ";
                    Stub        = "[^{}]*?(?:[Ss]tub|[Зз]аготовка)";
                    break;

                case "sk":
                    mSummaryTag = " ";
                    WPAWB       = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                    break;

                case "sl":
                    mSummaryTag = " ";
                    WPAWB       = "[[Wikipedija:AutoWikiBrowser|AWB]]";
                    Stub        = "(?:[^{}]*?[Ss]tub|[Šš]krbina[^{}]*?)";
                    break;

                case "sv":
                    mSummaryTag    = " med ";
                    TypoSummaryTag = ", rättningar:";
                    Stub           = @"(?:[^{}]*?[Ss]tub|[^{}]+?stub\-[^{}]+)";
                    break;

                case "tr":
                    mSummaryTag    = " ";
                    WPAWB          = "[[Vikipedi:AWB|AWB]] ile ";
                    TypoSummaryTag = " yazış şekli:";
                    break;

                case "uk":
                    Stub        = ".*?(?:[Ss]tub|[Дд]оробити)";
                    mSummaryTag = " за допомогою ";
                    WPAWB       = "[[Вікіпедія:AutoWikiBrowser|AWB]]";
                    break;

                case "zh":
                    mSummaryTag = "由";
                    WPAWB       = "[[维基百科:自动维基浏览器|自动维基浏览器]]协助";
                    break;

                case "zh-classical":
                    mSummaryTag = "藉";
                    WPAWB       = "[[维基百科:自动维基浏览器|自動維基瀏覽器]]之助";
                    break;

                case "zh-yue":
                    mSummaryTag = "由";
                    WPAWB       = "[[维基百科:自动维基浏览器|自動維基瀏覽器]]協助";
                    break;

                    // case "xx:
                    // strsummarytag = " ";
                    // strWPAWB = "";
                    // break;
                }
                break;

            case ProjectEnum.commons:
                URL      = "https://commons.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.meta:
                URL      = "https://meta.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.mediawiki:
                URL      = "https://www.mediawiki.org";
                LangCode = "en";
                break;

            case ProjectEnum.incubator:
                URL      = "https://incubator.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.species:
                URL      = "https://species.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.wikia:
                URL    = "http://" + customProject + ".wikia.com";
                URLEnd = "/";
                break;

            case ProjectEnum.custom:
                break;
            }

            //refresh once more in case project settings were reset due to error with loading
            RefreshProxy();

            //HACK:HACK:HACK:HACK:HACK:
            if (MainForm != null && MainForm.TheSession != null)
            {
                try
                {
                    if (!MainForm.TheSession.UpdateProject(false))
                    {
                        LangCode = "en";
                        Project  = ProjectEnum.wikipedia;
                        SetToEnglish();
                    }
                }
                catch (ReadApiDeniedException)
                {
                    TryLoadingAgainAfterLogin = true;
                    ReloadProjectSettings     = new ProjectHoldArea
                    {
                        projectName   = projectName,
                        customProject = customProject,
                        langCode      = langCode,
                        protocol      = Protocol
                    };
                    return;
                }
            }

            RegenerateRegexes();

            RetfPath = Namespaces[Namespace.Project] + "AutoWikiBrowser/Typos";

            foreach (string s in Namespaces.Values)
            {
                System.Diagnostics.Trace.Assert(s.EndsWith(":"), "Internal error: namespace does not end with ':'.",
                                                "Please contact a developer.");
            }
            System.Diagnostics.Trace.Assert(!Namespaces.ContainsKey(0), "Internal error: key exists for namespace 0.",
                                            "Please contact a developer.");

            if (projectName.Equals(ProjectEnum.wiktionary))
            {
                CapitalizeFirstLetter = false;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets different language variables, such as namespaces. Default is english Wikipedia
        /// </summary>
        /// <param name="langCode">The language code, default is en</param>
        /// <param name="projectName">The project name default is Wikipedia</param>
        /// <param name="customProject">Script path of a custom project or ""</param>
        /// <param name="protocol"></param>
        public static void SetProject(string langCode, ProjectEnum projectName, string customProject, string protocol)
        {
            TryLoadingAgainAfterLogin = false;
            Namespaces.Clear();
            CancelBackgroundRequests();
            UnderscoredTitles.Clear();
            WikiRegexes.TemplateRedirects.Clear();

            Project = projectName;
            LangCode = langCode;
            CustomProject = customProject;
            Protocol = protocol;

            RefreshProxy();

            URLEnd = "/w/";

            Stub = "[^{}|]*?[Ss]tub";

            MonthNames = ENLangMonthNames;

            SectStub = @"\{\{[Ss]ect";
            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);

            TypoSummaryTag = "typos fixed: ";
            AWBDefaultSummaryTag();
            mSummaryTag = " using ";

            if (IsCustomProject)
            {
                LangCode = "en";
                var uri = new Uri(Protocol + customProject);
                URLEnd = uri.AbsolutePath;
                URL = protocol + uri.Host;
                CustomProject = customProject;
            }
            else
            {
                URL = "https://" + LangCode + "." + Project + ".org";
            }

            // HACK:
            switch (projectName)
            {
                case ProjectEnum.wikipedia:
                case ProjectEnum.wikinews:
                case ProjectEnum.wikisource:
                case ProjectEnum.wikibooks:
                case ProjectEnum.wikiquote:
                case ProjectEnum.wiktionary:
                case ProjectEnum.wikiversity:
                    //If not set the following will be used:
                    //mSummaryTag="using";
                    //WPAWB = "[[Project:Wikipedia:AutoWikiBrowser|AWB]]";
                    switch (langCode)
                    {
                        case "en":
                            if (projectName == ProjectEnum.wikipedia)
                                SetToEnglish();
                            TypoSummaryTag = @"[[WP:AWB/T|typos fixed]]: ";
                            break;

                        case "ar":
                            mSummaryTag = " ";
                            WPAWB = "باستخدام [[Project:أوب|أوب]]";
                            Stub = @"(?:[^{}|]*?[Ss]tub|(بذرة|بذور)[^{}]*?)";
                            TypoSummaryTag = ".الأخطاء المصححة: ";
                            break;

                        case "bg":
                            mSummaryTag = " редактирано с ";
                            WPAWB = "AWB";
                            break;

                        case "ca":
                            mSummaryTag = " ";
                            WPAWB = "[[Viquipèdia:AutoWikiBrowser|AWB]]";
                            break;

                        case "cs":
                            mSummaryTag = " za použití ";
                            WPAWB = "[[Wikipedie:AutoWikiBrowser|AWB]]";
                            //Stub = @"[^{}|]*?([Pp]ahýl)";
                            break;
                            
                        case "da":
                            mSummaryTag = " ved brug af ";
                            WPAWB = "[[en:Wikipedia:AutoWikiBrowser|AWB]]";
                            break;

                        case "de":
                            mSummaryTag = " mit ";
                            TypoSummaryTag = ", Schreibweise:";
                            break;

                        case "el":
                            mSummaryTag = " με τη χρήση ";
                            WPAWB = "[[Βικιπαίδεια:AutoWikiBrowser|AWB]]";
                            //Stub = @"[^{}|]*?([Ss]tub|[Εε]πέκταση)";
                            SectStub = @"\{\{θέματος";
                            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
                            break;

                        case "eo":
                            mSummaryTag = " per ";
                            WPAWB = "[[Vikipedio:AutoWikiBrowser|AWB]]";
                            TypoSummaryTag = ", Skribmaniero:";
                            break;

                        case "he":
                            mSummaryTag = " באמצעות ";
                            WPAWB = "[[ויקיפדיה:AutoWikiBrowser|AWB]]";
                            break;

                        case "hi":
                            mSummaryTag = " ";
                            WPAWB = "[[विकिपीडिया:ऑटोविकिब्राउज़र|AWB]] के साथ";
                            break;

                        case "hu":
                            mSummaryTag = " ";
                            WPAWB = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                            break;

                        case "hy":
                            mSummaryTag = " oգտվելով ";
                            WPAWB = "[[Վիքիպեդիա:ԱվտոՎիքիԲրաուզեր|ԱՎԲ]]";
                            break;

                           case "ku":
                            mSummaryTag = " ";
                            WPAWB = "[[Wîkîpediya:AutoWikiBrowser|AWB]]";
                            break;

                        case "ms":
                            mSummaryTag = "menggunakan";
                            break;

                        case "nl":
                            mSummaryTag = " met ";
                            break;
                            
                        case "pl":
                            mSummaryTag = " przy użyciu ";
                            SectStub = @"\{\{[Ss]ek";
                            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
                            break;

                        case "pt":
                            mSummaryTag = " utilizando ";
                            WPAWB = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                            break;

                        case "ru":
                            mSummaryTag = " с помощью ";
                            Stub = "[^{}]*?(?:[Ss]tub|[Зз]аготовка)";
                            break;

                        case "sk":
                            mSummaryTag = " ";
                            WPAWB = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                            break;

                        case "sl":
                            mSummaryTag = " ";
                            WPAWB = "[[Wikipedija:AutoWikiBrowser|AWB]]";
                            Stub = "(?:[^{}]*?[Ss]tub|[Šš]krbina[^{}]*?)";
                            break;

                        case "sv":
                            mSummaryTag = " med ";
                            TypoSummaryTag = ", rättningar:";
                            break;

                        case "tr":
                            mSummaryTag = " ";
                            WPAWB = "[[Vikipedi:AWB|AWB]] ile ";
                            TypoSummaryTag = " yazış şekli:";
                            break;

                        case "uk":
                            Stub = ".*?(?:[Ss]tub|[Дд]оробити)";
                            mSummaryTag = " за допомогою ";
                            WPAWB = "[[Вікіпедія:AutoWikiBrowser|AWB]]";
                            break;

                        case "zh":
                            mSummaryTag = "由";
                            WPAWB = "[[维基百科:自动维基浏览器|自动维基浏览器]]协助";
                            break;

                        case "zh-classical":
                            mSummaryTag = "藉";
                            WPAWB = "[[维基百科:自动维基浏览器|自動維基瀏覽器]]之助";
                            break;

                        case "zh-yue":
                            mSummaryTag = "由";
                            WPAWB = "[[维基百科:自动维基浏览器|自動維基瀏覽器]]協助";
                            break;

                            // case "xx:
                            // strsummarytag = " ";
                            // strWPAWB = "";
                            // break;
                    }
                    break;
                case ProjectEnum.commons:
                    URL = "https://commons.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.meta:
                    URL = "https://meta.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.mediawiki:
                    URL = "https://www.mediawiki.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.incubator:
                    URL = "https://incubator.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.species:
                    URL = "https://species.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.wikia:
                    URL = "http://" + customProject + ".wikia.com";
                    URLEnd = "/";
                    break;
                case ProjectEnum.custom:
                    break;
            }

            //refresh once more in case project settings were reset due to error with loading
            RefreshProxy();

            //HACK:HACK:HACK:HACK:HACK:
            if (MainForm != null && MainForm.TheSession != null)
            {
                try
                {
                    if (!MainForm.TheSession.UpdateProject(false))
                    {
                        LangCode = "en";
                        Project = ProjectEnum.wikipedia;
                        SetToEnglish();
                    }
                }
                catch (ReadApiDeniedException)
                {
                    TryLoadingAgainAfterLogin = true;
                    ReloadProjectSettings = new ProjectHoldArea
                                                {
                                                    projectName = projectName,
                                                    customProject = customProject,
                                                    langCode = langCode,
                                                    protocol = Protocol
                                                };
                    return;
                }
            }

            RegenerateRegexes();

            RetfPath = Namespaces[Namespace.Project] + "AutoWikiBrowser/Typos";

            foreach (string s in Namespaces.Values)
            {
                System.Diagnostics.Trace.Assert(s.EndsWith(":"), "Internal error: namespace does not end with ':'.",
                                                "Please contact a developer.");
            }
            System.Diagnostics.Trace.Assert(!Namespaces.ContainsKey(0), "Internal error: key exists for namespace 0.",
                                            "Please contact a developer.");

            if (projectName.Equals(ProjectEnum.wiktionary))
                CapitalizeFirstLetter = false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets different language variables, such as namespaces. Default is english Wikipedia
        /// </summary>
        /// <param name="langCode">The language code, default is en</param>
        /// <param name="projectName">The project name default is Wikipedia</param>
        /// <param name="customProject">Script path of a custom project or ""</param>
        /// <param name="protocol"></param>
        public static void SetProject(string langCode, ProjectEnum projectName, string customProject, string protocol)
        {
            TryLoadingAgainAfterLogin = false;
            Namespaces.Clear();
            CancelBackgroundRequests();
            UnderscoredTitles.Clear();
            WikiRegexes.TemplateRedirects.Clear();

            Project = projectName;
            LangCode = langCode;
            CustomProject = customProject;
            Protocol = protocol;

            RefreshProxy();

            URLEnd = "/w/";

            Stub = "[^{}|]*?[Ss]tub";

            MonthNames = ENLangMonthNames;

            SectStub = @"\{\{[Ss]ect";
            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);

            TypoSummaryTag = "typos fixed: ";
            AWBDefaultSummaryTag();
            mSummaryTag = "using";
            NotificationsEnabled = true;

            if (IsCustomProject)
            {
                LangCode = "en";
                var uri = new Uri(Protocol + customProject);
                URLEnd = uri.AbsolutePath;
                URL = protocol + uri.Host;
                CustomProject = customProject;
            }
            else
            {
                URL = "https://" + LangCode + "." + Project + ".org";
            }

            // HACK:
            switch (projectName)
            {
                case ProjectEnum.wikipedia:
                case ProjectEnum.wikinews:
                case ProjectEnum.wikisource:
                case ProjectEnum.wikibooks:
                case ProjectEnum.wikiquote:
                case ProjectEnum.wiktionary:
                case ProjectEnum.wikiversity:
                    //If not set the following will be used:
                    //mSummaryTag="using";
                    //WPAWB = "[[Project:Wikipedia:AutoWikiBrowser|AWB]]";
                    SetLanguageSpecificValues(langCode, projectName);
                    break;
                case ProjectEnum.commons:
                    URL = "https://commons.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.meta:
                    URL = "https://meta.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.mediawiki:
                    URL = "https://www.mediawiki.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.incubator:
                    URL = "https://incubator.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.species:
                    URL = "https://species.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.wikia:
                    URL = "http://" + customProject + ".wikia.com";
                    URLEnd = "/";
                    break;
                case ProjectEnum.custom:
                    break;
            }

            //refresh once more in case project settings were reset due to error with loading
            RefreshProxy();

            //HACK:HACK:HACK:HACK:HACK:
            if (MainForm != null && MainForm.TheSession != null)
            {
                try
                {
                    if (!MainForm.TheSession.UpdateProject(false))
                    {
                        LangCode = "en";
                        Project = ProjectEnum.wikipedia;
                        SetToEnglish();
                    }
                }
                catch (ReadApiDeniedException)
                {
                    TryLoadingAgainAfterLogin = true;
                    ReloadProjectSettings = new ProjectHoldArea
                                                {
                                                    projectName = projectName,
                                                    customProject = customProject,
                                                    langCode = langCode,
                                                    protocol = Protocol
                                                };
                    return;
                }
            }

            RegenerateRegexes();

            RetfPath = Namespaces[Namespace.Project] + "AutoWikiBrowser/Typos";

            if(MainForm != null)
                MainForm.LoadTypos(true);

            foreach (string s in Namespaces.Values)
            {
                System.Diagnostics.Trace.Assert(s.EndsWith(":"), "Internal error: namespace does not end with ':'.",
                                                "Please contact a developer.");
            }
            System.Diagnostics.Trace.Assert(!Namespaces.ContainsKey(0), "Internal error: key exists for namespace 0.",
                                            "Please contact a developer.");

            if (projectName.Equals(ProjectEnum.wiktionary))
                CapitalizeFirstLetter = false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sets different language variables, such as namespaces. Default is english Wikipedia
        /// </summary>
        /// <param name="langCode">The language code, default is en</param>
        /// <param name="projectName">The project name default is Wikipedia</param>
        /// <param name="customProject">Script path of a custom project or ""</param>
        /// <param name="usingSecure"></param>
        public static void SetProject(string langCode, ProjectEnum projectName, string customProject, bool usingSecure)
        {
            TryLoadingAgainAfterLogin = false;
            Namespaces.Clear();
            CancelBackgroundRequests();
            UnderscoredTitles.Clear();
            WikiRegexes.TemplateRedirects.Clear();

            Project       = projectName;
            LangCode      = langCode;
            CustomProject = customProject;
            UsingSecure   = usingSecure;

            RefreshProxy();

            URLEnd = "/w/";

            AWBDefaultSummaryTag();
            Stub = "[^{}|]*?[Ss]tub";

            MonthNames = ENLangMonthNames;

            SectStub      = @"\{\{[Ss]ect";
            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);

            if (IsCustomProject)
            {
                LangCode = "en";
                int x = customProject.IndexOf('/');

                if (x > 0)
                {
                    URLEnd        = customProject.Substring(x, customProject.Length - x);
                    CustomProject = customProject.Substring(0, x);
                }

                URL = "http://" + CustomProject;
            }
            else
            {
                URL       = "http://" + LangCode + "." + Project + ".org";
                URLSecure = "https://secure.wikimedia.org/";
                if (IsWikimediaMonolingualProject)
                {
                    URLSecure += "wikipedia/" + Project;
                }
                else
                {
                    URLSecure += Project + "/" + LangCode; //https://secure.wikimedia.org/wikipedia/en
                }
            }

            // HACK:
            switch (projectName)
            {
            case ProjectEnum.wikipedia:
            case ProjectEnum.wikinews:
            case ProjectEnum.wikisource:
            case ProjectEnum.wikibooks:
            case ProjectEnum.wikiquote:
            case ProjectEnum.wiktionary:
            case ProjectEnum.wikiversity:
                switch (langCode)
                {
                case "en":
                    if (projectName == ProjectEnum.wikipedia)
                    {
                        SetToEnglish();
                    }
                    break;

                case "ar":
                    mSummaryTag    = " ";
                    WPAWB          = "باستخدام [[ويكيبيديا:أوب|الأوتوويكي براوزر]]";
                    TypoSummaryTag = ".الأخطاء المصححة: ";
                    break;

                case "bg":
                    mSummaryTag = " редактирано с ";
                    WPAWB       = "AWB";
                    break;

                case "ca":
                    mSummaryTag = " ";
                    WPAWB       = "[[Viquipèdia:AutoWikiBrowser|AWB]]";
                    break;

                case "da":
                    mSummaryTag = " ved brug af ";
                    WPAWB       = "[[en:Wikipedia:AutoWikiBrowser|AWB]]";
                    break;

                case "de":
                    mSummaryTag    = " mit ";
                    TypoSummaryTag = ", Schreibweise:";
                    break;

                case "el":
                    mSummaryTag = " με τη χρήση ";
                    WPAWB       = "[[Βικιπαίδεια:AutoWikiBrowser|AWB]]";
                    break;

                case "eo":
                    mSummaryTag = " ";
                    WPAWB       = "[[Vikipedio:AutoWikiBrowser|AWB]]";
                    break;

                case "he":
                    mSummaryTag = " באמצעות ";
                    break;

                case "hu":
                    mSummaryTag = " ";
                    WPAWB       = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                    break;

                case "ku":
                    mSummaryTag = " ";
                    WPAWB       = "[[Wîkîpediya:AutoWikiBrowser|AWB]]";
                    break;

                case "ms":
                    mSummaryTag = "menggunakan";
                    break;

                case "nl":
                    mSummaryTag = " met ";
                    break;

                case "pl":
                    SectStub      = @"\{\{[Ss]ek";
                    SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
                    break;

                case "pt":
                    mSummaryTag = " utilizando ";
                    break;

                case "ru":
                    mSummaryTag = " с помощью ";
                    Stub        = "[^{}]*?(?:[Ss]tub|[Зз]аготовка)";
                    break;

                case "sk":
                    mSummaryTag = " ";
                    WPAWB       = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                    break;

                case "sl":
                    mSummaryTag = " ";
                    WPAWB       = "[[Wikipedija:AutoWikiBrowser|AWB]]";
                    Stub        = "(?:[^{}]*?[Ss]tub|[Šš]krbina[^{}]*?)";
                    break;

                case "uk":
                    Stub        = ".*?(?:[Ss]tub|[Дд]оробити)";
                    mSummaryTag = " за допомогою ";
                    WPAWB       = "[[Вікіпедія:AutoWikiBrowser|AWB]]";
                    break;

                // case "xx:
                // strsummarytag = " ";
                // strWPAWB = "";
                // break;

                default:
                    break;
                }
                break;

            case ProjectEnum.commons:
                URL      = "http://commons.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.meta:
                URL      = "http://meta.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.mediawiki:
                URL      = "http://www.mediawiki.org";
                LangCode = "en";
                break;

            case ProjectEnum.species:
                URL      = "http://species.wikimedia.org";
                LangCode = "en";
                break;

            case ProjectEnum.wikia:
                URL    = "http://" + customProject + ".wikia.com";
                URLEnd = "/";
                break;

            case ProjectEnum.custom:
                //URLEnd = "";
                break;
            }

            //refresh once more in case project settings were reset due to error with loading
            RefreshProxy();

            //HACK:HACK:HACK:HACK:HACK:
            if (MainForm != null && MainForm.TheSession != null)
            {
                try
                {
                    if (!MainForm.TheSession.UpdateProject(false))
                    {
                        LangCode = "en";
                        Project  = ProjectEnum.wikipedia;
                        SetToEnglish();
                    }
                }
                catch (ReadApiDeniedException)
                {
                    TryLoadingAgainAfterLogin = true;
                    ReloadProjectSettings     = new ProjectHoldArea
                    {
                        projectName   = projectName,
                        customProject = customProject,
                        langCode      = langCode,
                        usingSecure   = usingSecure
                    };
                    return;
                }
            }

            RegenerateRegexes();

            RetfPath = Namespaces[Namespace.Project] + "AutoWikiBrowser/Typos";

            foreach (string s in Namespaces.Values)
            {
                System.Diagnostics.Trace.Assert(s.EndsWith(":"), "Internal error: namespace does not end with ':'.",
                                                "Please contact a developer.");
            }
            System.Diagnostics.Trace.Assert(!Namespaces.ContainsKey(0), "Internal error: key exists for namespace 0.",
                                            "Please contact a developer.");

            if (projectName.Equals(ProjectEnum.wiktionary))
            {
                CapitalizeFirstLetter = false;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sets different language variables, such as namespaces. Default is english Wikipedia
        /// </summary>
        /// <param name="langCode">The language code, default is en</param>
        /// <param name="projectName">The project name default is Wikipedia</param>
        /// <param name="customProject">Script path of a custom project or ""</param>
        /// <param name="usingSecure"></param>
        public static void SetProject(string langCode, ProjectEnum projectName, string customProject, bool usingSecure)
        {
            TryLoadingAgainAfterLogin = false;
            Namespaces.Clear();
            CancelBackgroundRequests();
            UnderscoredTitles.Clear();
            WikiRegexes.TemplateRedirects.Clear();

            Project = projectName;
            LangCode = langCode;
            CustomProject = customProject;
            UsingSecure = usingSecure;

            RefreshProxy();

            URLEnd = "/w/";

            AWBDefaultSummaryTag();
            Stub = "[^{}|]*?[Ss]tub";

            MonthNames = ENLangMonthNames;

            SectStub = @"\{\{[Ss]ect";
            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);

            if (IsCustomProject)
            {
                LangCode = "en";
                int x = customProject.IndexOf('/');

                if (x > 0)
                {
                    URLEnd = customProject.Substring(x, customProject.Length - x);
                    CustomProject = customProject.Substring(0, x);
                }

                URL = "http://" + CustomProject;
            }
            else
            {
                URL = "http://" + LangCode + "." + Project + ".org";
                URLSecure = "https://secure.wikimedia.org/";
                if (IsWikimediaMonolingualProject)
                {
                    URLSecure += "wikipedia/" + Project;
                }
                else
                {                   	
                    URLSecure += Project + "/" + LangCode; //https://secure.wikimedia.org/wikipedia/en
                }
             }

            // HACK:
            switch (projectName)
            {
                case ProjectEnum.wikipedia:
                case ProjectEnum.wikinews:
                case ProjectEnum.wikisource:
                case ProjectEnum.wikibooks:
                case ProjectEnum.wikiquote:
                case ProjectEnum.wiktionary:
                case ProjectEnum.wikiversity:
                    switch (langCode)
                    {
                        case "en":
                            if (projectName == ProjectEnum.wikipedia)
                                SetToEnglish();
                            break;

                        case "ar":
                            mSummaryTag = " ";
                            WPAWB = "باستخدام [[ويكيبيديا:أوب|الأوتوويكي براوزر]]";
                            TypoSummaryTag = ".الأخطاء المصححة: ";
                            break;

                        case "bg":
                            mSummaryTag = " редактирано с ";
                            WPAWB = "AWB";
                            break;

                        case "ca":
                            mSummaryTag = " ";
                            WPAWB = "[[Viquipèdia:AutoWikiBrowser|AWB]]";
                            break;

                        case "da":
                            mSummaryTag = " ved brug af ";
                            WPAWB = "[[en:Wikipedia:AutoWikiBrowser|AWB]]";
                            break;

                        case "de":
                            mSummaryTag = " mit ";
                            TypoSummaryTag = ", Schreibweise:";
                            break;
						
						case "el":
							mSummaryTag = " με τη χρήση ";
                            WPAWB = "[[Βικιπαίδεια:AutoWikiBrowser|AWB]]";
							break;

                        case "eo":
                            mSummaryTag = " ";
                            WPAWB = "[[Vikipedio:AutoWikiBrowser|AWB]]";
                            break;

                        case "hu":
                            mSummaryTag = " ";
                            WPAWB = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                            break;

                        case "ku":
                            mSummaryTag = " ";
                            WPAWB = "[[Wîkîpediya:AutoWikiBrowser|AWB]]";
                            break;
                            
                        case "ms":
                            mSummaryTag = "menggunakan";
                            break;

                        case "nl":
                            mSummaryTag = " met ";
                            break;

                        case "pl":
                            SectStub = @"\{\{[Ss]ek";
                            SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
                            break;

                        case "pt":
                            mSummaryTag = " utilizando ";
                            break;

                        case "ru":
                            mSummaryTag = " с помощью ";
                            Stub = "[^{}]*?(?:[Ss]tub|[Зз]аготовка)";
                            break;

                        case "sk":
                            mSummaryTag = " ";
                            WPAWB = "[[Wikipédia:AutoWikiBrowser|AWB]]";
                            break;

                        case "sl":
                            mSummaryTag = " ";
                            WPAWB = "[[Wikipedija:AutoWikiBrowser|AWB]]";
                            Stub = "(?:[^{}]*?[Ss]tub|[Šš]krbina[^{}]*?)";
                            break;

                        case "uk":
                            Stub = ".*?(?:[Ss]tub|[Дд]оробити)";
                            mSummaryTag = " за допомогою ";
                            WPAWB = "[[Вікіпедія:AutoWikiBrowser|AWB]]";
                            break;

                        // case "xx:
                        // strsummarytag = " ";
                        // strWPAWB = "";
                        // break;

                        default:
                            break;
                    }
                    break;
                case ProjectEnum.commons:
                    URL = "http://commons.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.meta:
                    URL = "http://meta.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.mediawiki:
                    URL = "http://www.mediawiki.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.species:
                    URL = "http://species.wikimedia.org";
                    LangCode = "en";
                    break;
                case ProjectEnum.wikia:
                    URL = "http://" + customProject + ".wikia.com";
                    URLEnd = "/";
                    break;
                case ProjectEnum.custom:
                    //URLEnd = "";
                    break;
            }

            //refresh once more in case project settings were reset due to error with loading
            RefreshProxy();

            //HACK:HACK:HACK:HACK:HACK:
            if (MainForm != null && MainForm.TheSession != null)
            {
                try
                {
                    if (!MainForm.TheSession.UpdateProject(false))
                    {
                        LangCode = "en";
                        Project = ProjectEnum.wikipedia;
                        SetToEnglish();
                    }
                }
                catch (ReadApiDeniedException)
                {
                    TryLoadingAgainAfterLogin = true;
                    ReloadProjectSettings = new ProjectHoldArea
                                                {
                                                    projectName = projectName,
                                                    customProject = customProject,
                                                    langCode = langCode,
                                                    usingSecure = usingSecure
                                                };
                    return;
                }
            }

            RegenerateRegexes();

            RetfPath = Namespaces[Namespace.Project] + "AutoWikiBrowser/Typos";

            foreach (string s in Namespaces.Values)
            {
                System.Diagnostics.Trace.Assert(s.EndsWith(":"), "Internal error: namespace does not end with ':'.",
                                                "Please contact a developer.");
            }
            System.Diagnostics.Trace.Assert(!Namespaces.ContainsKey(0), "Internal error: key exists for namespace 0.",
                                            "Please contact a developer.");
            
            if(projectName.Equals(ProjectEnum.wiktionary))
              CapitalizeFirstLetter = false;
        }