Exemplo n.º 1
0
        public void RequestAuthors(SweepNetPage page, long start, long end)
        {
            if (aw == null)
            {
                return;
            }

            if (result != null && result.ready && result.page.title == page.title && start == result.start && end == result.end)
            {
                aw.events.Push("AuthorsReady" + start + "_" + end);
                return;
            }
            result = null;
            if (worker != null && worker.IsAlive)
            {
                try
                {
                    worker.Abort();
                    worker.Join();
                }
                catch { }
            }

            result       = new AuthorsRequestResult();
            result.ready = false;
            result.page  = page;
            result.start = start;
            result.end   = end;
            result.error = false;

            worker = new Thread(MyThreadFunction);
            worker.IsBackground = true;
            worker.Start();
        }
Exemplo n.º 2
0
        public List <AuthorsRequestResultItem> _Work(SweepNetPage page, long start_id, long end_id)
        {
            try
            {
                List <AuthorsRequestResultItem> result = new List <AuthorsRequestResultItem>();

                Hashtable     h     = page.GetHashtableofcontributors(start_id + 1, end_id);
                List <string> names = new List <string>();
                foreach (String k in h.Keys)
                {
                    names.Add(Tools.UrlEncode(k));
                }

                String data = aw.HTTP_W_REQUEST("api.php?format=xml&action=query&list=users&ususers=" + String.Join("|", names.ToArray()) + "&usprop=groups|editcount|registration|blockinfo");

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(data);
                XmlNode currentNode;
                currentNode = xmlDoc.DocumentElement.SelectSingleNode("query");
                if (currentNode == null)
                {
                    return(null);
                }
                currentNode = currentNode.SelectSingleNode("users");
                if (currentNode == null)
                {
                    return(null);
                }
                foreach (XmlNode el in currentNode.SelectNodes("user"))
                {
                    AuthorsRequestResultItem tmp = new AuthorsRequestResultItem();
                    tmp.user      = el.Attributes.GetNamedItem("name").Value;
                    tmp.edits     = Convert.ToInt32(el.Attributes.GetNamedItem("editcount").Value);
                    tmp.timestamp = el.Attributes.GetNamedItem("registration").Value;
                    tmp.banned    = el.Attributes.GetNamedItem("blockid") != null;
                    tmp.groups    = new List <string>();

                    XmlNode j = el.SelectSingleNode("groups");
                    if (j != null)
                    {
                        foreach (XmlNode v in j.SelectNodes("g"))
                        {
                            if (v.InnerText == "*")
                            {
                                continue;
                            }
                            tmp.groups.Add(v.InnerText);
                        }
                    }

                    result.Add(tmp);
                }
                return(result);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 3
0
 public void FinishStart(Site mysite)
 {
     if (!title.Equals(""))
     {
         page = new SweepNetPage(mysite, title);
     }
     rand = Tools.FullRandom();
 }
Exemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (comm.TextLength > 100)
            {
                MessageBox.Show("Summary is longer than it should be!".T()); return;
            }
            if (text.Text.Equals(""))
            {
                MessageBox.Show("You are not supposed to clear the text!".T()); return;
            }
            String c        = comm.Text;
            String t        = text.Text;
            bool   m        = minor.Checked;
            Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate()
            {
                try
                {
                    saved       = true;
                    long lrv    = Convert.ToInt64(pg.lastRevisionID);
                    long newrev = pg.Save2(t, c, m);
                    //Page p=aw.GetPage(pg.title);
                    if (newrev <= 0)
                    {
                        SweepNetPage p = new SweepNetPage(aw.mysite, pg.title);
                        p.LoadRevision(lrv);
                        newrev = p.maxid;
                        //  MessageBox.Show("rr");
                    }
                    if (newrev > 0)
                    {
                        // aw.UpdateMaxRevid(curr.stable_id, curr.curr_id, p.maxid);
                        curr.curr_id = newrev;
                        //обновить дифф

                        aw.UpdateDiff(curr);

                        if (review.Checked)
                        {
                            aw.Review(newrev);
                            // this.reviewed = true;
                        }
                    }
                }
                catch (Exception et) { MessageBox.Show("Error occured while applying the changes: ".T() + et.Message); }
            }));

            myThread.Start();
            this.reviewed = review.Checked;
            //   myThread.Join();
            this.Close();
        }
Exemplo n.º 5
0
        public TRevisionSet(SweepNetPage pg)
        {
            List <tl> l = new List <tl>();

            foreach (WikiRevision rev in pg.list)
            {
                tl curr = new tl();
                curr.count    = 1;
                curr.type     = 1;
                curr.hidden   = false;
                curr.revision = rev;
                curr.rand     = Tools.FullRandom();
                curr.user     = rev.user;
                l.Add(curr);
            }
            RevisionGroup(l);
        }
Exemplo n.º 6
0
        public static DiffTemporaryResult __GetDiff(CoreOperations aw, WikiRevision from, WikiRevision to, Element el, bool pro_info = false)
        {
            DiffTemporaryResult result = null;

            try
            {
                String title = el.title;
                title = title.Replace(' ', '_');
                SweepNetPage page = el.page;
                if (page.list.Count == 0)
                {
                    return(result);
                }
                String data = "";
                long   start_id, end_id;
                if (from == null)
                {
                    from = to; to = null;
                }
                bool textflag = false;

                if (from == null || to == null || from.revid == to.revid)
                {
                    data = aw.HTTP_W_REQUEST("index.php?oldid=" + (from != null ? from.revid : to.revid) + "&action=raw&ctype=text/css");
                    if (data.Equals("") || data.Equals("/* Empty */"))
                    {
                        return(result);
                    }
                    data     = "<tr width=\"100%\"><td width=\"100%\" colspan=\"4\">" + HttpUtility.HtmlEncode(data).Replace("\n", "<br />") + "</td></tr>";
                    start_id = -1; end_id = el.page.curr.revid;
                }
                else
                {
                    data = aw.HTTP_W_REQUEST("api.php?format=xml&action=query&prop=revisions&titles=" + HttpUtility.UrlEncode(title) + "&rvstartid=" + from.revid + "&rvlimit=1&rvdiffto=" + to.revid);
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(data);
                    XmlNode currentNode;
                    currentNode = xmlDoc.DocumentElement.SelectSingleNode("query");
                    if (currentNode == null)
                    {
                        return(result);
                    }
                    currentNode = currentNode.SelectSingleNode("pages");
                    if (currentNode == null)
                    {
                        return(result);
                    }
                    currentNode = currentNode.SelectSingleNode("page");
                    if (currentNode == null)
                    {
                        return(result);
                    }
                    currentNode = currentNode.SelectSingleNode("revisions");
                    if (currentNode == null)
                    {
                        return(result);
                    }
                    currentNode = currentNode.SelectSingleNode("rev");
                    if (currentNode == null)
                    {
                        return(result);
                    }
                    currentNode = currentNode.SelectSingleNode("diff");
                    if (currentNode == null)
                    {
                        return(result);
                    }
                    data = currentNode.InnerText;

                    start_id = page.flagged_rev + 1; end_id = el.page.curr.revid;
                }

                String diffrez = "<html><head>" + i18n.GetText("diff_head" + Options.GetOption("diff_style")) + "</head><body width=\"100%\">";

                if (pro_info)
                {
                    diffrez += "<table width=\"100%\" border=\"0\" valign=\"top\"><tr>";
                    diffrez += "<td width=\"" + (to != null ? "50" : "100") + "%\" valign=\"top\">" + DateTime.Parse(from.timestamp).ToString("dd/MM/yyyy HH:mm") + " " + from.user + "" + (to != null ? "<br />" : "") + " [" + from.size + " байт]" + (from.minor ? " [m] " : "") + " (" + HttpUtility.HtmlEncode(from.comm) + ")" + "</td>";
                    if (to != null)
                    {
                        diffrez += "<td valign=\"top\">" + DateTime.Parse(to.timestamp).ToString("dd/MM/yyyy HH:mm") + " " + to.user + "<br /> [" + to.size + " байт]" + (to.minor ? " [m] " : "") + " (" + HttpUtility.HtmlEncode(to.comm) + ")" + "</td>";
                    }
                    diffrez += "</tr></table>";
                }
                else
                {
                    diffrez += "<table width=\"100%\" border=\"0\"><tr><td colspan=\"2\">" + String.Format("{0} edits have been made by: {1}".T(), (page.GeCountOfEdits(start_id, end_id)), Tools.GetColoredListOfUsers(page.GetHashtableofcontributors(start_id, end_id))) /*page.GetContributors(1).ToArray())*/;
                    if (page.unflagged_count == 1)
                    {
                        diffrez += "; " + "Summary".T() + ": \"" + HttpUtility.HtmlEncode(page.GetLastRevision().comm) + "\"";
                    }
                    diffrez += @"<span id=""authors""></span>";//"<!--SPACE_FOR_AUTHORS_BEGINNING--><!--SPACE_FOR_AUTHORS_ENDING-->";
                    diffrez += "</td></tr><tr><td align=\"left\" valign=\"bottom\">" + (page.is_flagged ? "Stable revision".T() : "First revision".T()) + " — " + Tools.ConvertTimestampToDate(page.list[0].timestamp) + "</td><td align=\"right\" valign=\"bottom\">Текущая — " + Tools.ConvertTimestampToDate(page.list[page.list.Count - 1].timestamp) + "</td></tr></table>";
                }

                if (!WBcallback.CheckVisbleChanges(data) && !data.Equals(""))
                {
                    diffrez += "<div align=\"center\"><b>" + "No noticeable changes".T() + "</b></div>";
                }
                diffrez += "<table width=\"100%\" style=\"border-top: solid #000000 1px;\">";
                diffrez += "<col width=\"2%\" valign=\"top\"><col width=\"46%\" valign=\"top\"><col width=\"2%\" valign=\"top\"><col width=\"46%\" valign=\"top\">";
                List <DiffPiece> pieces = DiffEditor.SplitIntoPieces(ref data);
                diffrez += data.Equals("") ? "<td colspan=\"4\"><!--diff_is_empty-->" + "These revisions are the same".T() + "</td>" : data;
                diffrez += "</table>";
                diffrez += "<br/><script>";
                diffrez += "</script></body></html>";
                diffrez  = Tools.ReplaceFirst(diffrez, "<span class=\"diffchange", "<span id=\"first_difference\" class=\"diffchange");

                diffrez = (Options.GetOptionInt("check_links") == 1 ? WBcallback.ProcessPage(diffrez) : diffrez);

                return(new DiffTemporaryResult(diffrez, pieces));
            }
            catch (Exception) {
                return(result);
            }
        }
Exemplo n.º 7
0
        public static String __GetView(CoreOperations aw, WikiRevision rev, Element el, bool pro_info = false)
        {
            try
            {
                String title = el.title;
                title = title.Replace(' ', '_');
                SweepNetPage page = el.page;
                if (page.list.Count == 0)
                {
                    return("");
                }
                String data = "";
                long   start_id;

                if (el.stable_id < 1)
                {
                    data     = aw.HTTP_W_REQUEST("api.php?format=xml&action=query&prop=revisions&rvprop=content&titles=" + HttpUtility.UrlEncode(title) + "&rvlimit=1&rvparse=1");
                    start_id = -1;
                }
                else
                {
                    data     = aw.HTTP_W_REQUEST("api.php?format=xml&action=query&prop=revisions&rvprop=content&titles=" + HttpUtility.UrlEncode(title) + "&rvstartid=" + el.stable_id + "&rvlimit=1&rvparse=1");
                    start_id = page.flagged_rev;
                }
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(data);
                XmlNode currentNode;
                currentNode = xmlDoc.DocumentElement.SelectSingleNode("query");
                if (currentNode == null)
                {
                    return("");
                }
                currentNode = currentNode.SelectSingleNode("pages");
                if (currentNode == null)
                {
                    return("");
                }
                currentNode = currentNode.SelectSingleNode("page");
                if (currentNode == null)
                {
                    return("");
                }
                currentNode = currentNode.SelectSingleNode("revisions");
                if (currentNode == null)
                {
                    return("");
                }
                currentNode = currentNode.SelectSingleNode("rev");
                if (currentNode == null)
                {
                    return("");
                }
                data = currentNode.InnerText;
                if (data.Equals("") || data == null)
                {
                    data = "-1";
                }


                String diffrez = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body>";
                if (pro_info)
                {
                    diffrez += "<table width=\"100%\" border=\"0\" valign=\"top\"><tr>";
                    diffrez += "<td width=\"100%\" valign=\"top\">" + DateTime.Parse(rev.timestamp).ToString("dd/MM/yyyy HH:mm") + " " + rev.user + " [" + rev.size + " байт]" + (rev.minor ? " [m] " : "") + " (" + HttpUtility.HtmlEncode(rev.comm) + ")" + "</td>";
                    diffrez += "</tr></table>";
                }
                else
                {
                    if (page.unflagged_count == 1)
                    {
                        diffrez += "; " + "Summary".T() + ": \"" + HttpUtility.HtmlEncode(page.GetLastRevision().comm) + "\"";
                    }
                    diffrez += "</td></tr><tr><td align=\"left\" valign=\"bottom\">" + "Stable revision".T() + " — " + Tools.ConvertTimestampToDate(page.list[0].timestamp) + "</td><td align=\"right\" valign=\"bottom\">Текущая — " + Tools.ConvertTimestampToDate(page.list[page.list.Count - 1].timestamp) + "</td></tr></table>";
                }
                diffrez += "<table width=\"100%\" style=\"border-top: solid #000000 1px;\">";
                diffrez += "<tr width=\"100%\"><td>" + data + "</td></tr>";
                diffrez += "</table><br/></body></html>";

                return(diffrez);
            }
            catch (Exception) { /*MessageBox.Show(e.Message+"\r\n\r\n"+e.StackTrace);*/ return(""); }
        }
Exemplo n.º 8
0
        public static String _GetView(CoreOperations aw, Element el)
        {
            try
            {
                String title = el.title;
                title = title.Replace(' ', '_');
                SweepNetPage page = el.page;
                if (page.list.Count == 0)
                {
                    return("");
                }
                String data = "";
                long   start_id;

                if (el.stable_id < 1)
                {
                    data     = aw.HTTP_W_REQUEST("api.php?format=xml&action=query&prop=revisions&rvprop=content&titles=" + HttpUtility.UrlEncode(title) + "&rvlimit=1&rvparse=1");
                    start_id = -1;
                }
                else
                {
                    data     = aw.HTTP_W_REQUEST("api.php?format=xml&action=query&prop=revisions&rvprop=content&titles=" + HttpUtility.UrlEncode(title) + "&rvstartid=" + el.stable_id + "&rvlimit=1&rvparse=1");
                    start_id = page.flagged_rev;
                }
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(data);
                XmlNode currentNode;
                currentNode = xmlDoc.DocumentElement.SelectSingleNode("query");
                if (currentNode == null)
                {
                    return("");
                }
                currentNode = currentNode.SelectSingleNode("pages");
                if (currentNode == null)
                {
                    return("");
                }
                currentNode = currentNode.SelectSingleNode("page");
                if (currentNode == null)
                {
                    return("");
                }
                currentNode = currentNode.SelectSingleNode("revisions");
                if (currentNode == null)
                {
                    return("");
                }
                currentNode = currentNode.SelectSingleNode("rev");
                if (currentNode == null)
                {
                    return("");
                }
                data = currentNode.InnerText;
                if (data.Equals("") || data == null)
                {
                    data = "-1";
                }

                String diffrez = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" + Properties.Resources.view_css_style + "</head><body>";
                diffrez += "<table width=\"100%\" border=\"0\"><tr><td colspan=\"2\">" + String.Format("{0} edits have been made by: {1}".T(), (page.unflagged_count), Tools.GetColoredListOfUsers(page.GetHashtableofcontributors(start_id + 1))) /*page.GetContributors(1).ToArray())*/;
                if (page.unflagged_count == 1)
                {
                    diffrez += "; " + "Summary".T() + ": \"" + HttpUtility.HtmlEncode(page.GetLastRevision().comm) + "\"";
                }
                diffrez += "</td></tr><tr><td align=\"left\" valign=\"bottom\">" + "Stable revision".T() + " — " + Tools.ConvertTimestampToDate(page.list[0].timestamp) + "</td><td align=\"right\" valign=\"bottom\">Текущая — " + Tools.ConvertTimestampToDate(page.list[page.list.Count - 1].timestamp) + "</td></tr></table>";
                diffrez += "<table width=\"100%\" style=\"border-top: solid #000000 1px;\">";
                while (data.Contains("<span class=\"mw-editsection\">"))
                {
                    string delete = "";

                    int from = data.IndexOf("<span class=\"mw-editsection\">");
                    int to   = data.IndexOf("<span class=\"mw-editsection-bracket\">]</span></span>") + "<span class=\"mw-editsection-bracket\">]</span></span>".Length;
                    if (from >= 0 && to > 0 && to > from)
                    {
                        delete = data.Substring(from, to - from);
                        data   = data.Replace(delete, "");
                    }
                    else
                    {
                        break;
                    }
                }



                diffrez += "<tr width=\"100%\"><td>" + data + "</td></tr>";
                diffrez += "</table>";
                diffrez += "<br/></body></html>";

                return(diffrez);
            }
            catch (Exception) { return(""); }
        }
Exemplo n.º 9
0
        /* Applying changes */
        private void ThreadFunction()
        {
            try
            {
                if (aw != null && wb != null)
                {
                    Page p = aw.PageCreate(element.page.title);
                    p.Load();

                    if (p.text != "")
                    {
                        string[] lines = p.text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                        foreach (DiffPiece d in pieces)
                        {
                            int from = d.starting;
                            for (int k = (from - 1) >= 0 ? (from - 1) : 0; k < lines.Length; k++)
                            {
                                if (lines[k] == d.text)
                                {
                                    d.real_line = k;
                                    d.ready     = true;
                                    break;
                                }
                            }
                        }


                        //  EditAndReview(this, new EditAndReviewActionArguments(element, p.text));
                        bool error = false, done = false;
                        lock (wb)
                        {
                            for (int i = 0; i < pieces.Count; i++)
                            {
                                if (pieces[i].being_edited)
                                {
                                    if (!pieces[i].ready)
                                    {
                                        error = true;
                                    }
                                    else
                                    {
                                        HtmlElement el = null;
                                        wb.Invoke((MethodInvoker) delegate
                                        {
                                            el = wb.Document.GetElementById("textarea_" + (i + 1).ToString());
                                        });
                                        if (el == null)
                                        {
                                            error = true;
                                        }
                                        else
                                        {
                                            lines[pieces[i].real_line] = el.InnerText;
                                            done = true;
                                        }
                                    }
                                }
                            }
                        }

                        if (error)
                        {
                            string errstr = "Due to internal errors the application did not manage to apply the changes you've made.".T();
                            wb.Invoke((MethodInvoker) delegate
                            {
                                MessageBox.Show(errstr, "Error", MessageBoxButtons.OK);
                            });
                            return;
                        }

                        string summary = ""; bool success = false, minor = false;
                        wb.Invoke((MethodInvoker) delegate
                        {
                            TextInputForm form = new TextInputForm("Enter a summary".T(), "([[Project:Sweep-Net|Sweep-Net]]): ");
                            form.ShowDialog((IWin32Window)wb.Parent);
                            if (form.successfully)
                            {
                                success = true;
                                summary = form.text;
                            }

                            HtmlElement el = wb.Document.GetElementById("is_minor");
                            if (el != null)
                            {
                                minor = el.GetAttribute("checked").ToLower() == "true";
                            }
                        });

                        if (success)
                        {
                            wb.Invoke((MethodInvoker) delegate
                            {
                                SetUpdatingStatus();
                            });
                            //    MessageBox.Show(String.Join("\r\n", lines));
                            p.Save2(String.Join("\r\n", lines), summary, minor);
                            SweepNetPage tp = new SweepNetPage(aw.mysite, p.title);

                            element.page.ReloadRevision();
                            //tp.LoadRevision(Convert.ToInt64(p.lastRevisionID));

                            if (element.page.maxid > 0)
                            {
                                element.curr_id = element.page.curr.revid;

                                //обновить дифф

                                aw.UpdateDiff(element);
                                wb.Invoke((MethodInvoker) delegate
                                {
                                    SetUpdatedStatus();
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //    MessageBox.Show(e.Message+e.StackTrace);
            }
        }