public static AlignWithTimezone ( System.DateTime dateTime ) : System.DateTime | ||
dateTime | System.DateTime | The date/time to align. |
return | System.DateTime |
/// <summary> /// Prints the pages. /// </summary> public void PrintPages() { StringBuilder sb = new StringBuilder(65536); if (currentPages == null) { currentPages = GetAllPages(); } // Prepare ExtendedPageInfo array ExtendedPageInfo[] tempPageList = new ExtendedPageInfo[rangeEnd - rangeBegin + 1]; PageContent cnt; for (int i = 0; i < tempPageList.Length; i++) { cnt = Content.GetPageContent(currentPages[rangeBegin + i], true); tempPageList[i] = new ExtendedPageInfo(currentPages[rangeBegin + i], cnt.Title, cnt.LastModified, GetCreator(currentPages[rangeBegin + i]), cnt.User); } // Prepare for sorting bool reverse = false; SortingMethod sortBy = SortingMethod.Title; if (Request["SortBy"] != null) { try { sortBy = (SortingMethod)Enum.Parse(typeof(SortingMethod), Request["SortBy"], true); } catch { // Backwards compatibility if (Request["SortBy"].ToLowerInvariant() == "date") { sortBy = SortingMethod.DateTime; } } if (Request["Reverse"] != null) { reverse = true; } } SortedDictionary <SortingGroup, List <ExtendedPageInfo> > sortedPages = PageSortingTools.Sort(tempPageList, sortBy, reverse); sb.Append(@"<table id=""PageListTable"" class=""generic"" cellpadding=""0"" cellspacing=""0"">"); sb.Append("<thead>"); sb.Append(@"<tr class=""tableheader"">"); // Page title sb.Append(@"<th><a rel=""nofollow"" href="""); UrlTools.BuildUrl(sb, "AllPages.aspx?SortBy=Title", (!reverse && sortBy == SortingMethod.Title ? "&Reverse=1" : ""), (Request["Cat"] != null ? "&Cat=" + Tools.UrlEncode(Request["Cat"]) : ""), "&Page=", selectedPage.ToString()); sb.Append(@""" title="""); sb.Append(Properties.Messages.SortByTitle); sb.Append(@""">"); sb.Append(Properties.Messages.PageTitle); sb.Append((reverse && sortBy.Equals("title") ? " ↑" : "")); sb.Append((!reverse && sortBy.Equals("title") ? " ↓" : "")); sb.Append("</a></th>"); // Message count sb.Append(@"<th><img src=""Images/Comment.png"" alt=""Comments"" /></th>"); // Creation date/time sb.Append(@"<th><a rel=""nofollow"" href="""); UrlTools.BuildUrl(sb, "AllPages.aspx?SortBy=Creation", (!reverse && sortBy == SortingMethod.Creation ? "&Reverse=1" : ""), (Request["Cat"] != null ? "&Cat=" + Tools.UrlEncode(Request["Cat"]) : ""), "&Page=", selectedPage.ToString()); sb.Append(@""" title="""); sb.Append(Properties.Messages.SortByDate); sb.Append(@""">"); sb.Append(Properties.Messages.CreatedOn); sb.Append((reverse && sortBy.Equals("creation") ? " ↑" : "")); sb.Append((!reverse && sortBy.Equals("creation") ? " ↓" : "")); sb.Append("</a></th>"); // Mod. date/time sb.Append(@"<th><a rel=""nofollow"" href="""); UrlTools.BuildUrl(sb, "AllPages.aspx?SortBy=DateTime", (!reverse && sortBy == SortingMethod.DateTime ? "&Reverse=1" : ""), (Request["Cat"] != null ? "&Cat=" + Tools.UrlEncode(Request["Cat"]) : ""), "&Page=", selectedPage.ToString()); sb.Append(@""" title="""); sb.Append(Properties.Messages.SortByDate); sb.Append(@""">"); sb.Append(Properties.Messages.ModifiedOn); sb.Append((reverse && sortBy.Equals("date") ? " ↑" : "")); sb.Append((!reverse && sortBy.Equals("date") ? " ↓" : "")); sb.Append("</a></th>"); // Creator sb.Append(@"<th><a rel=""nofollow"" href="""); UrlTools.BuildUrl(sb, "AllPages.aspx?SortBy=Creator", (!reverse && sortBy == SortingMethod.Creator ? "&Reverse=1" : ""), (Request["Cat"] != null ? "&Cat=" + Tools.UrlEncode(Request["Cat"]) : ""), "&Page=", selectedPage.ToString()); sb.Append(@""" title="""); sb.Append(Properties.Messages.SortByUser); sb.Append(@""">"); sb.Append(Properties.Messages.CreatedBy); sb.Append((reverse && sortBy.Equals("creator") ? " ↑" : "")); sb.Append((!reverse && sortBy.Equals("creator") ? " ↓" : "")); sb.Append("</a></th>"); // Last author sb.Append(@"<th><a rel=""nofollow"" href="""); UrlTools.BuildUrl(sb, "AllPages.aspx?SortBy=User", (!reverse && sortBy == SortingMethod.User ? "&Reverse=1" : ""), (Request["Cat"] != null ? "&Cat=" + Tools.UrlEncode(Request["Cat"]) : ""), "&Page=", selectedPage.ToString()); sb.Append(@""" title="""); sb.Append(Properties.Messages.SortByUser); sb.Append(@""">"); sb.Append(Properties.Messages.ModifiedBy); sb.Append((reverse && sortBy.Equals("user") ? " ↑" : "")); sb.Append((!reverse && sortBy.Equals("user") ? " ↓" : "")); sb.Append("</a></th>"); // Categories sb.Append("<th>"); sb.Append(Properties.Messages.Categories); sb.Append("</th>"); sb.Append("</tr>"); sb.Append("</thead><tbody>"); foreach (SortingGroup key in sortedPages.Keys) { List <ExtendedPageInfo> pageList = sortedPages[key]; for (int i = 0; i < pageList.Count; i++) { if (i == 0) { // Add group header sb.Append(@"<tr class=""tablerow"">"); if (sortBy == SortingMethod.Title) { sb.AppendFormat("<td colspan=\"7\"><b>{0}</b></td>", key.Label); } else if (sortBy == SortingMethod.Creation) { sb.AppendFormat("<td colspan=\"2\"></td><td colspan=\"5\"><b>{0}</b></td>", key.Label); } else if (sortBy == SortingMethod.DateTime) { sb.AppendFormat("<td colspan=\"3\"></td><td colspan=\"4\"><b>{0}</b></td>", key.Label); } else if (sortBy == SortingMethod.Creator) { sb.AppendFormat("<td colspan=\"4\"></td><td colspan=\"3\"><b>{0}</b></td>", key.Label); } else if (sortBy == SortingMethod.User) { sb.AppendFormat("<td colspan=\"5\"></td><td colspan=\"2\"><b>{0}</b></td>", key.Label); } sb.Append("</tr>"); } sb.Append(@"<tr class=""tablerow"); if ((i + 1) % 2 == 0) { sb.Append("alternate"); } sb.Append(@""">"); // Page title sb.Append(@"<td>"); sb.Append(@"<a href="""); UrlTools.BuildUrl(sb, Tools.UrlEncode(pageList[i].PageInfo.FullName), Settings.PageExtension); sb.Append(@""">"); sb.Append(pageList[i].Title); sb.Append("</a>"); sb.Append("</td>"); // Message count sb.Append(@"<td>"); int msg = pageList[i].MessageCount; if (msg > 0) { sb.Append(@"<a href="""); UrlTools.BuildUrl(sb, Tools.UrlEncode(pageList[i].PageInfo.FullName), Settings.PageExtension, "?Discuss=1"); sb.Append(@""" title="""); sb.Append(Properties.Messages.Discuss); sb.Append(@""">"); sb.Append(msg.ToString()); sb.Append("</a>"); } else { sb.Append(" "); } sb.Append("</td>"); // Creation date/time sb.Append(@"<td>"); sb.Append(Preferences.AlignWithTimezone(pageList[i].CreationDateTime).ToString(Settings.DateTimeFormat) + " "); sb.Append("</td>"); // Mod. date/time sb.Append(@"<td>"); sb.Append(Preferences.AlignWithTimezone(pageList[i].ModificationDateTime).ToString(Settings.DateTimeFormat) + " "); sb.Append("</td>"); // Creator sb.Append(@"<td>"); sb.Append(Users.UserLink(pageList[i].Creator)); sb.Append("</td>"); // Last author sb.Append(@"<td>"); sb.Append(Users.UserLink(pageList[i].LastAuthor)); sb.Append("</td>"); // Categories CategoryInfo[] cats = Pages.GetCategoriesForPage(pageList[i].PageInfo); sb.Append(@"<td>"); if (cats.Length == 0) { sb.Append(@"<a href="""); UrlTools.BuildUrl(sb, "AllPages.aspx?Cat=-"); sb.Append(@""">"); sb.Append(Properties.Messages.NC); sb.Append("</a>"); } else { for (int k = 0; k < cats.Length; k++) { sb.Append(@"<a href="""); UrlTools.BuildUrl(sb, "AllPages.aspx?Cat=", Tools.UrlEncode(cats[k].FullName)); sb.Append(@""">"); sb.Append(NameTools.GetLocalName(cats[k].FullName)); sb.Append("</a>"); if (k != cats.Length - 1) { sb.Append(", "); } } } sb.Append("</td>"); sb.Append("</tr>"); } } sb.Append("</tbody>"); sb.Append("</table>"); Literal lbl = new Literal(); lbl.Text = sb.ToString(); pnlPageList.Controls.Clear(); pnlPageList.Controls.Add(lbl); }
/// <summary> /// Manages the draft status display. /// </summary> private void ManageDraft() { if (isDraft) { chkSaveAsDraft.Checked = true; chkMinorChange.Enabled = false; pnlDraft.Visible = true; lblDraftInfo.Text = lblDraftInfo.Text.Replace("##USER##", Users.UserLink(currentContent.User, true)).Replace("##DATETIME##", Preferences.AlignWithTimezone(currentContent.LastModified).ToString(Settings.DateTimeFormat)).Replace("##VIEWCHANGES##", string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", UrlTools.BuildUrl("Diff.aspx?Page=", Tools.UrlEncode(currentPage.FullName), "&Rev1=Current&Rev2=Draft"), Properties.Messages.ViewChanges)); } else { pnlDraft.Visible = false; } }
/// <summary> /// Prints a message. /// </summary> /// <param name="message">The message to print.</param> /// <param name="parent">The parent message, or <c>null</c>.</param> /// <param name="sb">The output <see cref="T:StringBuilder" />.</param> private void PrintMessage(Message message, Message parent, StringBuilder sb) { string currentWiki = Tools.DetectCurrentWiki(); // Print header sb.Append(@"<div class=""messageheader"">"); //sb.AppendFormat(@"<a id=""MSG_{0}""></a>", message.ID); if (!currentPage.Provider.ReadOnly) { // Print reply/edit/delete buttons only if provider is not read-only sb.Append(@"<div class=""reply"">"); if (canPostMessages) { sb.Append(@"<a class=""reply"" href="""); sb.Append(UrlTools.BuildUrl(currentWiki, "Post.aspx?Page=", Tools.UrlEncode(currentPage.FullName), "&Parent=", message.ID.ToString())); sb.Append(@""">"); sb.Append(Properties.Messages.Reply); sb.Append("</a>"); } // If current user is the author of the message or is an admin, print the edit hyperLink // A message can be edited only if the user is authenticated - anonymous users cannot edit their messages if (SessionFacade.LoginKey != null && ((message.Username == SessionFacade.CurrentUsername && canPostMessages) || canManageDiscussion)) { sb.Append(@" <a class=""edit"" href="""); sb.Append(UrlTools.BuildUrl(currentWiki, "Post.aspx?Page=", Tools.UrlEncode(currentPage.FullName), "&Edit=", message.ID.ToString())); sb.Append(@""">"); sb.Append(Properties.Messages.Edit); sb.Append("</a>"); } // If the current user is an admin, print the delete hyperLink if (SessionFacade.LoginKey != null && canManageDiscussion) { sb.Append(@" <a class=""delete"" href="""); sb.Append(UrlTools.BuildUrl(currentWiki, "Operation.aspx?Operation=DeleteMessage&Message=", message.ID.ToString(), "&Page=", Tools.UrlEncode(currentPage.FullName))); sb.Append(@""">"); sb.Append(Properties.Messages.Delete); sb.Append("</a>"); } sb.Append("</div>"); } sb.Append(@"<div>"); sb.AppendFormat(@"<a id=""{0}"" href=""#{0}"" title=""Permalink"">¶</a> ", Tools.GetMessageIdForAnchor(message.DateTime)); // Print subject if (message.Subject.Length > 0) { sb.Append(@"<span class=""messagesubject"">"); sb.Append(FormattingPipeline.PrepareTitle(currentWiki, message.Subject, false, FormattingContext.MessageBody, currentPage.FullName)); sb.Append("</span>"); } // Print message date/time sb.Append(@"<span class=""messagedatetime"">"); sb.Append(Preferences.AlignWithTimezone(currentWiki, message.DateTime).ToString(Settings.GetDateTimeFormat(currentWiki))); sb.Append(" "); sb.Append(Properties.Messages.By); sb.Append(" "); sb.Append(Users.UserLink(currentWiki, message.Username)); sb.Append("</span>"); sb.Append("</div>"); sb.Append("</div>"); // Print body sb.Append(@"<div class=""messagebody"">"); sb.Append(FormattingPipeline.FormatWithPhase3(currentWiki, FormattingPipeline.FormatWithPhase1And2(currentWiki, message.Body, false, FormattingContext.MessageBody, currentPage.FullName), FormattingContext.MessageBody, currentPage.FullName)); sb.Append("</div>"); }
/// <summary> /// Prepares the message deletion GUI. /// </summary> private void PrepareDeleteMessage() { string ms = Request["Message"]; string pg = Request["Page"]; if (ms == null || ms.Length == 0 || pg == null || pg.Length == 0) { UrlTools.RedirectHome(currentWiki); } PageContent page = Pages.FindPage(currentWiki, pg); if (page == null) { UrlTools.RedirectHome(currentWiki); } if (page.Provider.ReadOnly) { UrlTools.Redirect(UrlTools.BuildUrl(currentWiki, page.FullName, GlobalSettings.PageExtension)); } AuthChecker authChecker = new AuthChecker(Collectors.CollectorsBox.GetSettingsProvider(currentWiki)); bool canManageDiscussion = authChecker.CheckActionForPage(page.FullName, Actions.ForPages.ManageDiscussion, SessionFacade.GetCurrentUsername(), SessionFacade.GetCurrentGroupNames(currentWiki)); if (!canManageDiscussion) { UrlTools.Redirect("AccessDenied.aspx"); } int id = -1; try { id = int.Parse(ms); } catch { UrlTools.RedirectHome(currentWiki); } Message message = Pages.FindMessage(Pages.GetPageMessages(page), id); if (message == null) { UrlTools.RedirectHome(currentWiki); } StringBuilder sb = new StringBuilder(500); sb.Append("<b>"); sb.Append(FormattingPipeline.PrepareTitle(currentWiki, message.Subject, false, FormattingContext.MessageBody, page.FullName)); sb.Append("</b><br /><small>"); sb.Append(Properties.Messages.Posted); sb.Append(" "); sb.Append(Preferences.AlignWithTimezone(currentWiki, message.DateTime).ToString(Settings.GetDateTimeFormat(currentWiki))); sb.Append(" "); sb.Append(Properties.Messages.By); sb.Append(" "); sb.Append(Users.UserLink(currentWiki, message.Username)); sb.Append("</small><br /><br />"); sb.Append(FormattingPipeline.FormatWithPhase3(currentWiki, FormattingPipeline.FormatWithPhase1And2(currentWiki, message.Body, false, FormattingContext.MessageBody, page.FullName), FormattingContext.MessageBody, page.FullName)); lblDeleteMessageContent.Text = sb.ToString(); }
/// <summary> /// Prints the history. /// </summary> public void PrintHistory() { if (page == null) { return; } StringBuilder sb = new StringBuilder(); if (Request["Revision"] == null) { // Show version list List <int> revisions = Pages.GetBackups(page); revisions.Reverse(); List <RevisionRow> result = new List <RevisionRow>(revisions.Count + 1); result.Add(new RevisionRow(-1, Content.GetPageContent(page, false), false)); foreach (int rev in revisions) { PageContent content = Pages.GetBackupContent(page, rev); result.Add(new RevisionRow(rev, content, canRollback)); } rptHistory.DataSource = result; rptHistory.DataBind(); } else { int rev = -1; if (!int.TryParse(Request["Revision"], out rev)) { UrlTools.Redirect(page.FullName + Settings.PageExtension); } List <int> backups = Pages.GetBackups(page); if (!backups.Contains(rev)) { UrlTools.Redirect(page.FullName + Settings.PageExtension); return; } PageContent revision = Pages.GetBackupContent(page, rev); sb.Append(@"<table class=""box"" cellpadding=""0"" cellspacing=""0""><tr><td>"); sb.Append(@"<p style=""text-align: center;""><b>"); if (rev > 0) { sb.Append(@"<a href="""); UrlTools.BuildUrl(sb, "History.aspx?Page=", Tools.UrlEncode(page.FullName), "&Revision=", Tools.GetVersionString((int)(rev - 1))); sb.Append(@""">« "); sb.Append(Properties.Messages.OlderRevision); sb.Append("</a>"); } else { sb.Append("« "); sb.Append(Properties.Messages.OlderRevision); } sb.Append(@" - <a href="""); UrlTools.BuildUrl(sb, "History.aspx?Page=", Tools.UrlEncode(page.FullName)); sb.Append(@""">"); sb.Append(Properties.Messages.BackToHistory); sb.Append("</a> - "); if (rev < backups.Count - 1) { sb.Append(@"<a href="""); UrlTools.BuildUrl(sb, "History.aspx?Page=", Tools.UrlEncode(page.FullName), "&Revision=", Tools.GetVersionString((int)(rev + 1))); sb.Append(@""">"); sb.Append(Properties.Messages.NewerRevision); sb.Append(" »</a>"); } else { sb.Append(@"<a href="""); UrlTools.BuildUrl(sb, Tools.UrlEncode(page.FullName), Settings.PageExtension); sb.Append(@""">"); sb.Append(Properties.Messages.CurrentRevision); sb.Append("</a>"); } sb.Append("</b></p></td></tr></table><br />"); sb.Append(@"<h3 class=""separator"">"); sb.Append(Properties.Messages.PageRevision); sb.Append(": "); sb.Append(Preferences.AlignWithTimezone(revision.LastModified).ToString(Settings.DateTimeFormat)); sb.Append("</h3><br />"); sb.Append(FormattingPipeline.FormatWithPhase3(FormattingPipeline.FormatWithPhase1And2(revision.Content, false, FormattingContext.PageContent, page).Replace(Formatter.EditSectionPlaceHolder, ""), FormattingContext.PageContent, page)); } lblHistory.Text = sb.ToString(); }