Ejemplo n.º 1
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-->");
                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);
            }
        }
Ejemplo n.º 2
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 checkPageText = Editor.SynchronousEditor.HttpGet(url);

                Variables.RTL = Site.IsRightToLeft;

                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);
            }
        }