protected DataSet GetPageText(bool FormatWikiText) { using ( SqlDataAdapter da = new SqlDataAdapter( "w_GetPage", ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString )) { da.SelectCommand.CommandType = CommandType.StoredProcedure; da.SelectCommand.Parameters.Add("@PageName", SqlDbType.VarChar).Value = pageName; da.SelectCommand.Parameters.Add("@IncrementHitCount", SqlDbType.Bit).Value = Page.IsPostBack ? 0 : 1; DataSet ds = new DataSet(); da.Fill(ds, "Wiki"); if (ds.Tables["Wiki"] != null && ds.Tables["Wiki"].Rows.Count > 0) { try { //Get the links from the table da.SelectCommand.CommandText = "w_GetLinks"; da.SelectCommand.Parameters.Clear(); da.Fill(ds, "Links"); //Add the wiki formatted text to the dataset ds.Tables["Wiki"].Columns.Add("PageView"); wikiStartTime = System.DateTime.Now; if (FormatWikiText) { ds.Tables["Wiki"].Rows[0]["PageView"] = WikiParser.GenerateWikiText(ds.Tables["Wiki"].Rows[0]["PageText"].ToString(), ds.Tables["Links"]); } wikiEndTime = System.DateTime.Now; if (ConfigurationManager.AppSettings["displayPageStats"].ToString().ToLower() == "true") { lblPageStats.Text = string.Format("Wiki formatted text generation: {0}", wikiEndTime - wikiStartTime); } return(ds); } catch (Exception ex) { HandleError(ex); return(null); } } else { return(null); } } }
protected void btnPreviewInsert_Click(object sender, EventArgs e) { pnlPreview.Visible = true; string previewText = txtNewPage.Text; int maxPageLength = Convert.ToInt32(ConfigurationManager.AppSettings["maxPageLength"]); if (maxPageLength > 0) { if (previewText.Length > maxPageLength) { previewText = "! Warning - Results truncated to not exceed " + maxPageLength.ToString() + " bytes.\r\n" + previewText.Substring(0, maxPageLength); } } litPreview.Text = WikiParser.GenerateWikiText(previewText); }
protected void btnPreview_Click(object sender, EventArgs e) { pnlPreview.Visible = true; //truncate if over max length int maxPageLength = Convert.ToInt32(ConfigurationManager.AppSettings["maxPageLength"]); string previewText = ((TextBox)DataList1.Items[0].FindControl("txtPageText")).Text; if (maxPageLength > 0) { if (previewText.Length > maxPageLength) { previewText = "! Warning - Results truncated to not exceed " + maxPageLength.ToString() + " bytes.\r\n" + previewText.Substring(0, maxPageLength); } } litPreview.Text = WikiParser.GenerateWikiText(previewText); }
protected void grdHistory_SelectedIndexChanged(object sender, EventArgs e) { pnlPageText.Visible = true; //TODO: someone can currently promote the current page - needed if promoting a deleted page // but otherwise will create a redundant version. if (User.IsInRole("Editor") || User.IsInRole("Administrator")) { btnPromote.Visible = true; } else { btnPromote.Visible = false; } using (SqlConnection conn = new SqlConnection( ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { SqlCommand cmd = new SqlCommand("w_GetPageByVersion", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@PageName", SqlDbType.VarChar).Value = pageName; int version = int.Parse(((GridView)sender).SelectedRow.Cells[0].Text); cmd.Parameters.Add("@Version", SqlDbType.Int).Value = version; SqlDataReader reader; try { conn.Open(); reader = cmd.ExecuteReader(); reader.Read(); lblVersionHeader.Text = string.Format("<br><H2>Page History for {0}, v{1}</H2><br>", pageName, version); litPageHistoryView.Text = WikiParser.GenerateWikiText(reader["PageText"].ToString()); } catch (Exception ex) { HandleError(ex); } } }
protected void Page_Load(object sender, EventArgs e) { string page = ""; int v1 = 0; int v2 = 0; try { page = Request.Params["page"].ToString(); v1 = int.Parse(Request.Params["v1"].ToString()); v2 = int.Parse(Request.Params["v2"].ToString()); } catch { HandleError(new Exception("This page needs a page and version parameters passed to it. If you are " + "reading this message now, these parameters were not properly supplied. Please return to " + "the history view for a wiki page and select the 'Show Differences' option from there, or " + "contact your system administrator")); Response.End(); return; } lblVersion1.Text = v1.ToString(); lblVersion2.Text = v2.ToString(); lnkPage.Text = page; //now get the page text from the wiki string page1Text = ""; string page2Text = ""; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { SqlCommand cmd = new SqlCommand("w_GetPageByVersion", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@PageName", SqlDbType.VarChar).Value = page; cmd.Parameters.Add("@Version", SqlDbType.Int).Value = v1; SqlDataReader reader; try { conn.Open(); reader = cmd.ExecuteReader(); if (reader.Read()) { page1Text = reader["PageText"].ToString(); } reader.Close(); cmd.Parameters["@Version"].Value = v2; reader = cmd.ExecuteReader(); if (reader.Read()) { page2Text = reader["PageText"].ToString(); } reader.Close(); } catch (Exception ex) { HandleError(ex); } } //display the results string results = HTMLDiff(page1Text, page2Text); //HACK: handle UL and OL elements and headers results = Regex.Replace(results, @"(<span class=text(?:added|missing)>)\s?(\++|#+|!+)", "$2$1", RegexOptions.Compiled); results = WikiParser.GenerateWikiText(results); litVersion1.Text = (results).Replace("<span class=textadded>", "<span class=textadded>").Replace("</span>", "</span>").Replace("<span class=textmissing>", "<span class=textmissing>"); }