상속: IXmlSerializable
예제 #1
0
        public static SiteInfo CreateOrLoad(IApiEdit editor)
        {
            SiteInfo si = (SiteInfo)ObjectCache.Global.Get<SiteInfo>(Key(editor.URL));
            if (si != null) return si;

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

            return si;
        }
예제 #2
0
        public static SiteInfo CreateOrLoad(string scriptPath, bool php5Ext)
        {
            SiteInfo si = (SiteInfo)ObjectCache.Global.Get<SiteInfo>(Key(scriptPath, php5Ext));
            if (si != null) return si;

            si = new SiteInfo(scriptPath, php5Ext);
            ObjectCache.Global[Key(scriptPath, php5Ext)] = si;

            return si;
        }
예제 #3
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;
        }
예제 #4
0
        /// <summary>
        /// Loads namespaces
        /// </summary>
        public static void LoadProjectOptions()
        {
            string[] months = (string[])ENLangMonthNames.Clone();

            try
            {
                SiteInfo si = new SiteInfo(URLLong, PHP5);

                for (int i = 0; i < months.Length; i++) months[i] += "-gen";
                Dictionary<string, string> messages = si.GetMessages(months);

                if (messages.Count == 12)
                {
                    for (int i = 0; i < months.Length; i++)
                    {
                        months[i] = messages[months[i]];
                    }
                    MonthNames = months;
                }

                Namespaces = si.Namespaces;
                NamespaceAliases = si.NamespaceAliases;
                MagicWords = si.MagicWords;
            }
            catch
            {
                MessageBox.Show("An error occured while connecting to the server or loading project information from it. " +
                        "Please make sure that your internet connection works and such combination of project/language exist." +
                        "\r\nEnter the URL in the format \"en.wikipedia.org/w/\" (including path where index.php and api.php reside).",
                        "Error connecting to wiki", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SetDefaults();
                return;
            }
        }
예제 #5
0
        /// <summary>
        /// Loads namespaces
        /// </summary>
        public static void LoadProjectOptions()
        {
            string[] months = (string[])ENLangMonthNames.Clone();

            try
            {
                SiteInfo si = new SiteInfo(URLLong);

                for (int i = 0; i < months.Length; i++) months[i] += "-gen";
                Dictionary<string, string> messages = si.GetMessages(months);

                if (messages.Count == 12)
                {
                    for (int i = 0; i < months.Length; i++)
                    {
                        months[i] = messages[months[i]];
                    }
                    MonthNames = months;
                }

                Namespaces = si.Namespaces;
            }
            catch
            {
                if (MessageBox.Show(@"An error occured while loading project information from the server.
Do you want to use default settings?", "Error loading namespaces", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Namespaces = enLangNamespaces;
                    MonthNames = (string[])ENLangMonthNames.Clone();
                    return;
                }
                else if (!string.IsNullOrEmpty(CustomProject))
                {
                    MessageBox.Show("An error occured while loading project information from the server. " +
                        "Please make sure that your internet connection works and such combination of project/language exist." +
                        "\r\nEnter the URL of the index.php file in the format \"en.wikipedia.org/w/\"",
                        "Error loading namespaces", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SetDefaults();
                }
                MessageBox.Show("Defaulting to the English Wikipedia settings.", "Project options",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
예제 #6
0
        /// <summary>
        /// Loads namespaces
        /// </summary>
        private void LoadProjectOptions()
        {
            string[] months = (string[])Variables.ENLangMonthNames.Clone();

            try
            {
                Site = new SiteInfo(Editor.SynchronousEditor);

                for (int i = 0; i < months.Length; i++) months[i] += "-gen";
                Dictionary<string, string> messages = Site.GetMessages(months);

                if (messages.Count == 12)
                {
                    for (int i = 0; i < months.Length; i++)
                    {
                        months[i] = messages[months[i]];
                    }
                    Variables.MonthNames = months;
                }

                Variables.Namespaces = Site.Namespaces;
                Variables.NamespaceAliases = Site.NamespaceAliases;
                Variables.MagicWords = Site.MagicWords;
            }
            catch (Exception ex)
            {
                //TODO:Better error handling

                string message = ex is WikiUrlException && ex.InnerException != null 
                    ? ex.InnerException.Message
                    : ex.Message;

                MessageBox.Show("An error occured while connecting to the server or loading project information from it. " +
                        "Please make sure that your internet connection works and such combination of project/language exist." +
                        "\r\nEnter the URL in the format \"en.wikipedia.org/w/\" (including path where index.php and api.php reside)." +
                        "\r\nError description: " + message,
                        "Error connecting to wiki", MessageBoxButtons.OK, MessageBoxIcon.Error);

                throw;
            }
        }
예제 #7
0
        /// <summary>
        /// Checks log in status, registered and version.
        /// </summary>
        private WikiStatusResult UpdateWikiStatus()
        {
            try
            {
                IsBot = false;

                Site = new SiteInfo(Editor.SynchronousEditor);

                //load version check page if no status set
                if (Updater.Result == Updater.AWBEnabledStatus.None)
                    Updater.CheckForUpdates();

                //load check page
                string url;
                if (Variables.IsWikia)
                    url = "http://community.wikia.com/index.php?title=Wikia:AutoWikiBrowser/CheckPage&action=raw";
                else
                    url = Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=raw";

                string checkPageText = Editor.SynchronousEditor.HttpGet(url);

                Variables.RTL = Site.IsRightToLeft;
                Variables.CapitalizeFirstLetter = Site.CapitalizeFirstLetter;

                if (Variables.IsCustomProject || Variables.IsWikia)
                {
                    Variables.LangCode = Site.Language;
                }

                string typoPostfix = "", localCheckPage = "";
                if (Variables.IsWikia)
                {
                    typoPostfix = "-" + Variables.LangCode;

                    try
                    {
                        //load a local checkpage on Wikia
                        //it cannot be used to approve users, but it could be used to set some settings
                        //such as underscores and pages to ignore

                        localCheckPage = Editor.SynchronousEditor.Open("Project:AutoWikiBrowser/CheckPage", true);

                        // selectively add content of the local checkpage to the global one
                        checkPageText += Message.Match(localCheckPage).Value
                                         /*+ Underscores.Match(s).Value*/
                                         + WikiRegexes.NoGeneralFixes.Match(localCheckPage);
                    }
                    catch
                    {
                    }
                }

                Updater.WaitForCompletion();
                Updater.AWBEnabledStatus versionStatus = Updater.Result;
                VersionCheckPage = Updater.GlobalVersionPage;

                //see if this version is enabled
                if (versionStatus == Updater.AWBEnabledStatus.Disabled)
                    return WikiStatusResult.OldVersion;

                CheckPageText = checkPageText;

                if (!User.IsLoggedIn)
                    return WikiStatusResult.NotLoggedIn;

                if (!User.HasRight("writeapi"))
                    return WikiStatusResult.NoRights;

                // TODO: assess the impact on servers later
                Editor.Maxlag = /*User.IsBot ? 5 : 20*/ -1;

                // check if username is globally blacklisted
                foreach (Match badName in BadName.Matches(Updater.GlobalVersionPage))
                {
                    if (!string.IsNullOrEmpty(badName.Groups[1].Value.Trim()) &&
                        !string.IsNullOrEmpty(User.Name) &&
                        Regex.IsMatch(User.Name, badName.Groups[1].Value.Trim(),
                                      RegexOptions.IgnoreCase | RegexOptions.Multiline))
                        return WikiStatusResult.NotRegistered;
                }

                //see if there is a message
                Match messages = Message.Match(checkPageText);
                if (messages.Success && messages.Groups[1].Value.Trim().Length > 0)
                {
                    MessageBox.Show(messages.Groups[1].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                //see if there is a version-specific message
                messages = VersionMessage.Match(checkPageText);
                if (messages.Success && messages.Groups[1].Value.Trim().Length > 0 &&
                    messages.Groups[1].Value == AWBVersion)
                {
                    MessageBox.Show(messages.Groups[2].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                bool foundTypoLink = false;
                if (Variables.IsWikia && !string.IsNullOrEmpty(localCheckPage))
                {
                    foundTypoLink = HasTypoLink(localCheckPage, typoPostfix);
                }

                if (!foundTypoLink)
                {
                    HasTypoLink(checkPageText, typoPostfix);
                }

                List<string> us = new List<string>();
                foreach (Match underscore in Underscores.Matches(checkPageText))
                {
                    if (underscore.Success && underscore.Groups[1].Value.Trim().Length > 0)
                        us.Add(underscore.Groups[1].Value.Trim());
                }
                if (us.Count > 0) Variables.LoadUnderscores(us.ToArray());

                //don't require approval if checkpage does not exist.
                if (checkPageText.Length < 1)
                {
                    IsBot = true;
                    return WikiStatusResult.Registered;
                }

                if (checkPageText.Contains("<!--All users enabled-->"))
                {
                    //see if all users enabled
                    IsBot = true;
                    return WikiStatusResult.Registered;
                }

                //see if we are allowed to use this software
                checkPageText = Tools.StringBetween(checkPageText, "<!--enabledusersbegins-->",
                                                    "<!--enabledusersends-->");

                string strBotUsers = Tools.StringBetween(checkPageText, "<!--enabledbots-->", "<!--enabledbotsends-->");
                Regex username = new Regex(@"^\*\s*" + Tools.CaseInsensitive(Regex.Escape(User.Name))
                                           + @"\s*$", RegexOptions.Multiline);

                if (IsSysop && Variables.Project != ProjectEnum.wikia)
                {
                    IsBot = username.IsMatch(strBotUsers);
                    return WikiStatusResult.Registered;
                }

                if (username.IsMatch(checkPageText))
                {
                    //enable bot mode
                    IsBot = username.IsMatch(strBotUsers);

                    return WikiStatusResult.Registered;
                }

                if (Variables.Project != ProjectEnum.custom)
                {
                    string globalUsers = Tools.StringBetween(VersionCheckPage, "<!--globalusers-->",
                                                             "<!--globalusersend-->");

                    if (username.IsMatch(globalUsers))
                        return WikiStatusResult.Registered;
                }
                return WikiStatusResult.NotRegistered;
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(ToString(), ex.Message);
                Tools.WriteDebug(ToString(), ex.StackTrace);
                IsBot = false;
                return WikiStatusResult.Error;
            }
        }
예제 #8
0
 public void Add(SiteInfo si)
 {
     m_Cache.Add(si);
 }
예제 #9
0
        /// <summary>
        /// Checks log in status, registered and version.
        /// </summary>
        private WikiStatusResult UpdateWikiStatus()
        {
            try
            {
                string typoPostfix = "";

                IsBot = false;

                //TODO: login?
                Site = new SiteInfo(Editor);

                //load version check page
                BackgroundRequest versionRequest = new BackgroundRequest();
                versionRequest.GetHTML(
                    "http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw");

                //load check page
                string url;
                if (Variables.IsWikia)
                {
                    url = "http://www.wikia.com/wiki/index.php?title=Wikia:AutoWikiBrowser/CheckPage&action=edit";
                }
                else if ((Variables.Project == ProjectEnum.wikipedia) && (Variables.LangCode == LangCodeEnum.ar))
                {
                    url = "http://ar.wikipedia.org/w/index.php?title=%D9%88%D9%8A%D9%83%D9%8A%D8%A8%D9%8A%D8%AF%D9%8A%D8%A7:%D8%A7%D9%84%D8%A3%D9%88%D8%AA%D9%88%D9%88%D9%8A%D9%83%D9%8A_%D8%A8%D8%B1%D8%A7%D9%88%D8%B2%D8%B1/%D9%85%D8%B3%D9%85%D9%88%D8%AD&action=edit";
                }
                else
                {
                    url = Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=edit";
                }

                string strText = Editor.SynchronousEditor.HttpGet(url);

                Variables.RTL = Site.IsRightToLeft;

                if (Variables.IsCustomProject || Variables.IsWikia)
                {
                    try
                    {
                        Variables.LangCode =
                            Variables.ParseLanguage(Site.Language);
                    }
                    catch
                    {
                        // use English if language not recognized
                        Variables.LangCode = LangCodeEnum.en;
                    }
                }

                if (Variables.IsWikia)
                {
                    //this object loads a local checkpage on Wikia
                    //it cannot be used to approve users, but it could be used to set some settings
                    //such as underscores and pages to ignore
                    AsyncApiEdit editWikia = (AsyncApiEdit)Editor.Clone();
                    SiteInfo     wikiaInfo = new SiteInfo();
                    string       s         = editWikia.SynchronousEditor.Open("Project:AutoWikiBrowser/CheckPage");

                    typoPostfix = "-" + Variables.LangCode;

                    // selectively add content of the local checkpage to the global one
                    strText += Message.Match(s).Value
                               /*+ Underscores.Match(s).Value*/
                               + WikiRegexes.NoGeneralFixes.Match(s);
                }

                versionRequest.Wait();
                string strVersionPage = (string)versionRequest.Result;

                //see if this version is enabled
                if (!strVersionPage.Contains(AWBVersion + " enabled"))
                {
                    return(WikiStatusResult.OldVersion);
                }

                //TODO:
                // else
                //if (!WeAskedAboutUpdate && strVersionPage.Contains(AWBVersion + " enabled (old)"))
                //{
                //    WeAskedAboutUpdate = true;
                //    if (
                //        MessageBox.Show(
                //            "This version has been superceeded by a new version.  You may continue to use this version or update to the newest version.\r\n\r\nWould you like to automatically upgrade to the newest version?",
                //            "Upgrade?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //    {
                //        Match version = Regex.Match(strVersionPage, @"<!-- Current version: (.*?) -->");
                //        if (version.Success && version.Groups[1].Value.Length == 4)
                //        {
                //            System.Diagnostics.Process.Start(Path.GetDirectoryName(Application.ExecutablePath) +
                //                                             "\\AWBUpdater.exe");
                //        }
                //        else if (
                //            MessageBox.Show("Error automatically updating AWB. Load the download page instead?",
                //                            "Load download page?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //        {
                //            Tools.OpenURLInBrowser("http://sourceforge.net/project/showfiles.php?group_id=158332");
                //        }
                //    }
                //}

                CheckPageText = strText;

                // don't run GetInLogInStatus if we don't have the username, we sometimes get 2 error message boxes otherwise
                bool loggedIn = Editor.User.IsRegistered;

                if (!loggedIn)
                {
                    return(WikiStatusResult.NotLoggedIn);
                }

                // check if username is globally blacklisted
                foreach (
                    Match m3 in Regex.Matches(strVersionPage, @"badname:\s*(.*)\s*(:?|#.*)$", RegexOptions.IgnoreCase))
                {
                    if (!string.IsNullOrEmpty(m3.Groups[1].Value.Trim()) &&
                        !string.IsNullOrEmpty(Editor.User.Name) &&
                        Regex.IsMatch(Editor.User.Name, m3.Groups[1].Value.Trim(),
                                      RegexOptions.IgnoreCase | RegexOptions.Multiline))
                    {
                        return(WikiStatusResult.NotRegistered);
                    }
                }

                //see if there is a message
                Match m = Message.Match(strText);
                if (m.Success && m.Groups[1].Value.Trim().Length > 0)
                {
                    MessageBox.Show(m.Groups[1].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                //see if there is a version-specific message
                m = VersionMessage.Match(strText);
                if (m.Success && m.Groups[1].Value.Trim().Length > 0 && m.Groups[1].Value == AWBVersion)
                {
                    MessageBox.Show(m.Groups[2].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                m = Regex.Match(strText, "<!--[Tt]ypos" + typoPostfix + ":(.*?)-->");
                if (m.Success && m.Groups[1].Value.Trim().Length > 0)
                {
                    Variables.RetfPath = m.Groups[1].Value.Trim();
                }

                List <string> us = new List <string>();
                foreach (Match m1 in Underscores.Matches(strText))
                {
                    if (m1.Success && m1.Groups[1].Value.Trim().Length > 0)
                    {
                        us.Add(m1.Groups[1].Value.Trim());
                    }
                }
                if (us.Count > 0)
                {
                    Variables.LoadUnderscores(us.ToArray());
                }

                //don't require approval if checkpage does not exist.
                if (strText.Length < 1)
                {
                    IsBot = true;
                    return(WikiStatusResult.Registered);
                }

                if (strText.Contains("<!--All users enabled-->"))
                {
                    //see if all users enabled
                    IsBot = true;
                    return(WikiStatusResult.Registered);
                }

                //see if we are allowed to use this softare
                strText = Tools.StringBetween(strText, "<!--enabledusersbegins-->", "<!--enabledusersends-->");

                string strBotUsers = Tools.StringBetween(strText, "<!--enabledbots-->", "<!--enabledbotsends-->");
                Regex  username    = new Regex(@"^\*\s*" + Tools.CaseInsensitive(Editor.User.Name)
                                               + @"\s*$", RegexOptions.Multiline);

                if (IsSysop)
                {
                    IsBot = username.IsMatch(strBotUsers);
                    return(WikiStatusResult.Registered);
                }

                if (!string.IsNullOrEmpty(Editor.User.Name) && username.IsMatch(strText))
                {
                    //enable bot mode
                    IsBot = username.IsMatch(strBotUsers);

                    return(WikiStatusResult.Registered);
                }

                return(WikiStatusResult.NotRegistered);
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(ToString(), ex.Message);
                Tools.WriteDebug(ToString(), ex.StackTrace);
                IsBot = false;
                return(WikiStatusResult.Error);
            }
        }
예제 #10
0
        /// <summary>
        /// Checks log in status, registered and version.
        /// </summary>
        private WikiStatusResult UpdateWikiStatus()
        {
            try
            {
                string typoPostfix = "";

                IsBot = false;

                //TODO: login?
                Site = new SiteInfo(Editor);

                //load version check page
                BackgroundRequest versionRequest = new BackgroundRequest();
                versionRequest.GetHTML(
                    "http://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage/Version&action=raw");

                //load check page
                string url;
                if (Variables.IsWikia)
                    url = "http://www.wikia.com/wiki/index.php?title=Wikia:AutoWikiBrowser/CheckPage&action=edit";
                else if ((Variables.Project == ProjectEnum.wikipedia) && (Variables.LangCode == LangCodeEnum.ar))
                    url = "http://ar.wikipedia.org/w/index.php?title=%D9%88%D9%8A%D9%83%D9%8A%D8%A8%D9%8A%D8%AF%D9%8A%D8%A7:%D8%A7%D9%84%D8%A3%D9%88%D8%AA%D9%88%D9%88%D9%8A%D9%83%D9%8A_%D8%A8%D8%B1%D8%A7%D9%88%D8%B2%D8%B1/%D9%85%D8%B3%D9%85%D9%88%D8%AD&action=edit";
                else
                    url = Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=edit";

                string strText = Editor.SynchronousEditor.HttpGet(url);

                Variables.RTL = Site.IsRightToLeft;

                if (Variables.IsCustomProject || Variables.IsWikia)
                {
                    try
                    {
                        Variables.LangCode =
                            Variables.ParseLanguage(Site.Language);
                    }
                    catch
                    {
                        // use English if language not recognized
                        Variables.LangCode = LangCodeEnum.en;
                    }
                }

                if (Variables.IsWikia)
                {
                    //this object loads a local checkpage on Wikia
                    //it cannot be used to approve users, but it could be used to set some settings
                    //such as underscores and pages to ignore
                    AsyncApiEdit editWikia = (AsyncApiEdit)Editor.Clone();
                    SiteInfo wikiaInfo = new SiteInfo();
                    string s = editWikia.SynchronousEditor.Open("Project:AutoWikiBrowser/CheckPage");

                    typoPostfix = "-" + Variables.LangCode;

                    // selectively add content of the local checkpage to the global one
                    strText += Message.Match(s).Value
                        /*+ Underscores.Match(s).Value*/
                               + WikiRegexes.NoGeneralFixes.Match(s);

                }

                versionRequest.Wait();
                string strVersionPage = (string)versionRequest.Result;

                //see if this version is enabled
                if (!strVersionPage.Contains(AWBVersion + " enabled"))
                    return WikiStatusResult.OldVersion;

                //TODO:
                // else
                //if (!WeAskedAboutUpdate && strVersionPage.Contains(AWBVersion + " enabled (old)"))
                //{
                //    WeAskedAboutUpdate = true;
                //    if (
                //        MessageBox.Show(
                //            "This version has been superceeded by a new version.  You may continue to use this version or update to the newest version.\r\n\r\nWould you like to automatically upgrade to the newest version?",
                //            "Upgrade?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //    {
                //        Match version = Regex.Match(strVersionPage, @"<!-- Current version: (.*?) -->");
                //        if (version.Success && version.Groups[1].Value.Length == 4)
                //        {
                //            System.Diagnostics.Process.Start(Path.GetDirectoryName(Application.ExecutablePath) +
                //                                             "\\AWBUpdater.exe");
                //        }
                //        else if (
                //            MessageBox.Show("Error automatically updating AWB. Load the download page instead?",
                //                            "Load download page?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                //        {
                //            Tools.OpenURLInBrowser("http://sourceforge.net/project/showfiles.php?group_id=158332");
                //        }
                //    }
                //}

                CheckPageText = strText;

                // don't run GetInLogInStatus if we don't have the username, we sometimes get 2 error message boxes otherwise
                bool loggedIn = Editor.User.IsRegistered;

                if (!loggedIn)
                    return WikiStatusResult.NotLoggedIn;

                // check if username is globally blacklisted
                foreach (
                    Match m3 in Regex.Matches(strVersionPage, @"badname:\s*(.*)\s*(:?|#.*)$", RegexOptions.IgnoreCase))
                {
                    if (!string.IsNullOrEmpty(m3.Groups[1].Value.Trim()) &&
                        !string.IsNullOrEmpty(Editor.User.Name) &&
                        Regex.IsMatch(Editor.User.Name, m3.Groups[1].Value.Trim(),
                                      RegexOptions.IgnoreCase | RegexOptions.Multiline))
                        return WikiStatusResult.NotRegistered;
                }

                //see if there is a message
                Match m = Message.Match(strText);
                if (m.Success && m.Groups[1].Value.Trim().Length > 0)
                    MessageBox.Show(m.Groups[1].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);

                //see if there is a version-specific message
                m = VersionMessage.Match(strText);
                if (m.Success && m.Groups[1].Value.Trim().Length > 0 && m.Groups[1].Value == AWBVersion)
                    MessageBox.Show(m.Groups[2].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);

                m = Regex.Match(strText, "<!--[Tt]ypos" + typoPostfix + ":(.*?)-->");
                if (m.Success && m.Groups[1].Value.Trim().Length > 0)
                    Variables.RetfPath = m.Groups[1].Value.Trim();

                List<string> us = new List<string>();
                foreach (Match m1 in Underscores.Matches(strText))
                {
                    if (m1.Success && m1.Groups[1].Value.Trim().Length > 0)
                        us.Add(m1.Groups[1].Value.Trim());
                }
                if (us.Count > 0) Variables.LoadUnderscores(us.ToArray());

                //don't require approval if checkpage does not exist.
                if (strText.Length < 1)
                {
                    IsBot = true;
                    return WikiStatusResult.Registered;
                }

                if (strText.Contains("<!--All users enabled-->"))
                {
                    //see if all users enabled
                    IsBot = true;
                    return WikiStatusResult.Registered;
                }

                //see if we are allowed to use this softare
                strText = Tools.StringBetween(strText, "<!--enabledusersbegins-->", "<!--enabledusersends-->");

                string strBotUsers = Tools.StringBetween(strText, "<!--enabledbots-->", "<!--enabledbotsends-->");
                Regex username = new Regex(@"^\*\s*" + Tools.CaseInsensitive(Editor.User.Name)
                                           + @"\s*$", RegexOptions.Multiline);

                if (IsSysop)
                {
                    IsBot = username.IsMatch(strBotUsers);
                    return WikiStatusResult.Registered;
                }

                if (!string.IsNullOrEmpty(Editor.User.Name) && username.IsMatch(strText))
                {
                    //enable bot mode
                    IsBot = username.IsMatch(strBotUsers);

                    return WikiStatusResult.Registered;
                }

                return WikiStatusResult.NotRegistered;
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(ToString(), ex.Message);
                Tools.WriteDebug(ToString(), ex.StackTrace);
                IsBot = false;
                return WikiStatusResult.Error;
            }
        }
예제 #11
0
        /// <summary>
        /// Loads namespaces
        /// </summary>
        private void LoadProjectOptions()
        {
            string[] months = (string[])Variables.ENLangMonthNames.Clone();

            try
            {
                Site = new SiteInfo(Editor.SynchronousEditor);

                for (int i = 0; i < months.Length; i++)
                {
                    months[i] += "-gen";
                }

                // get localized month names if not en-wiki
                if (!Variables.IsWikipediaEN)
                {
                    Dictionary <string, string> messages = Site.GetMessages(months);

                    if (messages.Count == 12)
                    {
                        for (int i = 0; i < months.Length; i++)
                        {
                            months[i] = messages[months[i]];
                        }
                        Variables.MonthNames = months;
                    }
                }

                Variables.Namespaces       = Site.Namespaces;
                Variables.NamespaceAliases = Site.NamespaceAliases;
                Variables.MagicWords       = Site.MagicWords;
            }
            catch (ReadApiDeniedException)
            {
                throw;
            }
            catch (WebException ex)
            {
                string message = "";

                if (ex.InnerException != null)
                {
                    if (ex.InnerException is AuthenticationException)
                    {
                        if (message.Equals(""))
                        {
                            message = ex.Message;
                        }
                        else
                        {
                            message += " " + ex.Message;
                        }
                    }

                    if (message.Equals(""))
                    {
                        message = ex.InnerException.Message;
                    }
                    else
                    {
                        message += " " + ex.InnerException.Message;
                    }
                }
                else
                {
                    var resp = (HttpWebResponse)ex.Response;
                    if (resp == null)
                    {
                        throw;
                    }

                    // Check for HTTP 401 error.
                    switch (resp.StatusCode)
                    {
                    case HttpStatusCode.Unauthorized:     // 401
                        throw;
                    }

                    message = ex.Message;
                }

                MessageBox.Show(message, "Error connecting to wiki", MessageBoxButtons.OK, MessageBoxIcon.Error);

                throw;
            }
            catch (Exception ex)
            {
                //TODO:Better error handling

                string message = "";

                if (ex is WikiUrlException)
                {
                    if (ex.InnerException != null)
                    {
                        message = ex.InnerException.Message;
                    }
                }
                else
                {
                    message = ex.Message;
                }

                MessageBox.Show("An error occured while connecting to the server or loading project information from it. " +
                                "Please make sure that your internet connection works and such combination of project/language exist." +
                                "\r\nEnter the URL in the format \"en.wikipedia.org/w/\" (including path where index.php and api.php reside)." +
                                "\r\nError description: " + message,
                                "Error connecting to wiki", MessageBoxButtons.OK, MessageBoxIcon.Error);

                throw;
            }
        }
예제 #12
0
        /// <summary>
        /// Checks log in status, registered and version.
        /// </summary>
        private WikiStatusResult UpdateWikiStatus()
        {
            try
            {
                IsBot = false;

                Site = new SiteInfo(Editor.SynchronousEditor);

                //load version check page if no status set
                if (Updater.Result == Updater.AWBEnabledStatus.None)
                {
                    Updater.CheckForUpdates();
                }

                //load check page
                string url = Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=raw";

                string checkPageText = Editor.SynchronousEditor.HttpGet(url);

                Variables.RTL = Site.IsRightToLeft;
                Variables.CapitalizeFirstLetter = Site.CapitalizeFirstLetter;

                if (Variables.IsCustomProject || Variables.IsWikia)
                {
                    Variables.LangCode = Site.Language;
                }

                Updater.WaitForCompletion();
                Updater.AWBEnabledStatus versionStatus = Updater.Result;
                VersionCheckPage = Updater.GlobalVersionPage;

                //see if this version is enabled
                if (versionStatus == Updater.AWBEnabledStatus.Disabled)
                {
                    return(WikiStatusResult.OldVersion);
                }

                CheckPageText = checkPageText;

                if (!User.IsLoggedIn)
                {
                    return(WikiStatusResult.NotLoggedIn);
                }

                if (!User.HasRight("writeapi"))
                {
                    return(WikiStatusResult.NoRights);
                }

                // TODO: assess the impact on servers later
                Editor.Maxlag = /*User.IsBot ? 5 : 20*/ -1;

                // check if username is globally blacklisted
                foreach (Match badName in BadName.Matches(Updater.GlobalVersionPage))
                {
                    if (!string.IsNullOrEmpty(badName.Groups[1].Value.Trim()) &&
                        !string.IsNullOrEmpty(User.Name) &&
                        Regex.IsMatch(User.Name, badName.Groups[1].Value.Trim(),
                                      RegexOptions.IgnoreCase | RegexOptions.Multiline))
                    {
                        return(WikiStatusResult.NotRegistered);
                    }
                }

                //see if there is a message
                Match messages = Message.Match(checkPageText);
                if (messages.Success && messages.Groups[1].Value.Trim().Length > 0)
                {
                    MessageBox.Show(messages.Groups[1].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                //see if there is a version-specific message
                messages = VersionMessage.Match(checkPageText);
                if (messages.Success && messages.Groups[1].Value.Trim().Length > 0 &&
                    messages.Groups[1].Value == AWBVersion)
                {
                    MessageBox.Show(messages.Groups[2].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                HasTypoLink(checkPageText);

                List <string> us = new List <string>();
                foreach (Match underscore in Underscores.Matches(checkPageText))
                {
                    if (underscore.Success && underscore.Groups[1].Value.Trim().Length > 0)
                    {
                        us.Add(underscore.Groups[1].Value.Trim());
                    }
                }
                if (us.Count > 0)
                {
                    Variables.LoadUnderscores(us.ToArray());
                }

                //don't require approval if checkpage does not exist.
                if (checkPageText.Length < 1)
                {
                    IsBot = true;
                    return(WikiStatusResult.Registered);
                }

                if (checkPageText.Contains("<!--All users enabled-->"))
                {
                    //see if all users enabled
                    IsBot = true;
                    return(WikiStatusResult.Registered);
                }

                //see if we are allowed to use this software
                checkPageText = Tools.StringBetween(checkPageText, "<!--enabledusersbegins-->",
                                                    "<!--enabledusersends-->");

                string strBotUsers = Tools.StringBetween(checkPageText, "<!--enabledbots-->", "<!--enabledbotsends-->");

                if (IsSysop && Variables.Project != ProjectEnum.wikia)
                {
                    IsBot = UserNameInText(User.Name, strBotUsers);
                    return(WikiStatusResult.Registered);
                }

                if (UserNameInText(User.Name, checkPageText))
                {
                    // enable bot mode if in bots section
                    IsBot = UserNameInText(User.Name, strBotUsers);

                    return(WikiStatusResult.Registered);
                }

                if (Variables.Project != ProjectEnum.custom)
                {
                    string globalUsers = Tools.StringBetween(VersionCheckPage, "<!--globalusers-->",
                                                             "<!--globalusersend-->");

                    if (UserNameInText(User.Name, globalUsers))
                    {
                        return(WikiStatusResult.Registered);
                    }
                }
                return(WikiStatusResult.NotRegistered);
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(ToString(), ex.Message);
                Tools.WriteDebug(ToString(), ex.StackTrace);
                IsBot = false;
                return(WikiStatusResult.Error);
            }
        }
예제 #13
0
        /// <summary>
        /// Checks log in status, registered and version.
        /// </summary>
        private WikiStatusResult UpdateWikiStatus()
        {
            try
            {
                IsBot = false;

                Site = new SiteInfo(Editor.SynchronousEditor);

                // load version check page if no status set
                if (Updater.Result == Updater.AWBEnabledStatus.None)
                {
                    Updater.CheckForUpdates();
                }

                Variables.RTL = Site.IsRightToLeft;
                Variables.CapitalizeFirstLetter = Site.CapitalizeFirstLetter;

                Variables.UnicodeCategoryCollation = !Variables.IsCustomProject && Regex.IsMatch(Site.CategoryCollation, "[a-z-]*uca-");

                if (Variables.IsCustomProject || Variables.IsWikia)
                {
                    Variables.LangCode = Site.Language;
                }

                Variables.TagEdits = Site.IsAWBTagDefined;

                Updater.WaitForCompletion();
                Updater.AWBEnabledStatus versionStatus = Updater.Result;
                VersionCheckPage = Updater.GlobalVersionPage;

                // see if this version is enabled
                if ((versionStatus & Updater.AWBEnabledStatus.Disabled) == Updater.AWBEnabledStatus.Disabled)
                {
                    return(WikiStatusResult.OldVersion);
                }

                bool usingJSON = false;

                // Attempt to load the JSON CheckPage from the wiki
                string JSONCheckPageText = Editor.SynchronousEditor.HttpGet(Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPageJSON&action=raw");

                // HttpGet returns "" for 404
                if (!string.IsNullOrEmpty(JSONCheckPageText))
                {
                    usingJSON         = true;
                    CheckPageJSONText = JSONCheckPageText;
                }
                else
                {
                    // load non JSON check page
                    string nonJSONCheckPageText = Editor.SynchronousEditor.HttpGet(Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=raw");

                    // TODO: Some error handling

                    // remove U+200E LEFT-TO-RIGHT MARK, U+200F RIGHT-TO-LEFT MARK as on RTL wikis these can get typed in by accident
                    nonJSONCheckPageText = DirectionMarks.Replace(nonJSONCheckPageText, "");

                    CheckPageText = nonJSONCheckPageText;
                }

                if (!User.IsLoggedIn)
                {
                    return(WikiStatusResult.NotLoggedIn);
                }

                if (!User.HasRight("writeapi"))
                {
                    return(WikiStatusResult.NoRights);
                }

                // TODO: assess the impact on servers later
                Editor.Maxlag = /*User.IsBot ? 5 : 20*/ -1;

                var versionJson = JObject.Parse(Updater.GlobalVersionPage);

                // check if username is globally blacklisted based on the enwiki version page
                foreach (string badName in versionJson["badnames"])
                {
                    if (!string.IsNullOrEmpty(User.Name) &&
                        Regex.IsMatch(User.Name, badName,
                                      RegexOptions.IgnoreCase | RegexOptions.Multiline))
                    {
                        return(WikiStatusResult.NotRegistered);
                    }
                }

                // See if there's any global messages on the enwiki json version page
                JSONMessages(versionJson["messages"]);

                if (usingJSON)
                {
                    string configJSONText = Editor.SynchronousEditor.HttpGet(Variables.URLIndex + "?title=Project:AutoWikiBrowser/Config&action=raw");
                    // TODO: 404

                    ConfigJSONText = configJSONText;

                    var configJson = JObject.Parse(configJSONText);

                    // See if there's any messages on the local wikis config page
                    JSONMessages(configJson["messages"]);

                    Variables.RetfPath = !string.IsNullOrEmpty(configJson["typolink"].ToString()) ? configJson["typolink"].ToString() : "";

                    List <string> us = new List <string>();
                    foreach (var underscore in configJson["underscoretitles"])
                    {
                        if (underscore.ToString().Trim().Length > 0)
                        {
                            us.Add(underscore.ToString().Trim());
                        }
                    }
                    if (us.Count > 0)
                    {
                        Variables.LoadUnderscores(us.ToArray());
                    }

                    // don't require approval if CheckPage does not exist
                    // Or it has the special config option...
                    if (CheckPageJSONText.Length < 1 || (bool)configJson["allusersenabled"])
                    {
                        IsBot = true;
                        return(WikiStatusResult.Registered);
                    }

                    var checkPageJson = JObject.Parse(CheckPageJSONText);

                    var enabledUsers = checkPageJson["enabledusers"].Select(u => u.ToString()).ToList();
                    var enabledBots  = checkPageJson["enabledbots"].Select(u => u.ToString()).ToList();

                    // CheckPage option: 'allusersenabledusermode' will enable all users for user mode,
                    // and enable bots only when in 'enabledbots' section
                    if (
                        (bool)configJson["allusersenabledusermode"] ||
                        (IsSysop && Variables.Project != ProjectEnum.wikia) ||
                        enabledUsers.Contains(User.Name) ||
                        enabledBots.Contains(User.Name)
                        )
                    {
                        // enable bot mode if in bots section
                        IsBot = enabledBots.Contains(User.Name);

                        return(WikiStatusResult.Registered);
                    }
                }
                else
                {
                    // THIS IS ALL BASICALLY DEPRECATED...

                    // CheckPage Messages per wiki are still in scary HTML comments.... TBC!
                    // see if there is a message
                    foreach (Match m in Message.Matches(CheckPageText))
                    {
                        if (m.Groups[1].Value.Trim().Length == 0)
                        {
                            continue;
                        }
                        MessageBox.Show(m.Groups[1].Value.Trim(), "Automated message", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }

                    // see if there is a version-specific message
                    foreach (Match m in VersionMessage.Matches(CheckPageText))
                    {
                        if (m.Groups[1].Value.Trim().Length == 0 ||
                            m.Groups[1].Value != AWBVersion)
                        {
                            continue;
                        }
                        MessageBox.Show(m.Groups[2].Value.Trim(), "Automated message", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }

                    HasTypoLink(CheckPageText);

                    List <string> us = new List <string>();
                    foreach (Match underscore in Underscores.Matches(CheckPageText))
                    {
                        if (underscore.Success && underscore.Groups[1].Value.Trim().Length > 0)
                        {
                            us.Add(underscore.Groups[1].Value.Trim());
                        }
                    }
                    if (us.Count > 0)
                    {
                        Variables.LoadUnderscores(us.ToArray());
                    }

                    // don't require approval if checkpage does not exist
                    // Or it has the special text...
                    if (CheckPageText.Length < 1 || CheckPageText.Contains("<!--All users enabled-->"))
                    {
                        IsBot = true;
                        return(WikiStatusResult.Registered);
                    }

                    // see if we are allowed to use this software
                    CheckPageText = Tools.StringBetween(CheckPageText, "<!--enabledusersbegins-->",
                                                        "<!--enabledusersends-->");

                    // Checkpage option: <!--All users enabled user mode--> will enable all users for user mode,
                    // and enable bots only when in <!--enabledbots--> section
                    if (CheckPageText.Contains("<!--All users enabled user mode-->") ||
                        (IsSysop && Variables.Project != ProjectEnum.wikia) ||
                        UserNameInText(User.Name, CheckPageText))
                    {
                        string botUsers = Tools.StringBetween(CheckPageText, "<!--enabledbots-->", "<!--enabledbotsends-->");

                        // enable bot mode if in bots section
                        IsBot = UserNameInText(User.Name, botUsers);

                        return(WikiStatusResult.Registered);
                    }
                }

                if (Variables.Project != ProjectEnum.custom)
                {
                    var globalUsers = versionJson["globalusers"];
                    foreach (string s in globalUsers)
                    {
                        if (User.Name == s)
                        {
                            return(WikiStatusResult.Registered);
                        }
                    }
                }
                return(WikiStatusResult.NotRegistered);
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(ToString(), ex.Message);
                Tools.WriteDebug(ToString(), ex.StackTrace);
                IsBot = false;
                return(WikiStatusResult.Error);
            }
        }
예제 #14
0
        /// <summary>
        /// Checks log in status, registered and version.
        /// </summary>
        private WikiStatusResult UpdateWikiStatus()
        {
            try
            {
                IsBot = false;

                Site = new SiteInfo(Editor.SynchronousEditor);

                //load version check page if no status set
                if (Updater.Result == Updater.AWBEnabledStatus.None)
                {
                    Updater.CheckForUpdates();
                }

                //load check page
                string url;
                if (Variables.IsWikia)
                {
                    url = "http://community.wikia.com/index.php?title=Wikia:AutoWikiBrowser/CheckPage&action=raw";
                }
                else if ((Variables.Project == ProjectEnum.wikipedia) && (Variables.LangCode == "ar"))
                {
                    url =
                        "http://ar.wikipedia.org/w/index.php?title=%D9%88%D9%8A%D9%83%D9%8A%D8%A8%D9%8A%D8%AF%D9%8A%D8%A7:%D8%A7%D9%84%D8%A3%D9%88%D8%AA%D9%88%D9%88%D9%8A%D9%83%D9%8A_%D8%A8%D8%B1%D8%A7%D9%88%D8%B2%D8%B1/%D9%85%D8%B3%D9%85%D9%88%D8%AD&action=raw";
                }
                else
                {
                    url = Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=raw";
                }

                string strText = Editor.SynchronousEditor.HttpGet(url);

                Variables.RTL = Site.IsRightToLeft;

                if (Variables.IsCustomProject || Variables.IsWikia)
                {
                    Variables.LangCode = Site.Language;
                }

                string typoPostfix = "";
                if (Variables.IsWikia)
                {
                    typoPostfix = "-" + Variables.LangCode;

                    try
                    {
                        //load a local checkpage on Wikia
                        //it cannot be used to approve users, but it could be used to set some settings
                        //such as underscores and pages to ignore

                        string s = Editor.SynchronousEditor.Open("Project:AutoWikiBrowser/CheckPage");

                        // selectively add content of the local checkpage to the global one
                        strText += Message.Match(s).Value
                                   /*+ Underscores.Match(s).Value*/
                                   + WikiRegexes.NoGeneralFixes.Match(s);
                    }
                    catch
                    {
                    }
                }

                Updater.WaitForCompletion();
                Updater.AWBEnabledStatus versionStatus = Updater.Result;
                VersionCheckPage = Updater.GlobalVersionPage;

                //see if this version is enabled
                if (versionStatus == Updater.AWBEnabledStatus.Disabled)
                {
                    return(WikiStatusResult.OldVersion);
                }

                CheckPageText = strText;

                if (!User.IsLoggedIn)
                {
                    return(WikiStatusResult.NotLoggedIn);
                }

                if (!User.HasRight("writeapi"))
                {
                    return(WikiStatusResult.NoRights);
                }

                // TODO: assess the impact on servers later
                Editor.Maxlag = /*User.IsBot ? 5 : 20*/ -1;

                // check if username is globally blacklisted
                foreach (Match m3 in BadName.Matches(Updater.GlobalVersionPage))
                {
                    if (!string.IsNullOrEmpty(m3.Groups[1].Value.Trim()) &&
                        !string.IsNullOrEmpty(User.Name) &&
                        Regex.IsMatch(User.Name, m3.Groups[1].Value.Trim(),
                                      RegexOptions.IgnoreCase | RegexOptions.Multiline))
                    {
                        return(WikiStatusResult.NotRegistered);
                    }
                }

                //see if there is a message
                Match m = Message.Match(strText);
                if (m.Success && m.Groups[1].Value.Trim().Length > 0)
                {
                    MessageBox.Show(m.Groups[1].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                //see if there is a version-specific message
                m = VersionMessage.Match(strText);
                if (m.Success && m.Groups[1].Value.Trim().Length > 0 && m.Groups[1].Value == AWBVersion)
                {
                    MessageBox.Show(m.Groups[2].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                m = Regex.Match(strText, "<!--[Tt]ypos" + typoPostfix + ":(.*?)-->");
                if (m.Success && m.Groups[1].Value.Trim().Length > 0)
                {
                    Variables.RetfPath = m.Groups[1].Value.Trim();
                }

                List <string> us = new List <string>();
                foreach (Match m1 in Underscores.Matches(strText))
                {
                    if (m1.Success && m1.Groups[1].Value.Trim().Length > 0)
                    {
                        us.Add(m1.Groups[1].Value.Trim());
                    }
                }
                if (us.Count > 0)
                {
                    Variables.LoadUnderscores(us.ToArray());
                }

                //don't require approval if checkpage does not exist.
                if (strText.Length < 1)
                {
                    IsBot = true;
                    return(WikiStatusResult.Registered);
                }

                if (strText.Contains("<!--All users enabled-->"))
                {
                    //see if all users enabled
                    IsBot = true;
                    return(WikiStatusResult.Registered);
                }

                //see if we are allowed to use this software
                strText = Tools.StringBetween(strText, "<!--enabledusersbegins-->", "<!--enabledusersends-->");

                string strBotUsers = Tools.StringBetween(strText, "<!--enabledbots-->", "<!--enabledbotsends-->");
                Regex  username    = new Regex(@"^\*\s*" + Tools.CaseInsensitive(Regex.Escape(User.Name))
                                               + @"\s*$", RegexOptions.Multiline);

                if (IsSysop && Variables.Project != ProjectEnum.wikia)
                {
                    IsBot = username.IsMatch(strBotUsers);
                    return(WikiStatusResult.Registered);
                }

                if (username.IsMatch(strText))
                {
                    //enable bot mode
                    IsBot = username.IsMatch(strBotUsers);

                    return(WikiStatusResult.Registered);
                }

                if (Variables.Project != ProjectEnum.custom)
                {
                    string globalUsers = Tools.StringBetween(VersionCheckPage, "<!--globalusers-->", "<!--globalusersend-->");

                    if (username.IsMatch(globalUsers))
                    {
                        return(WikiStatusResult.Registered);
                    }
                }
                return(WikiStatusResult.NotRegistered);
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(ToString(), ex.Message);
                Tools.WriteDebug(ToString(), ex.StackTrace);
                IsBot = false;
                return(WikiStatusResult.Error);
            }
        }
예제 #15
0
        /// <summary>
        /// Checks log in status, registered and version.
        /// </summary>
        private WikiStatusResult UpdateWikiStatus()
        {
            try
            {
                IsBot = false;

                Site = new SiteInfo(Editor.SynchronousEditor);

                //load version check page if no status set
                if (Updater.Result == Updater.AWBEnabledStatus.None)
                    Updater.CheckForUpdates();

                //load check page
                string url = Variables.URLIndex + "?title=Project:AutoWikiBrowser/CheckPage&action=raw";

                string checkPageText = Editor.SynchronousEditor.HttpGet(url);

                Variables.RTL = Site.IsRightToLeft;
                Variables.CapitalizeFirstLetter = Site.CapitalizeFirstLetter;

                if (Variables.IsCustomProject || Variables.IsWikia)
                    Variables.LangCode = Site.Language;

                Updater.WaitForCompletion();
                Updater.AWBEnabledStatus versionStatus = Updater.Result;
                VersionCheckPage = Updater.GlobalVersionPage;

                //see if this version is enabled
                if (versionStatus == Updater.AWBEnabledStatus.Disabled)
                    return WikiStatusResult.OldVersion;

                CheckPageText = checkPageText;

                if (!User.IsLoggedIn)
                    return WikiStatusResult.NotLoggedIn;

                if (!User.HasRight("writeapi"))
                    return WikiStatusResult.NoRights;

                // TODO: assess the impact on servers later
                Editor.Maxlag = /*User.IsBot ? 5 : 20*/ -1;

                // check if username is globally blacklisted
                foreach (Match badName in BadName.Matches(Updater.GlobalVersionPage))
                {
                    if (!string.IsNullOrEmpty(badName.Groups[1].Value.Trim()) &&
                        !string.IsNullOrEmpty(User.Name) &&
                        Regex.IsMatch(User.Name, badName.Groups[1].Value.Trim(),
                                      RegexOptions.IgnoreCase | RegexOptions.Multiline))
                        return WikiStatusResult.NotRegistered;
                }

                //see if there is a message
                Match messages = Message.Match(checkPageText);
                if (messages.Success && messages.Groups[1].Value.Trim().Length > 0)
                {
                    MessageBox.Show(messages.Groups[1].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                //see if there is a version-specific message
                messages = VersionMessage.Match(checkPageText);
                if (messages.Success && messages.Groups[1].Value.Trim().Length > 0 &&
                    messages.Groups[1].Value == AWBVersion)
                {
                    MessageBox.Show(messages.Groups[2].Value, "Automated message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                HasTypoLink(checkPageText);

                List<string> us = new List<string>();
                foreach (Match underscore in Underscores.Matches(checkPageText))
                {
                    if (underscore.Success && underscore.Groups[1].Value.Trim().Length > 0)
                        us.Add(underscore.Groups[1].Value.Trim());
                }
                if (us.Count > 0) Variables.LoadUnderscores(us.ToArray());

                //don't require approval if checkpage does not exist.
                if (checkPageText.Length < 1)
                {
                    IsBot = true;
                    return WikiStatusResult.Registered;
                }

                if (checkPageText.Contains("<!--All users enabled-->"))
                {
                    //see if all users enabled
                    IsBot = true;
                    return WikiStatusResult.Registered;
                }

                //see if we are allowed to use this software
                checkPageText = Tools.StringBetween(checkPageText, "<!--enabledusersbegins-->",
                                                    "<!--enabledusersends-->");

                string strBotUsers = Tools.StringBetween(checkPageText, "<!--enabledbots-->", "<!--enabledbotsends-->");

                if (IsSysop && Variables.Project != ProjectEnum.wikia)
                {
                    IsBot = UserNameInText(User.Name, strBotUsers);
                    return WikiStatusResult.Registered;
                }

                if (UserNameInText(User.Name, checkPageText))
                {
                    //enable bot mode
                    IsBot = UserNameInText(User.Name, strBotUsers);

                    return WikiStatusResult.Registered;
                }

                if (Variables.Project != ProjectEnum.custom)
                {
                    string globalUsers = Tools.StringBetween(VersionCheckPage, "<!--globalusers-->",
                                                             "<!--globalusersend-->");

                    if (UserNameInText(User.Name, globalUsers))
                        return WikiStatusResult.Registered;
                }
                return WikiStatusResult.NotRegistered;
            }
            catch (Exception ex)
            {
                Tools.WriteDebug(ToString(), ex.Message);
                Tools.WriteDebug(ToString(), ex.StackTrace);
                IsBot = false;
                return WikiStatusResult.Error;
            }
        }
예제 #16
0
        /// <summary>
        /// Loads namespaces
        /// </summary>
        private void LoadProjectOptions()
        {
            string[] months = (string[])Variables.ENLangMonthNames.Clone();

            try
            {
                Site = new SiteInfo(Editor.SynchronousEditor);

                for (int i = 0; i < months.Length; i++)
                {
                    months[i] += "-gen";
                }
                Dictionary<string, string> messages = Site.GetMessages(months);

                if (messages.Count == 12)
                {
                    for (int i = 0; i < months.Length; i++)
                    {
                        months[i] = messages[months[i]];
                    }
                    Variables.MonthNames = months;
                }

                Variables.Namespaces = Site.Namespaces;
                Variables.NamespaceAliases = Site.NamespaceAliases;
                Variables.MagicWords = Site.MagicWords;
            }
            catch (ReadApiDeniedException)
            {
                throw;
            }
            catch (WebException ex)
            {
                string message = "";
                
                if (ex.InnerException != null)
                {
                    if (ex.InnerException is AuthenticationException)
                    {

                        if (message.Equals(""))
                        {
                            message = ex.Message;
                        }
                        else
                        {
                            message += " " + ex.Message;
                        }
                    }

                    if (message.Equals(""))
                    {
                        message = ex.InnerException.Message;
                    }
                    else
                    {
                        message += " " + ex.InnerException.Message;
                    }
                }
                else
                {
                    var resp = (HttpWebResponse)ex.Response;
                    if (resp == null) throw;

                    // Check for HTTP 401 error.
                    switch (resp.StatusCode)
                    {
                        case HttpStatusCode.Unauthorized: // 401
                            throw;
                    }
                    
                    message = ex.Message;
                }

                MessageBox.Show(message, "Error connecting to wiki", MessageBoxButtons.OK, MessageBoxIcon.Error);
                
                throw ex;
            }
            catch (Exception ex)
            {
                //TODO:Better error handling

                string message = "";

                if (ex is WikiUrlException)
                {
                    if (ex.InnerException != null)
                    {
                        message = ex.InnerException.Message;
                    }
                }
                else
                {
                    message = ex.Message;
                }

                MessageBox.Show("An error occured while connecting to the server or loading project information from it. " +
                        "Please make sure that your internet connection works and such combination of project/language exist." +
                        "\r\nEnter the URL in the format \"en.wikipedia.org/w/\" (including path where index.php and api.php reside)." +
                        "\r\nError description: " + message,
                        "Error connecting to wiki", MessageBoxButtons.OK, MessageBoxIcon.Error);

                throw;
            }
        }
예제 #17
0
        public SiteInfo Get(string url)
        {
            SiteInfo si = Find(url);
            if (si != null) return si;

            si = new SiteInfo(url);
            m_Cache.Add(si);
            SaveCache();

            return si;
        }