Пример #1
0
 /// <summary>
 /// Return a new page
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static Page Get_NewPage(string name)
 {
     // create new page
     Page NewPage = new Page(name);
     if (name == null)
     {
         return null;
     }
     return NewPage;
 }
Пример #2
0
        /// <summary>
        /// Format a page to html
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="Text"></param>
        /// <returns></returns>
        public static string FormatHTML(Page Page, string Text)
        {
            History("Core.FormatHTML (" + Page + " )");
            try
            {
                string return_value = "";
                if (Text.Contains("<!-- start content -->") && Text.Contains("<!-- end content -->") && Text != "")
                {
                    return_value = Text.Substring(Text.IndexOf("<!-- start content -->"));
                    return_value = return_value.Substring(0, return_value.IndexOf("<!-- end content -->"));
                }
                else if (Text.Contains("<!-- content -->") && Text.Contains("<!-- mw_content -->"))
                {
                    return_value = Text.Substring(Text.IndexOf("<!-- content -->"));
                    return_value = return_value.Substring(0, return_value.IndexOf("<!-- mw_content -->"));
                }
                else if (Text.Contains("</h1>") && Text.Contains("<div class=\"printfooter\">"))
                {
                    return_value = Text.Substring(Text.IndexOf("</h1>"));
                    return_value = return_value.Substring(0, return_value.IndexOf("<div class=\"printfooter\">"));
                }

                if (Text.Contains("<script>") && Text.Contains("</script>"))
                {

                }
                return_value = "<h1>" + Page.Name + "</h1>" + return_value;

                return return_value;
            }
            catch (Exception B)
            { Core.ExceptionHandler(B); }
            return "";
        }
Пример #3
0
 /// <summary>
 /// Gets the page
 /// </summary>
 /// <returns>The page.</returns>
 /// <param name="PageName">Page name.</param>
 public static Page GetPage(string PageName)
 {
     // get a new page
     Core.History("GetPage()");
     try
     {
         Page Page = new Page(PageName);
         return Page;
     }
     catch (Exception weird)
     {
         // weird, probably out of memory or something like that
         Core.ExceptionHandler(weird);
     }
     return null;
 }
Пример #4
0
            public ApiResult PostEdit(Page page, string text, string reason, string section = null, bool minor = false, bool watch = false, bool SuppressSummary = false, bool Create = true)
            {
                ApiResult result = new ApiResult(null, null, null);

                string token = null;
                bool InvalidToken = false;

                while (!InvalidToken)
                {
                    while (token == null)
                    {
                        if (section != null || Variables.EditToken == null)
                        {
                            result = ApiRequest("action=query&prop=info&intoken=edit&titles=" + System.Web.HttpUtility.UrlEncode(page.Name));
                            if (result.ResultInError)
                            {
                                return result;
                            }
                            token = GetParameter(result.Text, "edittoken");
                        }
                    }
                }

                return result;
            }
Пример #5
0
        public void Browser_DisplayPage(Page _Page)
        {
            try
            {
                if (_Page != null && this.Visible)
                {
                    if (_Page !=  _CurrentPage)
                    {
                        _CurrentEdit = _Page.LastEdit;
                        if (_Page.LastEdit == null)
                        {
                            _CurrentEdit = new Edit();

                            _CurrentEdit._Page = _Page;
                        }

                        Processing.DisplayEdit(_CurrentEdit);

                        if (_Page.LastEdit == Core.NullEdit)
                        {

                        }
                        Refresh_Interface();

                    }
                }
            }
            catch(Exception B)
            {
                Core.ExceptionHandler(B);
            }
        }
Пример #6
0
        public bool Set_Current_Page(Page _page)
        {
            Core.History("Set_Current_Page()");
            if (_page != null)
            {
                if ((_page != _CurrentPage) && DisplayingLast)
                {
                    if (_page.LastEdit == null)
                    {
                        _CurrentEdit = new Edit();
                        _CurrentEdit._Page = _page;
                        _CurrentPage = _page;

                        Requests.request_read.history History = new Requests.request_read.history();
                        History.Page = _page;
                        History.Start(RetrievePageContent);
                    }
                }
                if (_page.LastEdit == Core.NullEdit)
                {
                    CurrentPage.ForeColor = Color.Red;
                    Refresh_Interface();
                }
                if (_CurrentPage == _page && _CurrentEdit.Id != null)
                {
                    if (Edit.All.ContainsKey(_CurrentEdit.Id))
                    {
                        historyStrip.NewerEdit = Edit.All[_CurrentEdit.Id];
                    }
                }
                if  ( ! CurrentPage.Items.Contains(_page.Name))
                {
                    CurrentPage.Items.Add(_page.Name);
                    if (CurrentPage.Items.Count > 20) // this needs to be in config
                    {
                        CurrentPage.Items.RemoveAt(0);
                    }
                }
            }
            return true;
        }
Пример #7
0
 public void DisplayPage(string name)
 {
     Core.History("DisplayPage()");
     Page Page = new Page(CurrentPage.Text);
     Browser_DisplayPage(Page);
 }
Пример #8
0
        /// <summary>
        /// History
        /// </summary>
        /// <param name="Result"></param>
        /// <param name="Page"></param>
        public static void Process_History(string Result, Page Page)
        {
            try
            {
                Core.History("Processing.Process_History()");
                if (Result == null) return;

                System.Text.RegularExpressions.MatchCollection History = new System.Text.RegularExpressions.Regex("<rev revid=\"([^\"]+)\" parentid=\"([^\"]+)\" user=\"([^\"]+)\" (anon=\"\" )?timestamp=\"([^\"]+)\"( comment=\"([^\"]+)\")?(>([^<]*)</)?", System.Text.RegularExpressions.RegexOptions.Compiled).Matches(Result);

                if (History.Count == 0)
                {
                    if (Page.LastEdit == null)
                    {
                        Page.LastEdit = Core.NullEdit;
                    }
                }
                Edit NextEdit = null;
                for (int i = 0; i < History.Count - 1; i++)
                {
                    Edit _Edit = new Edit();
                    string Content = History[i].Groups[1].Value;

                    if (Edit.All.ContainsKey(Content))
                    {
                        _Edit = Edit.All[Content];
                    }

                    _Edit.Id = Content;

                    if (_Edit.Oldid == null)
                    {
                        _Edit.Oldid = "prev";
                    }
                    _Edit._Page = Page;

                    if (History[i].Groups[8].Value != "")
                    {
                        _Edit._Text = System.Web.HttpUtility.HtmlDecode(History[i].Groups[9].Value);
                    }

                    _Edit._User = Core.GetUser(System.Web.HttpUtility.HtmlDecode(History[i].Groups[3].Value));

                    if (_Edit.Summary == null)
                    {
                        _Edit.Summary = System.Web.HttpUtility.HtmlDecode(History[i].Groups[7].Value);
                    }

                    if (_Edit._Time == DateTime.MinValue)
                    {
                        _Edit._Time = DateTime.Parse(History[i].Groups[5].Value);
                    }

                    if (Page.LastEdit == null)
                    {
                        Page.LastEdit = _Edit;
                    }
                    else if (NextEdit != null)
                    {
                        _Edit.Next = NextEdit;
                        NextEdit.Prev = _Edit;
                        _Edit.Next.Oldid = _Edit.Id;
                    }

                    NextEdit = _Edit;
                    ProcessEdit(_Edit);
                }

                if (Result.Contains("<revisions rvstartid=\""))
                {
                    Page.HistoryOffset = NextEdit.Id;
                }
                else
                {
                    Page.HistoryOffset = null;
                    if (NextEdit != null)
                    {
                        NextEdit.Prev = Core.NullEdit;
                        Page.FirstEdit = NextEdit;
                    }
                }
                Program.MainForm.Draw_History();
            }
            catch (Exception B)
            {
                Core.ExceptionHandler(B);
            }
        }