/// <summary> /// Redirects to the login page if needed. /// </summary> public static void RedirectToLoginIfNeeded() { if (SessionFacade.LoginKey == null) { UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed())); } }
protected void rptItems_DataBinding(object sender, EventArgs e) { if (pageFullName == null) { return; } // Build a DataTable containing the proper information DataTable table = new DataTable("Items"); table.Columns.Add("Name"); table.Columns.Add("Size"); table.Columns.Add("Link"); string currentWiki = Tools.DetectCurrentWiki(); foreach (IFilesStorageProviderV40 provider in Collectors.CollectorsBox.FilesProviderCollector.GetAllProviders(currentWiki)) { string[] attachments = provider.ListPageAttachments(pageFullName); foreach (string s in attachments) { DataRow row = table.NewRow(); row["Name"] = s; row["Size"] = Tools.BytesToString(provider.GetPageAttachmentDetails(pageFullName, s).Size); row["Link"] = "GetFile.aspx?File=" + Tools.UrlEncode(s).Replace("'", "'") + "&AsStreamAttachment=1&Provider=" + provider.GetType().FullName + "&IsPageAttachment=1&Page=" + Tools.UrlEncode(pageFullName); table.Rows.Add(row); } } rptItems.DataSource = table; }
/// <summary> /// Creates a new instance of the <see cref="T:SearchResultRow" /> class. /// </summary> /// <param name="result">The result to use.</param> /// <returns>The instance.</returns> public static SearchResultRow CreateInstance(SearchResult result) { //string queryStringKeywords = "HL=" + GetKeywordsForQueryString(result.Matches); string queryStringKeywords = "HL=" + HttpContext.Current.Request.QueryString["Query"].Replace(" ", ","); if (result.DocumentType == DocumentType.Page) { PageDocument doc = result.Document as PageDocument; PageInfo pageInfo = Pages.FindPage(doc.PageFullName); return(new SearchResultRow(doc.PageFullName + Settings.PageExtension + "?" + queryStringKeywords, Page, FormattingPipeline.PrepareTitle(doc.Title, false, FormattingContext.PageContent, pageInfo), result.Relevance, string.IsNullOrEmpty(doc.HighlightedContent) ? doc.Content : doc.HighlightedContent)); } else if (result.DocumentType == DocumentType.Message) { MessageDocument doc = result.Document as MessageDocument; PageInfo pageInfo = Pages.FindPage(doc.PageFullName); PageContent content = Cache.GetPageContent(pageInfo); if (content == null) { content = Content.GetPageContent(pageInfo, false); } return(new SearchResultRow(content.FullName + Settings.PageExtension + "?" + queryStringKeywords + "&Discuss=1#" + Tools.GetMessageIdForAnchor(doc.DateTime), Message, FormattingPipeline.PrepareTitle(doc.Subject, false, FormattingContext.MessageBody, pageInfo) + " (" + FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.MessageBody, content.PageInfo) + ")", result.Relevance, doc.HighlightedBody)); } else if (result.DocumentType == DocumentType.File) { FileDocument fileDoc = result.Document as FileDocument; string[] fileParts = fileDoc.FileName.Split(new char[] { '|' }); return(new SearchResultRow("GetFile.aspx?File=" + Tools.UrlEncode(fileDoc.FileName.Substring(fileParts[0].Length + 1)) + "&Provider=" + Tools.UrlEncode(fileParts[0]), File, fileParts[1], result.Relevance, fileDoc.HighlightedFileContent)); } else if (result.DocumentType == DocumentType.Attachment) { PageAttachmentDocument attnDoc = result.Document as PageAttachmentDocument; PageInfo pageInfo = Pages.FindPage(attnDoc.PageFullName); PageContent content = Cache.GetPageContent(pageInfo); if (content == null) { content = Content.GetPageContent(pageInfo, false); } return(new SearchResultRow(content.FullName + Settings.PageExtension, Attachment, attnDoc.FileName + " (" + FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, content.PageInfo) + ")", result.Relevance, attnDoc.HighlightedFileContent)); } else { throw new NotSupportedException(); } }
protected void Page_Load(object sender, EventArgs e) { currentWiki = DetectWiki(); Page.Title = Properties.Messages.UserTitle + " - " + Settings.GetWikiTitle(currentWiki); currentUsername = Request["User"]; if (string.IsNullOrEmpty(currentUsername)) { currentUsername = Request["Username"]; } if (string.IsNullOrEmpty(currentUsername)) { UrlTools.Redirect("Default.aspx"); } if (currentUsername == "admin") { currentUser = Users.GetGlobalAdministratorAccount(); } else { currentUser = Users.FindUser(currentWiki, currentUsername); } if (currentUser == null) { UrlTools.Redirect("Default.aspx"); } if (!Page.IsPostBack) { lblTitle.Text = lblTitle.Text.Replace("##NAME##", Users.GetDisplayName(currentUser)); txtSubject.Text = Request["Subject"]; if (txtSubject.Text != "" && SessionFacade.LoginKey == null) { UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed())); } } if (SessionFacade.LoginKey == null) { pnlMessage.Visible = false; } else { pnlMessage.Visible = true; } DisplayGravatar(); DisplayRecentActivity(); }
/// <summary> /// Verifies the need for a page redirection, and performs it when appropriate. /// </summary> private void VerifyAndPerformPageRedirection() { if (currentPage == null) { return; } // Force formatting so that the destination can be detected Content.GetFormattedPageContent(currentPage, true); PageInfo dest = Redirections.GetDestination(currentPage, out var fragment); if (dest == null) { return; } if (dest != null) { if (Request["NoRedirect"] != "1") { var fullUrl = dest.FullName + Settings.PageExtension + "?From=" + currentPage.FullName; if (!string.IsNullOrEmpty(fragment)) { fullUrl += "#" + fragment; } UrlTools.Redirect(fullUrl, false); } else { // Write redirection hint var sb = new StringBuilder(); sb.Append(@"<div id=""RedirectionDiv"">"); sb.Append(Properties.Messages.ThisPageRedirectsTo); sb.Append(": "); sb.Append(@"<a href="""); var fullUrl = UrlTools.BuildUrl("++", Tools.UrlEncode(dest.FullName), Settings.PageExtension, "?From=", Tools.UrlEncode(currentPage.FullName)); if (!string.IsNullOrEmpty(fragment)) { fullUrl += "#" + fragment; } sb.Append(fullUrl); sb.Append(@""">"); PageContent k = Content.GetPageContent(dest, true); sb.Append(FormattingPipeline.PrepareTitle(k.Title, false, FormattingContext.PageContent, currentPage)); sb.Append("</a></div>"); var literal = new Literal(); literal.Text = sb.ToString(); plhContent.Controls.Add(literal); } } }
protected void rptItems_DataBinding(object sender, EventArgs e) { provider = Collectors.FilesProviderCollector.GetProvider(lstProviders.SelectedValue); if (provider == null || CurrentPage == null) { return; } // Build a DataTable containing the proper information var table = new DataTable("Items"); table.Columns.Add("Name"); table.Columns.Add("Size"); table.Columns.Add("Editable", typeof(bool)); table.Columns.Add("Page"); table.Columns.Add("Link"); table.Columns.Add("Downloads"); table.Columns.Add("CanDelete", typeof(bool)); table.Columns.Add("CanDownload", typeof(bool)); var attachments = provider.ListPageAttachments(CurrentPage); foreach (var s in attachments) { FileDetails details = provider.GetPageAttachmentDetails(CurrentPage, s); DataRow row = table.NewRow(); var ext = Path.GetExtension(s).ToLowerInvariant(); row["Name"] = s; row["Size"] = Tools.BytesToString(details.Size); row["Editable"] = canUpload && canDelete && (ext == ".jpg" || ext == ".jpeg" || ext == ".png"); row["Page"] = CurrentPage.FullName; if (canDownload) { row["Link"] = "GetFile.aspx?File=" + Tools.UrlEncode(s).Replace("'", "'") + "&AsStreamAttachment=1&Provider=" + provider.GetType().FullName + "&IsPageAttachment=1&Page=" + Tools.UrlEncode(CurrentPage.FullName) + "&NoHit=1"; } else { row["Link"] = ""; } row["Downloads"] = details.RetrievalCount.ToString(); row["CanDelete"] = canDelete; row["CanDownload"] = canDownload; table.Rows.Add(row); } rptItems.DataSource = table; }
/// <summary> /// Prints the results of the automatic search. /// </summary> public void PrintSearchResults() { StringBuilder sb = new StringBuilder(1000); PageInfo[] results = SearchTools.SearchSimilarPages(Request["Page"], DetectNamespace()); if (results.Length > 0) { sb.Append("<p>"); sb.Append(Properties.Messages.WereYouLookingFor); sb.Append("</p>"); sb.Append("<ul>"); PageContent c; for (int i = 0; i < results.Length; i++) { c = Content.GetPageContent(results[i], true); sb.Append(@"<li><a href="""); UrlTools.BuildUrl(sb, Tools.UrlEncode(results[i].FullName), Settings.PageExtension); sb.Append(@""">"); sb.Append(FormattingPipeline.PrepareTitle(c.Title, false, FormattingContext.PageContent, c.PageInfo)); sb.Append("</a></li>"); } sb.Append("</ul>"); } else { sb.Append("<p>"); sb.Append(Properties.Messages.NoSimilarPages); sb.Append("</p>"); } sb.Append(@"<br /><p>"); sb.Append(Properties.Messages.YouCanAlso); sb.Append(@" <a href="""); UrlTools.BuildUrl(sb, "Search.aspx?Query=", Tools.UrlEncode(Request["Page"])); sb.Append(@""">"); sb.Append(Properties.Messages.PerformASearch); sb.Append("</a> "); sb.Append(Properties.Messages.Or); sb.Append(@" <a href="""); UrlTools.BuildUrl(sb, "Edit.aspx?Page=", Tools.UrlEncode(Request["Page"])); sb.Append(@"""><b>"); sb.Append(Properties.Messages.CreateThePage); sb.Append("</b></a> ("); sb.Append(Properties.Messages.CouldRequireLogin); sb.Append(").</p>"); lblSearchResults.Text = sb.ToString(); }
/// <summary> /// Prints the session refresh code in the page. /// </summary> public void PrintSessionRefresh() { var sb = new StringBuilder(50); sb.Append(@"<iframe src="""); if (currentPage != null) { sb.AppendFormat("SessionRefresh.aspx?Page={0}", Tools.UrlEncode(currentPage.FullName)); } else { sb.Append("SessionRefresh.aspx"); } sb.Append(@""" style=""width: 1px; height: 1px; border: none;"" scrolling=""no""></iframe>"); lblSessionRefresh.Text = sb.ToString(); }
/// <summary> /// Creates a new instance of the <see cref="T:SearchResultRow" /> class. /// </summary> /// <param name="result">The result to use.</param> /// <returns>The instance.</returns> public static SearchResultRow CreateInstance(SearchResult result) { var queryStringKeywords = "HL=" + GetKeywordsForQueryString(result.Matches); if (result.Document.TypeTag == PageDocument.StandardTypeTag) { var pageDoc = result.Document as PageDocument; return(new SearchResultRow(pageDoc.PageInfo.FullName + Settings.PageExtension + "?" + queryStringKeywords, Page, FormattingPipeline.PrepareTitle(pageDoc.Title, false, FormattingContext.PageContent, pageDoc.PageInfo), result.Relevance.Value, GetExcerpt(pageDoc.PageInfo, result.Matches))); } else if (result.Document.TypeTag == MessageDocument.StandardTypeTag) { var msgDoc = result.Document as MessageDocument; PageContent content = Content.GetPageContent(msgDoc.PageInfo, true); return(new SearchResultRow(msgDoc.PageInfo.FullName + Settings.PageExtension + "?" + queryStringKeywords + "&Discuss=1#" + Tools.GetMessageIdForAnchor(msgDoc.DateTime), Message, FormattingPipeline.PrepareTitle(msgDoc.Title, false, FormattingContext.MessageBody, content.PageInfo) + " (" + FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.MessageBody, content.PageInfo) + ")", result.Relevance.Value, GetExcerpt(msgDoc.PageInfo, msgDoc.MessageID, result.Matches))); } else if (result.Document.TypeTag == FileDocument.StandardTypeTag) { var fileDoc = result.Document as FileDocument; return(new SearchResultRow("GetFile.aspx?File=" + Tools.UrlEncode(fileDoc.Name.Substring(fileDoc.Provider.Length + 1)) + "&Provider=" + Tools.UrlEncode(fileDoc.Provider), File, fileDoc.Title, result.Relevance.Value, "")); } else if (result.Document.TypeTag == PageAttachmentDocument.StandardTypeTag) { var attnDoc = result.Document as PageAttachmentDocument; PageContent content = Content.GetPageContent(attnDoc.Page, false); return(new SearchResultRow(attnDoc.Page.FullName + Settings.PageExtension, Attachment, attnDoc.Title + " (" + FormattingPipeline.PrepareTitle(content.Title, false, FormattingContext.PageContent, content.PageInfo) + ")", result.Relevance.Value, "")); } else { throw new NotSupportedException(); } }
public void PrintNavPaths() { StringBuilder sb = new StringBuilder(); sb.Append("<ul>"); List<NavigationPath> paths = NavigationPaths.GetNavigationPaths(DetectNamespaceInfo()); for(int i = 0; i < paths.Count; i++) { sb.Append(@"<li><a href="""); UrlTools.BuildUrl(sb, "Default.aspx?Page=", Tools.UrlEncode(paths[i].Pages[0]), "&NavPath=", Tools.UrlEncode(paths[i].FullName)); sb.Append(@""">"); sb.Append(paths[i].FullName); sb.Append("</a></li>"); } sb.Append("</ul>"); lblNavPathList.Text = sb.ToString(); }
/// <summary> /// Verifies for editing collisions, and if no collision is found, "locks" the page /// </summary> private void ManageEditingCollisions() { if (currentPage == null) { return; } lblRefreshLink.Text = @"<a href=""" + UrlTools.BuildUrl(currentWiki, "Edit.aspx?Page=", Tools.UrlEncode(currentPage.FullName), (Request["Section"] != null ? "&Section=" + currentSection.ToString() : "")) + @""">" + Properties.Messages.Refresh + " »</a>"; string username = Request.UserHostAddress; if (SessionFacade.LoginKey != null) { username = SessionFacade.CurrentUsername; } if (Collisions.IsPageBeingEdited(currentPage, username)) { pnlCollisions.Visible = true; lblConcurrentEditingUsername.Text = "(" + Users.UserLink(currentWiki, Collisions.WhosEditing(currentPage)) + ")"; if (Settings.GetDisableConcurrentEditing(currentWiki)) { lblSaveDisabled.Visible = true; lblSaveDangerous.Visible = false; btnSave.Enabled = false; btnSaveAndContinue.Enabled = false; } else { lblSaveDisabled.Visible = false; lblSaveDangerous.Visible = true; btnSave.Enabled = true; btnSaveAndContinue.Enabled = true; } } else { pnlCollisions.Visible = false; btnSave.Enabled = true; btnSaveAndContinue.Enabled = true; Collisions.RenewEditingSession(currentPage, username); } }
protected void Page_Load(object sender, EventArgs e) { currentWiki = Tools.DetectCurrentWiki(); if (!Page.IsPostBack) { NamespaceInfo currentNamespace = Tools.DetectCurrentNamespaceInfo(); string currentNamespaceName = currentNamespace != null ? currentNamespace.Name + "." : ""; StringBuilder sb = new StringBuilder(200); sb.Append("<script type=\"text/javascript\">\r\n<!--\r\n"); sb.AppendFormat("\tvar MarkupControl = \"{0}\";\r\n", txtMarkup.ClientID); sb.AppendFormat("\tvar VisualControl = \"{0}\";\r\n", lblWYSIWYG.ClientID); sb.AppendFormat("\tvar CurrentPage = \"{0}\";\r\n", (currentPage != null ? Tools.UrlEncode(currentPage.FullName) : "")); sb.AppendFormat("\tvar CurrentNamespace = \"{0}\";\r\n", Tools.UrlEncode(currentNamespaceName)); sb.Append("// -->\r\n</script>"); lblStrings.Text = sb.ToString(); if (ViewState["ToolbarVisible"] == null) { ViewState["ToolbarVisible"] = true; } InitToolbar(); } if (mlvEditor.ActiveViewIndex == 1) { inWYSIWYG = true; } else { inWYSIWYG = false; } //SelectTab(0); if (ViewState["Tab"] != null) { SelectTab((int)ViewState["Tab"]); } LoadSnippets(); PrintCustomSpecialTags(); }
/// <summary> /// Gets a list of keywords formatted for the query string. /// </summary> /// <param name="matches">The search keywords.</param> /// <returns>The formatted list, for example 'word1,word2,word3'.</returns> private static string GetKeywordsForQueryString(WordInfoCollection matches) { StringBuilder buffer = new StringBuilder(100); List <string> added = new List <string>(5); for (int i = 0; i < matches.Count; i++) { if (matches[i].Text.Length > 1 && !added.Contains(matches[i].Text)) { buffer.Append(Tools.UrlEncode(matches[i].Text)); if (i != matches.Count - 1) { buffer.Append(","); } added.Add(matches[i].Text); } } return(buffer.ToString().TrimEnd(',')); }
/// <summary> /// Verifies the need for a page redirection, and performs it when appropriate. /// </summary> private void VerifyAndPerformPageRedirection() { if (currentPage == null) { return; } // Force formatting so that the destination can be detected FormattedContent.GetFormattedPageContent(currentWiki, currentPage); PageContent dest = Redirections.GetDestination(currentPage.FullName); if (dest == null) { return; } if (dest != null) { if (Request["NoRedirect"] != "1") { UrlTools.Redirect(dest.FullName + GlobalSettings.PageExtension + "?From=" + currentPage.FullName, false); } else { // Write redirection hint StringBuilder sb = new StringBuilder(); sb.Append(@"<div id=""RedirectionDiv"">"); sb.Append(Properties.Messages.ThisPageRedirectsTo); sb.Append(": "); sb.Append(@"<a href="""); UrlTools.BuildUrl(currentWiki, sb, "++", Tools.UrlEncode(dest.FullName), GlobalSettings.PageExtension, "?From=", Tools.UrlEncode(currentPage.FullName)); sb.Append(@""">"); sb.Append(FormattingPipeline.PrepareTitle(currentWiki, dest.Title, false, FormattingContext.PageContent, currentPage.FullName)); sb.Append("</a></div>"); Literal literal = new Literal(); literal.Text = sb.ToString(); plhContent.Controls.Add(literal); } } }
/// <summary> /// Verifies read permissions for the current user, redirecting to the appropriate page if no valid permissions are found. /// </summary> public static void VerifyReadPermissionsForCurrentNamespace() { var currentUsername = SessionFacade.GetCurrentUsername(); var currentGroups = SessionFacade.GetCurrentGroupNames(); var canViewNamespace = AuthChecker.CheckActionForNamespace( Tools.DetectCurrentNamespaceInfo(), Actions.ForNamespaces.ReadPages, currentUsername, currentGroups); if (!canViewNamespace) { if (SessionFacade.CurrentUsername == null) { UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(Tools.GetCurrentUrlFixed())); } else { UrlTools.Redirect("AccessDenied.aspx"); } } }
/// <summary> /// Verifies read permissions for the current user, redirecting to the appropriate page if no valid permissions are found. /// </summary> public static void VerifyReadPermissionsForCurrentNamespace() { string currentUsername = SessionFacade.GetCurrentUsername(); string[] currentGroups = SessionFacade.GetCurrentGroupNames(); bool canViewNamespace = AuthChecker.CheckActionForNamespace( Tools.DetectCurrentNamespaceInfo(), Actions.ForNamespaces.ReadPages, currentUsername, currentGroups); if (!canViewNamespace) { if (SessionFacade.CurrentUsername == null) { UrlTools.Redirect("Login.aspx?Redirect=" + Tools.UrlEncode(HttpContext.Current.Request.Url.ToString())); } else { UrlTools.Redirect("AccessDenied.aspx"); } } }
protected void btnCancel_Click(object sender, EventArgs e) { if (currentPage == null && txtName.Visible) { currentPage = Pages.FindPage(currentWiki, NameTools.GetFullName(DetectNamespace(), txtName.Text)); } if (currentPage != null) { // Try redirecting to proper section string anchor = null; if (currentSection != -1) { int start, len; ExtractSection(currentPage.Content, currentSection, out start, out len, out anchor); } UrlTools.Redirect(Tools.UrlEncode(currentPage.FullName) + GlobalSettings.PageExtension + (anchor != null ? ("#" + anchor + "_" + currentSection.ToString()) : "")); } else { UrlTools.Redirect(UrlTools.BuildUrl(currentWiki, "Default.aspx")); } }