コード例 #1
0
        private void userContributionsButton_Click(object sender, EventArgs e)
        {
            WikiFunctions.API.ApiEdit api = new ApiEdit("http://ne.wikipedia.org/w/", false);
            api.Login("user", "password");

            List <string> userContribs = new List <string>();
            UserContribUserDefinedNumberListProvider listProvider = new UserContribUserDefinedNumberListProvider();

            listProvider.Limit = 15000;

            List <Article> allList;

            allList = listProvider.ApiMakeList(
                "http://ne.wikipedia.org/w/index.php?limit=500&tagFilter=&title=Special%3AContributions&contribs=user&target=Nirmal+Dulal&namespace=10&year=&month=-1",
                0);
            userContribs = allList.Select(p => p.Name + "/doc").ToList();
            StringBuilder sb = new StringBuilder();


            //adds doc
            foreach (Article article in allList)
            {
                sb.AppendLine(article.Name + "/doc");
            }
            richTextBoxTemplateList.Text = sb.ToString();



            //this.richTextBoxTemplateList.AppendText(userContribs);
        }
コード例 #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            groupBox2.Enabled = false;
            try
            {
                Editor = new ApiEdit(txtURL.Text);
                Editor.Login(txtUsername.Text, txtPassword.Text);

                groupBox2.Enabled = true;
                txtEdit.Text      = "";
                btnSave.Enabled   = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name);
            }
        }
コード例 #3
0
        private static string UpdateWiki(string url, string username, string password)
        {
            ApiEdit edit = new ApiEdit($"{url}/w/");

            edit.Login(username, password);

            var origCheckPageTitle = "Project:AutoWikiBrowser/CheckPage";
            var origCheckPageText  = edit.Open(origCheckPageTitle);

            var editProtection = edit.Page.EditProtection;
            var moveProtection = edit.Page.MoveProtection;

            if (!edit.Page.Exists || string.IsNullOrEmpty(origCheckPageText))
            {
                return("No check page");
            }

            var enabledUsers = Tools.StringBetween(origCheckPageText, "<!--enabledusersbegins-->",
                                                   "<!--enabledusersends-->");

            var botUsers = Tools.StringBetween(enabledUsers, "<!--enabledbots-->", "<!--enabledbotsends-->");

            var normalUsers = enabledUsers.Replace("<!--enabledbots-->" + botUsers + "<!--enabledbotsends-->", "");

            Regex usernameRegex = new Regex(@"^\*\s*(.*?)\s*$", RegexOptions.Multiline | RegexOptions.Compiled);

            List <string> users = new List <string>();

            foreach (Match m in usernameRegex.Matches(normalUsers))
            {
                if (!string.IsNullOrEmpty(m.Groups[1].Value.Trim()))
                {
                    users.Add(m.Groups[1].Value.Trim());
                }
            }

            users.Sort();

            List <string> bots = new List <string>();

            foreach (Match m in usernameRegex.Matches(botUsers))
            {
                if (!string.IsNullOrEmpty(m.Groups[1].Value.Trim()))
                {
                    bots.Add(m.Groups[1].Value.Trim());
                }
            }

            bots.Sort();

            Dictionary <string, List <string> > checkPageOutput = new Dictionary <string, List <string> >
            {
                { "enabledusers", users.Distinct().ToList() },
                { "enabledbots", bots.Distinct().ToList() }
            };

            var title = "Project:AutoWikiBrowser/CheckPageJSON";

            edit.Open(title);

            edit.Save(JsonConvert.SerializeObject(checkPageOutput, Formatting.Indented),
                      $"Converting AutoWikiBrowser CheckPage to json - {PHAB_TASK}", false,
                      WatchOptions.NoChange, "json");

            if (!string.IsNullOrEmpty(editProtection) || !string.IsNullOrEmpty(moveProtection))
            {
                edit.Open(title);

                edit.Protect(title, $"Copying protection from [[{origCheckPageTitle}]] - {PHAB_TASK}", "infinite",
                             editProtection, moveProtection);
            }

            // Site Config stuff
            Dictionary <string, object> configOutput = new Dictionary <string, object>();

            Match typoLink = Regex.Match(origCheckPageText, "<!--[Tt]ypos:(.*?)-->");

            configOutput.Add("typolink",
                             typoLink.Success && typoLink.Groups[1].Value.Trim().Length > 0 ? typoLink.Groups[1].Value.Trim() : "");

            configOutput.Add("allusersenabled", origCheckPageText.Contains("<!--All users enabled-->"));

            configOutput.Add("allusersenabledusermode",
                             origCheckPageText.Contains("<!--All users enabled user mode-->"));

            List <Dictionary <string, string> > awbMessages = new List <Dictionary <string, string> >();

            // see if there is a message
            foreach (Match m in Message.Matches(origCheckPageText))
            {
                if (m.Groups[1].Value.Trim().Length == 0)
                {
                    continue;
                }

                awbMessages.Add(new Dictionary <string, string>
                {
                    { "version", "*" },
                    { "message", m.Groups[1].Value.Trim() }
                });
            }

            // see if there is a version-specific message
            foreach (Match m in VersionMessage.Matches(origCheckPageText))
            {
                if (m.Groups[2].Value.Trim().Length == 0 || m.Groups[1].Value == "x.x.x.x")
                {
                    continue;
                }

                awbMessages.Add(new Dictionary <string, string>
                {
                    { "version", m.Groups[1].Value },
                    { "message", m.Groups[2].Value.Trim() }
                });
            }

            configOutput.Add("messages", awbMessages);

            List <string> us = new List <string>();

            foreach (Match underscore in Underscores.Matches(origCheckPageText))
            {
                if (underscore.Success && underscore.Groups[1].Value.Trim().Length > 0)
                {
                    us.Add(underscore.Groups[1].Value.Trim());
                }
            }

            us.Sort();
            configOutput.Add("underscoretitles", us);

            List <string> NoParse = new List <string>();

            // Get list of articles not to apply general fixes to.
            Match noGenFix = WikiRegexes.NoGeneralFixes.Match(origCheckPageText);

            if (noGenFix.Success)
            {
                foreach (Match link in WikiRegexes.UnPipedWikiLink.Matches(noGenFix.Value))
                {
                    if (!NoParse.Contains(link.Groups[1].Value))
                    {
                        NoParse.Add(link.Groups[1].Value);
                    }
                }
            }

            NoParse.Sort();
            configOutput.Add("nogenfixes", NoParse);

            List <string> NoRetf = new List <string>();

            // Get list of articles not to apply RETF to.
            Match noRETF = WikiRegexes.NoRETF.Match(origCheckPageText);

            if (noRETF.Success)
            {
                foreach (Match link in WikiRegexes.UnPipedWikiLink.Matches(noRETF.Value))
                {
                    if (!NoRetf.Contains(link.Groups[1].Value))
                    {
                        NoRetf.Add(link.Groups[1].Value);
                    }
                }
            }

            NoRetf.Sort();
            configOutput.Add("noregextypofix", NoRetf);

            title = "Project:AutoWikiBrowser/Config";
            edit.Open(title);
            edit.Save(JsonConvert.SerializeObject(configOutput, Formatting.Indented),
                      $"Converting AutoWikiBrowser wiki config to json - {PHAB_TASK}", false,
                      WatchOptions.NoChange, "json");

            if (!string.IsNullOrEmpty(editProtection) || !string.IsNullOrEmpty(moveProtection))
            {
                edit.Open(title);

                edit.Protect(title, $"Copying protection from [[{origCheckPageTitle}]] - {PHAB_TASK}", "infinite",
                             editProtection, moveProtection);
            }

            return("Done!");
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var origCheckPageText =
                Tools.GetHTML(
                    "https://en.wikipedia.org/w/index.php?title=Wikipedia:AutoWikiBrowser/CheckPage&action=raw");

            var enabledUsers = Tools.StringBetween(origCheckPageText, "<!--enabledusersbegins-->",
                                                   "<!--enabledusersends-->");

            var botUsers = Tools.StringBetween(enabledUsers, "<!--enabledbots-->", "<!--enabledbotsends-->");

            var normalUsers = enabledUsers.Replace("<!--enabledbots-->" + botUsers + "<!--enabledbotsends-->", "");

            Regex username = new Regex(@"^\*\s*(.*?)\s*$", RegexOptions.Multiline | RegexOptions.Compiled);

            List <string> users = new List <string>();

            foreach (Match m in username.Matches(normalUsers))
            {
                users.Add(m.Groups[1].Value.Trim());
            }

            users.Sort();

            List <string> bots = new List <string>();

            foreach (Match m in username.Matches(botUsers))
            {
                bots.Add(m.Groups[1].Value.Trim());
            }

            bots.Sort();

            Dictionary <string, List <string> > checkPageOutput = new Dictionary <string, List <string> > {
                { "enabledusers", users },
                { "enabledbots", bots }
            };

            ApiEdit edit    = new ApiEdit("https://en.wikipedia.org/w/");
            var     profile = AWBProfiles.GetProfile(1);

            edit.Login(profile.Username, profile.Password);

            edit.Open("Project:AutoWikiBrowser/CheckPageJSON");
            edit.Save(JsonConvert.SerializeObject(checkPageOutput, Formatting.Indented), "Converting from non json page", false, WatchOptions.NoChange);

            // Site Config stuff
            Dictionary <string, object> configOutput = new Dictionary <string, object>();

            Match typoLink = Regex.Match(origCheckPageText, "<!--[Tt]ypos:(.*?)-->");

            configOutput.Add("typolink", typoLink.Success && typoLink.Groups[1].Value.Trim().Length > 0 ? typoLink.Groups[1].Value.Trim() : "");

            configOutput.Add("allusersenabled", origCheckPageText.Contains("<!--All users enabled-->"));

            configOutput.Add("allusersenabledusermode", origCheckPageText.Contains("<!--All users enabled user mode-->"));

            List <Dictionary <string, string> > awbMessages = new List <Dictionary <string, string> >();

            // see if there is a message
            foreach (Match m in Message.Matches(origCheckPageText))
            {
                if (m.Groups[1].Value.Trim().Length == 0)
                {
                    continue;
                }

                awbMessages.Add(new Dictionary <string, string> {
                    { "version", "*" },
                    { "message", m.Groups[1].Value.Trim() }
                });
            }

            // see if there is a version-specific message
            foreach (Match m in VersionMessage.Matches(origCheckPageText))
            {
                if (m.Groups[2].Value.Trim().Length == 0 || m.Groups[1].Value == "x.x.x.x")
                {
                    continue;
                }

                awbMessages.Add(new Dictionary <string, string> {
                    { "version", m.Groups[1].Value },
                    { "message", m.Groups[2].Value.Trim() }
                });
            }

            configOutput.Add("messages", awbMessages);

            List <string> us = new List <string>();

            foreach (Match underscore in Underscores.Matches(origCheckPageText))
            {
                if (underscore.Success && underscore.Groups[1].Value.Trim().Length > 0)
                {
                    us.Add(underscore.Groups[1].Value.Trim());
                }
            }

            us.Sort();
            configOutput.Add("underscoretitles", us);

            List <string> NoParse = new List <string>();

            // Get list of articles not to apply general fixes to.
            Match noGenFix = WikiRegexes.NoGeneralFixes.Match(origCheckPageText);

            if (noGenFix.Success)
            {
                foreach (Match link in WikiRegexes.UnPipedWikiLink.Matches(noGenFix.Value))
                {
                    if (!NoParse.Contains(link.Groups[1].Value))
                    {
                        NoParse.Add(link.Groups[1].Value);
                    }
                }
            }

            NoParse.Sort();
            configOutput.Add("nogenfixes", NoParse);

            List <string> NoRetf = new List <string>();
            // Get list of articles not to apply RETF to.
            Match noRETF = WikiRegexes.NoRETF.Match(origCheckPageText);

            if (noRETF.Success)
            {
                foreach (Match link in WikiRegexes.UnPipedWikiLink.Matches(noRETF.Value))
                {
                    if (!NoRetf.Contains(link.Groups[1].Value))
                    {
                        NoRetf.Add(link.Groups[1].Value);
                    }
                }
            }

            NoRetf.Sort();
            configOutput.Add("noregextypofix", NoRetf);

            edit.Open("Project:AutoWikiBrowser/Config");
            edit.Save(JsonConvert.SerializeObject(configOutput, Formatting.Indented), "Converting from non json page", false, WatchOptions.NoChange);
        }